How do I Create code in JavaScript for a button that will show random scenes in my hype project?


(steven Lashley) #1

Do I make an array with the scenes and use math.random function?


#2

Yep. That’s about it :wink:

Hype’s API would make things nice and easy (providing you are using unique names in all your scenes)

var scenes = hypeDocument.sceneNames();
	
hypeDocument.showSceneNamed(scenes[getRandomScene(scenes.length)])
	
function getRandomScene(length) {
    return Math.floor(Math.random() * Math.floor(length));
}

#3

Elegant :sunny:


(steven Lashley) #4

Thank you DBear!