How do I pick last object created?

Get help using Construct 2

Post » Tue Sep 22, 2015 9:12 am

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 :cry:
B
7
Posts: 12
Reputation: 314

Post » Tue Sep 22, 2015 10:01 am

You can do like Newt here suggested pick-last-instance_t69019 and use Pick nth Instance and Sprite Count.

System Pick Platform instance Platform.count-1 -> do something.
B
27
S
3
G
1
Posts: 500
Reputation: 2,355

Post » Tue Sep 22, 2015 11:04 am

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 :D thank you a lot. I'll try to use that new knowlodge right away. If it Works I'll come back to tell you :)
B
7
Posts: 12
Reputation: 314

Post » Tue Sep 22, 2015 11:33 am

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.
Image
B
7
Posts: 12
Reputation: 314

Post » Tue Sep 22, 2015 12:00 pm

Sorry, but I don't understand this sentence.
entryz wrote: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?
B
27
S
3
G
1
Posts: 500
Reputation: 2,355

Post » Wed Sep 23, 2015 3:46 am

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 :)
B
7
Posts: 12
Reputation: 314

Post » Wed Sep 23, 2015 6:43 am

entryz wrote: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:

Code: Select all
Create Rainbow


You just have to store the UID of it in a variable or you can use a Boolean that keep track of it:

Code: Select all
Create Rainbow
Set Rainbow.Last_created = true


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: Select all
Set Rainbow.last_created = false
Create Rainbow
Set Rainbow.Last_created = true


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: Select all
Pick Rainbow.Last_created = true


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: Select all
Create Rainbow
Set Last_created_Rainbow_UID = Rainbow.UID


To select it:
Code: Select all
Pick Rainbow.UID = Last_created_Rainbow_UID


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.
B
45
S
12
G
3
Posts: 1,210
Reputation: 7,559

Post » Wed Sep 23, 2015 7:11 am

@entryz

I made a little example. It's that what you're looking for?
https://drive.google.com/file/d/0B5FlDY ... sp=sharing
B
27
S
3
G
1
Posts: 500
Reputation: 2,355

Post » Thu Sep 24, 2015 3:38 am

@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.
B
7
Posts: 12
Reputation: 314

Post » Thu Sep 24, 2015 4:35 am

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!
B
7
Posts: 12
Reputation: 314

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 1 guest

cron