Everything you ask is possible. You just have to get familiar with a few concepts.
-
Each layout can have its personal event sheet. You assign a event sheet to a layout in the layout's properties (in the left pane).
But, and that is interesting, you can have event sheets that are not assigned to a layout. You can 'include' those into an assigned event sheet. So, say, you have a bunch of events that are different for each layout, bring them in an assigned event sheet. You have a bunch of events that are the same for each layout, bring them in a unassigned and include them in an assigned event sheet.
https://www.scirra.com/manual/82/includes
-
Global / local objects
The property 'global' for an object can be "yes" or "no".
A global object (some are global by default, an array by example) will be 'just there' once it is created.
If you create a global object in the first layout, it will be present in every layout. And it wil keep its personal info, instance variables .... etc.
If you jump to another layout, you just take a global object with you. This also means, if that object is present in the next layout, you end up with 2 instance of that object, that one that survived the layout switch + the one that is already present in that next layout.
Local objects stay in the layout that they are created in. And they will just forget all their (non default) personal stuff (instance variables) when leaving that layout. Default personal stuff is everything that you have set in the layout editor. Everything that you changed to an object during runtime is non default stuff, so that will be all forgotten.
This is handy, but not always wanted. To avoid this use the Persist behavior.
https://www.scirra.com/manual/161/persist
An object with Persist attached to will not forget its personal stuff. So if you leave that layout, and come back, those objects will be the same as you left them.
-
Global / local layers.
Is a layer property. Every object on a global layer with a certain "NAME" will be auto recreated on a layer with the same "NAME" when switching layouts. Say you switch layouts. In the first layout you have a global layer named "HUD". On that layer you have objects. In the next layout you have also a layer named "HUD", but holding not 1 object. When you switch layout, all objects that are on "HUD" in the first layout, will be auto created on the layer with name "HUD" in the second layout.
https://www.scirra.com/tutorials/594/bu ... terface-ui
I really have no words to describe how handy this is.
-
Global variables.
Global variables in 1 event sheet are accessible/up-to-change in every event sheet.
This also means that, if you give each event sheet its own global variables, you will end up with a big mess.
Rather, make 1 unassigned event sheet, only for the global variables. Dont even include that event sheet.
Because the fact that they are global, you can use them to get values from one to another layout. They keep there values when changing layouts.
-
Other ways to make values survive a layout change.
Arrays and dictionaries are global objects by default. They do not suffer from the 'duplication' danger that goes with global objects, because they dont have a 'face' in the layout editor. (you can make instances during runtime, but lets avoid that for now)
Since they are global, you can store values in them, and those values will survive a layout change.
Perfect to exchange info between layouts.
-
On start/end of layout.
Those conditions are triggers. They run (only once) when a start/end is detected.
And yes, they for sure run their actions/sub events when you switch layouts.
You must think those trough, do you want this too happen ?
If not, you got to constrain them from running every time you enter/leave the layout. This is typical done by evaluating/setting an instance variable of an object with Persist attached.
-
Why use Persist ?
Well, global sprites are a nice thing. But also a PITA.
Usually you want to design a layout in the layout editor using instances of an object. Say, you switch layouts. In the first layout you designed a maze using instances of 1 sprite. In the second layout you do the same. If you make that sprite global, you will bring the instances created in the first layout with you to the second layout. And that is a mess you dont want.
So, rather use 'local' objects with the Persist behavior attached. They only live in their layout, and they keep their personal stuff between layout changes.
-
Switching layouts 'offline'.
That is another history. Got to do some tutorials about 'Local Storage'.
I hope i covered most of the 'layout switch' issues.