Random scenes, prevent doubles

hi!
maby someone can give me a hint.
i´ve 5 scenes and a button to random this scenes.
the problem is, i want to call each scene a minimum of once and during the process no scene double.
for now i call i.e. 1,5,3,5,… - this sould not be.
here´s my document.
random_scenes.hype.zip (39.5 KB)

random_scenes.hype.zip (39.7 KB)

you may like the slotmachine, too :wink:
slotMachine.hype.zip (103.1 KB)

3 Likes

wow - the slot machine is great!
thanks also for help at the “random scene” - on export it always starts with scene 1.
do i have to render onLoad, too, in order to avoid that?

simple solution could be to add a scene named start in first place and on its sceneload execute the initRandom with a small change:

var currentSceneName = hypeDocument.currentSceneName();
if(currentSceneName != 'start')sceneNamesForJumping.splice(sceneNamesForJumping.indexOf(currentSceneName), 1);
shuffleArray(sceneNamesForJumping);

if(sceneNamesForJumping.length > 0)hypeDocument.showSceneNamed(sceneNamesForJumping[0], hypeDocument.kSceneTransitionPushBottomToTop, 1.1)



function shuffleArray(o)
{ 
for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
return o;
}

this solves the problem - thank you very much! :grinning:

Hello. I’ve been playing around with this. For me the button stops working after 5 clicks. What would cause that?

@h_classen! how do i start this random again?
i use this often, but on new game i always have to reload the whole site.
but instead i want to jump to scene “start” and play again.
the problem is, that the button won´t work after first passage.
thanks for your help.
random_startAgain.hype.zip (56,5 KB)

The idea is that you cannot jump to a scene you've been to before, so after you've visited all scenes the button won't have anywhere to go!

If you want the start button to reset the cycle, you'll need to restore the sceneNamesForJumping array. This is currently set in the Head HTML <script> tag, but could instead be placed as an on scene load action in your first scene.

var sceneNamesForJumping = ["p1", "p2", "p3", "p4", "p5"];

1 Like

ok solved it - i use:

       `window.sceneNamesForJumping = ["p1", "p2", "p3", "p4", "p5"];`

onSceneLoad for the startScene. - this is working
thanx @jonathan!

Oh! Sorry, I missed that the scoping was different and it shouldn’t be using var but needs to be modifying the global. Glad you got it!

1 Like