Create Object and UID/IID's

Get help using Construct 2

Post » Wed Feb 06, 2013 5:01 am

When using create object, how does one get the new instance's UID and IID back to store for later? Couldn't find any direct answer to this in manual or forums so far. Also, what is the difference between 'create object' and 'spawn object?'
B
11
S
4
G
1
Posts: 159
Reputation: 1,803

Post » Wed Feb 06, 2013 5:27 am

The spawn action is an object action, the create object is a system action.
The consequence of this design, is that if you call the spawn action each picked object will spawn something
The second difference is that the spawn creates an object at the position of the calling object.
In short, spawn is equivalent to:
foreach object -> create object at object.X, object.Y

As far as retreiving UIDs, you shoudl be able to do it like that:
-> Create/Spawn object
-> set variable to object.UID

For IIDs I don't know exactly when IIDs are assigned and/or reevaluated. But usually, since there shouldn't be any "hole" in the IIDs the one attributed to the newly created object should be equal to object.Count. (ie: if you have 3 objects they probably have the IID 0,1,2 so the next one will be 3)

But you shouldn't rely too much on IIDs, I don't exactly know when they are assigned or recalculated, and with so much imprecision you really should use your own indexing (with your own instance variable), and C2 could change their way of doing things. IID are good for temporary uses or when the state of instances don't change.
When there's creation/destruction involved, you're better off handling things yourself or using UIDs.


B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Wed Feb 06, 2013 1:56 pm

Ok, so if I had several instances of an object, and I ran a spawn object, each instance would spawn a new object. But using create object, I would get just the one straight from the system? That makes sense.

Quote/
As far as retreiving UIDs, you shoudl be able to do it like that:
-> Create/Spawn object
-> set variable to object.UID
/quote

So how do I reference the new instance I just created, instead of another that may already be in existence? IE, I'm randomly generating a solar system, with a random number of planets. My random number generator comes up with five, so five planets are created. A few ticks later, I may need to update each individual planet's orbital positions and other data. In other languages/utilities, the creating function would return a pointer, or the equivalent of each planet's instances UID that could be stored and referenced later to get at instance-specific data. That's what I'm after.
This will become very important as I progress in my project, since there will be a great deal of procedural generation going on.

Thank you for your help so far!
B
11
S
4
G
1
Posts: 159
Reputation: 1,803

Post » Wed Feb 06, 2013 2:10 pm

[QUOTE=Yttermayn] So how do I reference the new instance I just created, instead of another that may already be in existence?[/QUOTE]

When you create an object, it is automatically picked so you can store it's UID to array, other object or where ever you wish to reference it later on.

I recommend you learn about picking which is really powerful tool in C2: C2 FAQ

It would allow you to neatly accomplish things like:

Pick all planets
Solarsystem = 'new system'
.. set variables
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Wed Feb 06, 2013 2:17 pm

Thank you, I will check that FAQ.

Another, minor thing: I cannot seem to make local variables. The manual says that they are created under events on the event sheet. Right clicking in the root (blank area) of the sheet gives the option to create a global, which works fine for me, but right clicking anywhere else give no options for variable creation. I am just wanting a couple local variables for number crunching in a function...
B
11
S
4
G
1
Posts: 159
Reputation: 1,803

Post » Wed Feb 06, 2013 2:19 pm

[QUOTE=Yttermayn]
Another, minor thing: I cannot seem to make local variables. The manual says that they are created under events on the event sheet. Right clicking in the root (blank area) of the sheet gives the option to create a global, which works fine for me, but right clicking anywhere else give no options for variable creation. I am just wanting a couple local variables for number crunching in a function...[/QUOTE]

You can just create a global variable and drag it inside the scope you wish to use it in, it becomes local variable. I recall V is quick key for creating variables, that works too.
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Wed Feb 06, 2013 2:24 pm

Hey, that's slick! Thanks! Why isn't that in the manual under variables???
B
11
S
4
G
1
Posts: 159
Reputation: 1,803

Post » Wed Feb 06, 2013 7:31 pm

Hmmm, more problems. I've made my variables I intend to use inside my function local by dragging them into the area just below the part in the event sheet that has my function object name followed by the function's name in quotes. On my screen its a blank, light purple colored area. This made the variables local and they would seem to be part of the function. When I try to calculate something using them in a system->set (variable) to blahblah event, C2 tells me that my local variables(whichever one it encounters first) are an unknown expression in this scope.
B
11
S
4
G
1
Posts: 159
Reputation: 1,803

Post » Wed Feb 06, 2013 7:50 pm

By looking at examples, I can see that the authors somehow got their local variables to appear above the events that use them within the same scope, but I am not able to move them or otherwise coax them to do the same on my event sheet. It's like trying to unwrap a stick of butter with socks on your hands! (don't ask)
B
11
S
4
G
1
Posts: 159
Reputation: 1,803

Post » Wed Feb 06, 2013 7:51 pm

They are probably one level too low in scope then, screenshot of the area could help to solve this.
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Next

Return to How do I....?

Who is online

Users browsing this forum: DiabloOvermind, emoticon, MrWhizm, Skebab and 16 guests