Is there a way to continue executed code from one scene through to another?

Phraustdesign

  • Posts: 9
I am not sure how to pose this question correctly - so I'll explain in brief.

Making a game that has a random event happen during scenes (A scene behaviour I attach to all scenes) This random event is a sequence of code that has a few "if then" & "do after X sec" & "play sound" blocks in it - so the whole code sequence takes about 2 to 3 seconds to execute completely. 

It is basically a computer voice that is telling you what has happened based upon a sequence of random attributes being changed. For example: "Core Power Failure Detected" - "Core now operating at" - "XX%" (Each "" is a different audio file that plays in a sequence based upon the random event)

However - if the player switches away from the scene to another one before this code is fully executed - it obviously stops and the audio doesn't play through completely, and a few variables fail to get set properly.

So is there a way to allow code in one scene to finish executing, even if the scene has changed? The flow of the game won't be the same if this isn't possible.

Thanks in advance!

Luyren

  • *
  • Posts: 2728
Store your sequence in a game attribute, and execute based on values in the game attribute. The executed events can be removed from the game attribute, and you can store manual timers instead of using do afters to keep the continuity between scenes.
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.
Twitter

Phraustdesign

  • Posts: 9
Bare with me here --- I don't quiet understand putting the sequence into an attribute.

How do I make an attribute that is a sequence of events and sounds? I'm still learning the full ability of attributes - so there might be a few things I don't yet understand.

Are there any examples you could point me towards?

Luyren

  • *
  • Posts: 2728
You can use a list attribute: https://www.stencyl.com/help/view/lists/
You can check what's in index 0, and do something based on its value. For example if you set it to "Play Soud,Sound Name", it plays the sound. Remove index 0 after it is done, which will drop all items one index, and check the new index 0. That's one example.

You can check the demo version of my cutscene pack if you want an idea of how to play events in sequence. https://luyren.itch.io/luyrens-cutscene-resource-pack
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.
Twitter