How do I set different instance variable ... ???

Just started using Construct 2? Post your questions here

Post » Tue Mar 22, 2016 10:33 am

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.
B
11
S
2
Posts: 42
Reputation: 711

Post » Tue Mar 22, 2016 11:11 am

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:
Image

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.
Zelda Gamekit (my project)



Example capxs:

Zelda-Style Inventory

Zelda Health

3-saveslot system

[url=https://www.dropbox.com/s/d4396pwak0oh7q6/ZeldaDialogueSystem.capx?dl=0]Zelda-like Dialogue[
B
47
S
24
G
30
Posts: 517
Reputation: 19,464

Post » Tue Mar 22, 2016 11:25 am

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.
Mistakes were made.
B
49
S
24
G
107
Posts: 1,581
Reputation: 60,303

Post » Tue Mar 22, 2016 12:17 pm

@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)
B
11
S
2
Posts: 42
Reputation: 711


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest