How do I store a link to one object within another?

For questions about using Classic.

Post » Sun Dec 09, 2007 2:15 am

Here's an image of my event sheet:



I'm wondering if it's possible to retrieve an object by its Unique ID, so I can use it in the expression that sets the Soldier's angle (for bullet movement, it's the one I've circled in the screenshot) so it chases the correct RouteMarker.

I know that I could just use the RouteMarker just created, but I'm planning on having a chain of RouteMarkers, each stores the UID of the next RouteMarker in the chain, which the Soldier reads and then heads towards... am I on the right track?
B
2
S
1
G
5
Posts: 15
Reputation: 1,430

Post » Sun Dec 09, 2007 2:28 am

If you want the 'Soldier' to follow the 'Routemarker' created in the same event, that's easy: just use Routemarker.X, Routermarker.Y and it will refer to the one just created. When you create an object, for the rest of the event, all actions and expressions refer to the created instance.

If later you want it to set its angle to the instance with the UID stored in its private variable, you can do something like:

+ For each Soldier
+ Routemarker Unique ID = Soldier('CurrentRouteMarker')
: Soldier: set angle to Routemarker.X, Routemarker.Y

This will check each soldier individually (instead of trying to do them all at once), find the correct routemarker, and use that to set the angle.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Sun Dec 09, 2007 2:44 am

[quote="Ashley":2f6z6j8x]If later you want it to set its angle to the instance with the UID stored in its private variable[/quote:2f6z6j8x]

Yes, that's what I was after, thanks.

[quote="Ashley":2f6z6j8x]
+ For each Soldier
+ Routemarker Unique ID = Soldier('CurrentRouteMarker')
: Soldier: set angle to Routemarker.X, Routemarker.Y
[/quote:2f6z6j8x]

Sorry, but I don't understand the bold part, how do I put this into the event list?
B
2
S
1
G
5
Posts: 15
Reputation: 1,430

Post » Sun Dec 09, 2007 2:50 am

Right click, select your object. Under Misc, pick "Compare unique ID."
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Sun Dec 09, 2007 3:21 am

Sorry, right click where? I must be missing something obvious, the only thing under Misc is "Destroy".
B
2
S
1
G
5
Posts: 15
Reputation: 1,430

Post » Sun Dec 09, 2007 3:24 am

It's the condition 'Compare unique ID' :P You're trying to add an action.

So right click an existing condition and Insert a new condition, or right click an empty space and insert a new event...
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Sun Dec 09, 2007 3:37 am

It worked! Thanks for the fast response.
B
2
S
1
G
5
Posts: 15
Reputation: 1,430

Post » Sun Dec 09, 2007 9:51 am

Sorry for bringing it a bit off-topic, but it sounds like the question was answered to the thread starters satisfaction. :)

How do I create and call functions?
I cannot find anything inside 0.86.2 that let me define and call them.


EDIT: nevermind! Found out that you can add a object called function. :P Thanks anyway. :)
B
2
S
1
G
5
Posts: 50
Reputation: 1,500


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests