How do I set different instance variable to many objects of the same type? Obviously there is a way to do it manually. But what if I have 1000 objects of these type. Is there an automated solution?
"On created" wont work, because they are already on the layout.
Instance variables are individually for each instance. Normally, this isn't a problem since you won't be usually messing with instance variables in a complex way. However, dealing with multiple instances, especially newly spawned ones can be tricky. Your best solution to use picking instances, either a specific preset/known UID (if it's a pre-existing object on the layout before preview), or the solution below:
The only issue if you would try to spawn two objects after one another, since int(Object.UID) will retrieve the UID of the last created object, unless you repeat the two create actions above twice to ensure otherwise, and do the needed actions (such as modifying the HP of a single enemy) before getting the UID of the next enemy.
If you are using the layout editor to place your instances, I think you will have to set them manually. Set them as you go, you'll have to go through each object to place them eventually anyway.
In the event that you really do have 1000 objects to place with unique instance variables, it is probably a good idea to set up a system with events to create them dynamically.
You can use placeholder objects and replace them on layout start and set all the properties of the object and its variables.
Or you could use a simple array to store the data - each object would get an x, y, angle, size, instance variable ect, then loop through the array to create all your objects.
Develop games in your browser. Powerful, performant & highly capable.
LaDestitute thanks for the advice
oosyrag I actually want to store all of my objects in the array. But how do i manage all them? Using UID looks like a simple solution for me, but some of those objects have uid from 5000 to 15000.
I was using:
object.x set to array.at(object.uid) to object.x
It works well... kinda.
Since the array is so huge game starts to freeze a little, when player interacts with those objects.
Using IID is not an option. I need something similar to UID but with better performance.
Also could you give me an example to what a placeholder is? (I'll make a guess: it is another sprite, that contains data, so on start of layout i replace "placeholder" with needed object. Right? If yes, thats not what i need)