How do I pick last object created?

0 favourites
From the Asset Store
Show your master of martial arts by killing all flies empty handedly!!!
  • Sorry to be asking this and hope I'm in the right forum.

    So i'm trying to make a Doodle Jump/Infinite Jumping game. I wanted to create an instance on the platforms or something that could make the game understand that THAT PLATFORM was the last created. Like to spawn an item or something on that block only.

    The ideia is like: The game is randomly creating infinite platforms. But when someone is created I need that to be the last. Them the next created to be the last, and the next... And so on. But just only one can be the last, right? So the previous last will be just another random block inside the layout.

    I'm trying to cut aroud this issue but the game keeps getting buggy and the Event Sheets ridiculous hahaha.

    I've been searching for a few days here in the forums and google but still couldn't find an answer.

    Hope somebody can help me

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • You can do like Newt here suggested and use Pick nth Instance and Sprite Count.

    System Pick Platform instance Platform.count-1 -> do something.

  • Hey Asmodean thx por replyin so quickly! I've tried to go on that .cout thing but to be honest with the Manual wasnt enought for me to understand how that work... But now i think you gave me some insight

  • So I'm still trying to figure out but testing seems like this method wont work... Maybe I'm just thinking wrong about what I need.

    Because the item that i want to show on the last created platform keeps going to the last created platform instead of being there until reaching the bottom or player touching it.

    The image is just for you to try to understand what i'm trying to do... The Rainbows are blocks and that 90º was just to text the conditions.

    Also I know that the way I put to create object is all wrong.

    I need to create a better instance maybe. And them spawn the object and cancel that instance afterwards until I want to spawn another object there.

  • Sorry, but I don't understand this sentence.

    Because the item that i want to show on the last created platform keeps going to the last created platform instead of being there until reaching the bottom or player touching it.

    Do you want that the item to remain on the 'last' platform where the item is created and is not exclusively on the last created platform?

  • Yeah I know that doesnt makes much sense but I don't even know how to express what I need... Perhaps I'm also thinking wrong.

    Did you ever play doodle jump? I need some item to spawn on top of a the highest platform visible and then stay there. If you passes through it upwards the item need to stay on the platform it was created and go down with it.

    What is happening is that the item is created at the highest platform and them when the player passes through it, it goes to the highest platform again and again. Never descending to be on the second highest platform on the layout.

    Maybe I could make the item spawn in another way... But how should I? The other methods turn out to be buggy. Like I've tried to spawn that item randomly on the top of the screen and a platform attached to it. That messes with the game a lot

    I would be really glad if you or anyone could point me to the right direction here. Maybe picking the last created platform just isnt the right method. And thanks for already try to help me Asmodean

  • I would be really glad if you or anyone could point me to the right direction here. Maybe picking the last created platform just isnt the right method. And thanks for already try to help me Asmodean

    The easiest way to do this is to use the UID or a Boolean "Last_created" variable I think. Since you always know that when you create a rainbow it must logically also be the last one created, which means that you already know which rainbow this is. So when you create a rainbow:

    Create Rainbow[/code:3nfu36u6]
    
    You just have to store the UID of it in a variable or you can use a Boolean that keep track of it:
    
    [code:3nfu36u6]
    Create Rainbow
    Set Rainbow.Last_created = true
    [/code:3nfu36u6]
    
    However to make sure that only the last created rainbow is marked as being the last you need to make sure that all other rainbows "last_created" variable is set to false:
    
    [code:3nfu36u6]
    Set Rainbow.last_created = false
    Create Rainbow
    Set Rainbow.Last_created = true
    [/code:3nfu36u6]
    
    That should solve the problem, however you might have to put the "Rainbow.last_created = false" in its own event or function before creating the new one. But im pretty sure that it will work fine without it, and that the "Create" action will automatically pick the correct one for you. 
    
    When you need to work with the last created rainbow you simply use:
    
    [code:3nfu36u6]
    Pick Rainbow.Last_created = true
    [/code:3nfu36u6]
    
    That should only pick the last one that was created. If you want to use the UID instead you simply make a Global variable called "Last_created_Rainbow_UID" and here you store the UID of the Rainbow:
    
    [code:3nfu36u6]
    Create Rainbow
    Set Last_created_Rainbow_UID = Rainbow.UID
    [/code:3nfu36u6]
    
    To select it:
    [code:3nfu36u6]
    Pick Rainbow.UID = Last_created_Rainbow_UID
    [/code:3nfu36u6]
    
    You only need one of the method not both. Personally I would prefer the UID way, since its unique and no matter what you can only pick one rainbow, so chance of making error is very low.
  • entryz

    I made a little example. It's that what you're looking for?

    https://drive.google.com/file/d/0B5FlDY ... sp=sharing

  • Asmodean

    nimos100

    Guys, you're awesome. Really! Thanks a lot a lot a lot.

    Sorry for taking so long to reply here. My spare time is really scarce these days.

    I'll jump right away on testing those new information you gave me and come back later.

  • Just so you know i've searched here if I could give you guys +rep or something. Because you deserve it.

    Asmodean Your .capx fits perfectly on my newbie mind. You solved my problem teaching me how to manage with it and I don't know how could I thank you for that.

    Despites that are some things that I don't know why you put there because I don't entirely know how they work... I'm still messing with it to try to undersand. But what's important is that I got the funciontion that I wanted! Haha thank you really.

    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!

  • 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):

    Create Rainbow
    [/code:2h16dx1w]
    
    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:2h16dx1w]
    <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>
    [/code:2h16dx1w] 
    
    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.
  • entryz

    You're welcome. Don't hesitate to ask if there is something unclear.

  • 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.

  • 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.

    [quote:2tttmvz9]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.

    [quote:2tttmvz9]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

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)