How do I select the last object created? [SOLVED]

Get help using Construct 2

Post » Mon Mar 07, 2016 1:58 am

For example, say I have a block and I have a System event that creates a new block. How can I select only this newest created block and move its location without moving the last one created? I can elaborate more if needed.
Last edited by TabloidA on Mon Mar 07, 2016 12:29 pm, edited 1 time in total.
I like giving game advice more than I actually like making games ;)

Image
B
40
S
15
G
3
Posts: 129
Reputation: 4,651

Post » Mon Mar 07, 2016 2:51 am

When objects are created, they are immediately picked by default, so any actions you have affecting this object only affects the newly created instance within the same event.

A more advanced topic would be if you wanted to specify only the last created instance of an object in an expression - you can do this with the IID - Sprite(-1).Expression, where the -1 represents the last created instance of this object. https://www.scirra.com/manual/78/expressions
Mistakes were made.
B
49
S
24
G
107
Posts: 1,579
Reputation: 60,299

Post » Mon Mar 07, 2016 12:29 pm

A more advanced topic would be if you wanted to specify only the last created instance of an object in an expression - you can do this with the IID - Sprite(-1).Expression, where the -1 represents the last created instance of this object. https://www.scirra.com/manual/78/expressions


This worked beautifully. Thank you!
I like giving game advice more than I actually like making games ;)

Image
B
40
S
15
G
3
Posts: 129
Reputation: 4,651

Post » Mon Mar 07, 2016 10:57 pm

Already solved, but may I suggest UID instead of IID? UID is more reliable, and never changes unlike IID.
Have a global variable, and set it's value to the following, right after you spawn a new object (when you tell the game to):
int(ObjectName.UID)

Then in conditions that require to be instance specific (such as lifting a pot in Zelda), you set a pick UID condition, except set it to the global variable name.

Image
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
46
S
24
G
30
Posts: 516
Reputation: 19,437


Return to How do I....?

Who is online

Users browsing this forum: marc254 and 10 guests