Pick random scene

Is there a way if I make a ton of scenes that when I press play it will randomly pick one of the 10? And not the same scene over and over.

sdieters

  • Posts: 2068
it's easy.
only problem is you need to specify every scene since you cant call a scene by simply using its name.
what you have to create is a behaviour as such:

lets say you have 5 scenes you want to pick from.
randomNumber << is a number attribute

when the mous (is released) on (self) << you can also place this on a scene behaviour, using the playbutton actor instead of (self).
set (randomNumber) pick a random number between 0 and 4 << giving 5 different options, since 0 is also an option.
IF randomnumber = 0,
*switch to level 1 using fading or not*
OTHERWISE IF = 1,
*switch to level 2 using fading or not*
OTHERWISE IF = 2,
*switch to level 3 using fading or not*
...(repeat this as many times as needed)
My new profile is TheIndieStation.
When you see a recent post with this name, i'm probably using my phone. So dont mind any typo's =p

kantieno

  • *
  • Posts: 242
But you can specify a scene by its name? Use the "scene with name: ____" block under scene > game flow. In which case you can just switch to a random scene with "scene with name: "Scene" + "Random number 1-10"".
Play my new game "Hidden Valley Ninja" here: http://www.kongregate.com/games/kantieno/hidden-valley-ninja

sdieters

  • Posts: 2068
oh yeah indeed.
i have bin asked this but with either sounds or actors for many times, in which case isnt posible, so i automaticly assumed it wouldn't be posible with scenes either haha.

so yeah, you could try that with the random number system above
My new profile is TheIndieStation.
When you see a recent post with this name, i'm probably using my phone. So dont mind any typo's =p

kantieno

  • *
  • Posts: 242
Ah yeah, understandable, I had somehow completely missed that block during the first year of using stencyl, pretty glad when I finally realized!
Play my new game "Hidden Valley Ninja" here: http://www.kongregate.com/games/kantieno/hidden-valley-ninja

krazziebone02

  • Posts: 113
it's easy.
only problem is you need to specify every scene since you cant call a scene by simply using its name.
what you have to create is a behaviour as such:

lets say you have 5 scenes you want to pick from.
randomNumber << is a number attribute

when the mous (is released) on (self) << you can also place this on a scene behaviour, using the playbutton actor instead of (self).
set (randomNumber) pick a random number between 0 and 4 << giving 5 different options, since 0 is also an option.
IF randomnumber = 0,
*switch to level 1 using fading or not*
OTHERWISE IF = 1,
*switch to level 2 using fading or not*
OTHERWISE IF = 2,
*switch to level 3 using fading or not*
...(repeat this as many times as needed)

what if i i want to remove the scene that is already answered??
what should i do?
i want to be the best user of stencyl

sdieters

  • Posts: 2068
Luckily almost a year later, I have found a much more easy way of doing this =)

Create a GameAttribute list, and add all names of your scenes to it.

Store the value of a random generated number between 0 and length of the list -1 in a number attribute, then store the value of a random index number between 0 and length of list -1 in a text attribute, remove the item from the list using the number attribute, and switch to a scene with the name of your text attribute =)
My new profile is TheIndieStation.
When you see a recent post with this name, i'm probably using my phone. So dont mind any typo's =p

Innes

  • *
  • Posts: 1963
what if i i want to remove the scene that is already answered??
what should i do?

It would be courteous to let others know that you already have a thread running on this topic. Sdieters has taken the time to answer your question, but the same answer has already been provided for you in the other thread.
Visit www.TheStencylBook.com - the only published book for learning Stencyl.

sdieters

  • Posts: 2068
My new profile is TheIndieStation.
When you see a recent post with this name, i'm probably using my phone. So dont mind any typo's =p

krazziebone02

  • Posts: 113
Luckily almost a year later, I have found a much more easy way of doing this =)

Create a GameAttribute list, and add all names of your scenes to it.

Store the value of a random generated number between 0 and length of the list -1 in a number attribute, then store the value of a random index number between 0 and length of list -1 in a text attribute, remove the item from the list using the number attribute, and switch to a scene with the name of your text attribute =)

sir what do you mean store?? is it add or insert??
i want to be the best user of stencyl

krazziebone02

  • Posts: 113
what if i i want to remove the scene that is already answered??
what should i do?

It would be courteous to let others know that you already have a thread running on this topic. Sdieters has taken the time to answer your question, but the same answer has already been provided for you in the other thread.

sir i think the reply of sdieters is better........
i want to be the best user of stencyl

krazziebone02

  • Posts: 113
Luckily almost a year later, I have found a much more easy way of doing this =)

Create a GameAttribute list, and add all names of your scenes to it.

Store the value of a random generated number between 0 and length of the list -1 in a number attribute, then store the value of a random index number between 0 and length of list -1 in a text attribute, remove the item from the list using the number attribute, and switch to a scene with the name of your text attribute =)

sir can you convert this in block codes?? please sir
i want to be the best user of stencyl

krazziebone02

  • Posts: 113
im sorry for being asking many questions im just newbie
i want to be the best user of stencyl

sdieters

  • Posts: 2068
Yes, we noticed.
We don't mind helping new people, but to be honest, you are very annoying when it comes to spamming. And in such cases I rather want to spend my time on people who wait their turn and don't open multiple threads.
My new profile is TheIndieStation.
When you see a recent post with this name, i'm probably using my phone. So dont mind any typo's =p

krazziebone02

  • Posts: 113
Yes, we noticed.
We don't mind helping new people, but to be honest, you are very annoying when it comes to spamming. And in such cases I rather want to spend my time on people who wait their turn and don't open multiple threads.

im so sorry for that sir it will not happen again
i want to be the best user of stencyl