How do I pick last object created?

Get help using Construct 2

Post » Thu Sep 24, 2015 6:22 am

entryz wrote:@nimos100 For what I understood both of these methods would only apply if I wanted to spawn the item on top of the rainbow only once, isn't it?
I don't know how I could store the UID for each rainbow on a regular interval of 10 rainbows created or 10 seconds passed.
And I also couldn't figure out how I could set "Rainbow.last_created = false" to all other rainbows...
I sense that it's pretty simple and its me that just can't understand much you meant... And I'm sorry for that. But I guess I'll figure it out soon. Everyday I'm learning more. Specially with you guys.

Thank you again!


The method will allow you to work with the last created rainbow until another is created. So in the case that you for instant wanted to spawn something on that rainbow as you said. But also if you wanted to for instant make a rainbow slowly rotate etc. So basically it will just allow you to apply whatever settings to a rainbow as long as its the last created one.

Its sounds to me like you are a bit uncertain about how picking works?
When you create an object (Rainbow):

Code: Select all
Create Rainbow


All actions beneath this in the same scope or any sub level will apply to the created Rainbow. So here is an quick overview of how actions work depending on where they are placed in relation to the "Create object":

Code: Select all
<All actions here will apply to all rainbows, because you haven't picked any specific rainbow yet>
Create Rainbow
<All actions here will apply to the last created rainbow>
---> (Sub level)
---> <All actions here will also apply to the last created rainbow>


So to set all "Rainbow.last_created = false" first you of course would have to create the variable in the rainbow object. Then add the "Set Rainbow.last_created = false" before the create Rainbow, because you want it to apply to all Rainbows and not only the last one created.

But anyway if Asmodean solution does what you need, then its of course good. But in general picking objects can be quite confusing at first and not uncommon that it causes a lot of problems for people starting to learn C2. Despite it seems simple, its crucial that the rules for picking are done correctly, otherwise it can results in a lot of weird problems.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,838

Post » Thu Sep 24, 2015 10:22 am

@entryz
You're welcome. Don't hesitate to ask if there is something unclear.
B
24
S
3
G
1
Posts: 451
Reputation: 2,165

Post » Sun Sep 27, 2015 11:45 am

@nimos100
Thank you very much for that last code section you wrote. That clarifies a lot. It's so obvious and I already knew that but because I've learned for myself I didn't actually stiched that to my memory.

But anyway, now I understand that this first method of "1= true and everything else = false" is the methoted that Asmodean presented to my on his .capx exemple. Right?

But how about the other method? It's still unclear to me how could I store the uid for the specific object on the circunstances that I need. And despite the solution that I already have, it's always good to understand the options and really learn about stuff instead of just copying... Of course if you could take your time again and try to explain it

By the way do I need to close this topic or something? I don't really know how to do that.

@Asmodean
There are still things that I don't understand but I figured out most of it. And I need to learn by myself also. Thanks anyway for willing to help me. And thank you again for all that you did to help me already :) I'm trully happy about the reception here from you guys.
B
7
Posts: 12
Reputation: 314

Post » Sun Sep 27, 2015 12:56 pm

entryz wrote:@nimos100
But anyway, now I understand that this first method of "1= true and everything else = false" is the methoted that Asmodean presented to my on his .capx exemple. Right?

Yeah pretty sure that was the idea behind it.

But how about the other method? It's still unclear to me how could I store the uid for the specific object on the circunstances that I need. And despite the solution that I already have, it's always good to understand the options and really learn about stuff instead of just copying... Of course if you could take your time again and try to explain it

The reason you can do it, is because as you create an object you have already picked it. So you can store the UID. Simply by doing "Stored_UID = Object.UID" So in this case you can say that the condition for the picking is that, its the last object created.
Compared to a "normal" condition like "Object.Name = James" would pick all objects which name are "James". This would just store the UID of the last object created, and you can then pick it later on using this.

"Object.UID = Stored_UID"

Which would be the same as doing "Object.Last_created_Object = true" but when using the UID you don't have to change "Last_created_object" to false all the time, because there can only be one last created object at the time. So you know that the "Stored_UID" will always be the UID of the last one created.

By the way do I need to close this topic or something? I don't really know how to do that.

You don't need to close topics it will "close" by it self when no one answer to it anymore :D
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,838

Post » Mon Sep 28, 2015 10:55 am

@nimos100
Thanks again man. Now I could finally understand what you mean. But the thing I can't see is how I would store de UID or retrieve it when I need it. I mean, until now i'm using the system condition "compare two values" when I need the game to know some global value. I'm still crawling around the expressions. I would guess that that's how you do it? Which the expressions?

I don't know even the basics of logical programming... That must be the reason it gets so hard for me to communicate with you.

Aaand is there anyway I could give you guys some prestige? Like an upvote or something.
B
7
Posts: 12
Reputation: 314

Post » Mon Sep 28, 2015 11:17 am

entryz wrote:@nimos100
Thanks again man. Now I could finally understand what you mean. But the thing I can't see is how I would store de UID or retrieve it when I need it. I mean, until now i'm using the system condition "compare two values" when I need the game to know some global value. I'm still crawling around the expressions. I would guess that that's how you do it? Which the expressions?

I don't know even the basics of logical programming... That must be the reason it gets so hard for me to communicate with you.

Aaand is there anyway I could give you guys some prestige? Like an upvote or something.

Sure no problem.

You can store the UID in a global variable, "Pressing V" while not in an event and you just name this "Last_created_UID = 0" this can then be used to store any number you want.

Since its global it means that its available to you from anywhere in the project. So when you need it you just do like this:

Code: Select all
Pick Object.UID = Last_created_UID


"Compare two values" doesn't make the system know anything, its simply compares two values and you can use the result to trigger whatever you need to. But maybe that was what you meant? But more important which is a normal mistake new users make is that they think that compare two value picks something, so it results in bugs, normally in the sense that suddenly more objects do things, where they thought it was only the one they "Picked". But "Compare two values" simply compares two value nothing more. So you have to pick the correct objects to compare before hand or it will cause problems. For instant:

Code: Select all
Compare Object.UID = Last_created_UID
----> Object.destroy


This would destroy all Object and not only one. So therefore you need to pick the correct Object first:

Code: Select all
Pick Object.UID = Last_created_UID
Compare Object.type = "Rabbit"
----> Object.destroy


Here you first Pick the object which UID is equal to the global variable "Last_created_UID" and if that Object have a type which is "Rabbit" it will be destroyed.

The reason I changed the compare to "Type" is because it doesn't really make sense to compare UID using "Compare two values" as it doesn't pick anything and because if "Pick Object.UID = Last_created_UID" is true you already know that they have the same value and you have already picked it. So when you pick something you are at the same time performing a comparison automatically.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,838

Post » Wed Sep 30, 2015 6:11 am

@nimos100

I think I'm getting to undestand this... Now I just need to practice more.
There is still stuff that I dont quite get but I figured that I only need to work more. Just complaining and listening to you won't teach me all that I need to know.

Thanks again nimos100. Now we can let this topic close by itself I guess...
I wish someday I can help people like you and Asmodean help'd me. Or even help you and him on the next years.
See you around :D
B
7
Posts: 12
Reputation: 314

Previous

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 5 guests