I've been looking through the forums to see if anyone's mentioned this, but as of yet, I haven't found any topics on this.
My problem is this. I'm creating a game that you can dig for rocks and minerals and such. Each "spot" you can dig is a sprite. I have one sprite that I copied and pasted around. I gave that sprite an instance variable, so that each time you clicked on it, it would add to that variable, and once a specific number was reached, that object would be destroyed. It was nice, with the instance variable, because then each was independent of one another and worked great. Until I left that layout, and came back. Then they were all back, even if they had already been destroyed. (I wouldn't mind them coming back eventually, being "replenished", but not instantly) So I figured it had something to do with it being on that layout, and getting reset when i left and came back. So I made them global, so their variables would be saved even if I left and came back. That worked... except (dun dun duuuuuh)... when i left the layout they were placed in, they seemed to disappear. (really they were just going to the very very back, because if i went to a layout that didn't have a tile background, "blank" i could see them. And even though i couldn't see them on the layout i made them on, i could still click on them (once if found their position) and their instance variables stayed stored nicely.
*whew* sorry for the long description. Anyways. I would like to keep them global, but I want them to stay on top of the layout i want them to be seen in, and not seen in the others.
This will help me when i want a type of hud that i can carry though the other layouts, and i will defiantly want them visible. Thanks for your help.
*edit: I am aware that I could make global variables and assign them as different sprites, and have each global variable linked to each though the events page. But that seems way too repetitive. (I'm willing and able to do that, just want to find out if there's a way to get it working this other way) It seems really really close to what i want, not sure if there's something I'm missing thats keeping it for doing exactly what i want. (and I have tried making them in a layer above everything else in the layout I have them on, to see if that kept them above the "ground" and they still move under the tiled background) Thanks again
Develop games in your browser. Powerful, performant & highly capable.
Use a global array to store the values for each instance.
On start of layout, apply the value to the instances according to the value stored in the array.
You can store the value and the UID of the instance in the array to make it easier to pick the correct instance on start of layout.
To know more about arrays check the how do I FAQ section "arrays" and about the UID picking check the section "Picking/Selecting an instance".
Amongst the items listed you should find all the explanations you need.
I've written a tutorial about that - remember values of instance variables - to keep it simple i've used a global text variable for storing, array is certainly better and should work similar.
remember values of instance variables