reference the object I just created?

Get help using Construct 2

Post » Thu Jul 25, 2013 11:31 pm

If I want to create a ball, then do stuff with it (e.g. move it around), that's easy. But If I want to create an instance of say a blue, black or red ball, then do the same stuff with which ever one I just created?

E.g. inn bingo, the balls are different colours depending on the number just called.

E.g. if the number is between 1 and 15, create a blue ball
if the number is between 16 and 30, create a green ball.

Then I want to do a whole lot of stuff with that ball. But I dont want to have to duplicate all that code for each ball colour, and I dont think you can pass balls (objects) in as parameters to a function.

I actually solved the problem by making the balls different frames of a single sprite, but I'm interested if there is another way for cases where the sprite hack would not have worked?

Many thanks for your thoughts.
B
17
S
6
G
3
Posts: 370
Reputation: 3,942

Post » Thu Jul 25, 2013 11:35 pm

You can pass a UID, and pick it again in the function. You have to be careful with creating and immediately picking. This has been documented many times on other threads, so I won't start that up again.
ImageImageImage
B
71
S
22
G
259
Posts: 3,793
Reputation: 143,702

Post » Fri Jul 26, 2013 10:31 am

Er, if you cant create then pick, what is the recommended solution? Create, wait, then pick? That would seem tricky?
B
17
S
6
G
3
Posts: 370
Reputation: 3,942

Post » Fri Jul 26, 2013 10:59 am

Ok, my solution did not work. I have tried the following:
1) Spawning a copy of an existing (off layout) ball object, then using ball->set x etc. in actions in the same event block. This moves all balls, not the one just created.
1) assigning a intance variable called "justCreated" and set it to 0. Use System->create object to create a new ball. In a sub event, select ball where justCreated = 0, and set it to 1. Do stuff to that ball. This doesnt work as it affects the newly created ball, AND the template/dummy ball which is only there to allow new balls to be created.

Can anyone point me to a man page, thread, or capx which shows how to pick the object you just created/spawned?

Thanks!
B
17
S
6
G
3
Posts: 370
Reputation: 3,942

Post » Fri Jul 26, 2013 11:17 am

I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Jul 26, 2013 1:48 pm

This does not seem to work for me. If I create a new ball object for example, then use ball.xx in the action of the same or a sub event, it always acts on all balls, not the one I just created.   As I don't know how to pick the event I just created, I actually do this:
1) have he ball on a special layer, called "templates"
2) have a blank layer called "new"
3) create a new "ball" object on layer "new".
4) use an event condition where I say ball.isOnLayer("new")
5) then in the events actions, do this: ball.setLayer("target")
B
17
S
6
G
3
Posts: 370
Reputation: 3,942

Post » Fri Jul 26, 2013 2:03 pm

This event works only on the one created:



I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Jul 26, 2013 3:53 pm

@LittleStain

good exmaple. Do you have to destroy the template object like this? I havent done this, which could be why in your third action its affecting mutliple sprites. Or perhaps because my equivalent of Sprite3 is in a family with lots of other copies of Sprite3?
B
17
S
6
G
3
Posts: 370
Reputation: 3,942

Post » Fri Jul 26, 2013 4:05 pm

Destroying should have no impact on the second event. Your problem probably lies somewhere else in your code.
The family also shouldn't affect it unless your other actions are affecting the whole family instead of just the created object.
I suspect you mean clones of sprite 3 instead of copies?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Jul 26, 2013 4:08 pm

Here's the link to my capx

I created a family in it just to try out if it would affect anything, but like I suspected it changes nothing.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Next

Return to How do I....?

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 27 guests