Pick object with function

Get help using Construct 2

Post » Thu Apr 11, 2013 4:05 pm

So I have a whole bunch of platform objects. They all have an instance variable called "trigger" which I change to different values to achieve different things. Right now I do

-Player: On Colission with platform
-- Platform.trigger != 0
-> call function "te_" & platform.trigger

- On function "te_1"
-> platform destroy

It's calling the function perfectly fine, but is deleting every platform instead of the one the player collided with. I know this has something to do with it not passing the platforms id to the function so it knows the specific one to delete. But how do I make it so it knows which one to do?

Sorry if it's confusing, I'm not the best at explaining things. EncryptedCow2013-04-11 16:07:46
B
40
S
12
G
7
Posts: 603
Reputation: 7,646

Post » Thu Apr 11, 2013 4:14 pm

When you call the function, add a parameter, and set it to the platforms UID. Then in the function, use the "Pick by UID" condition, and set it to the function parameter.

-Player: On Collision with platform
-- Platform.trigger != 0
-> call function "te_" & platform.trigger(Platform.UID)

- On function "te_1"
-Pick Platform by UID (function.param(0)
-> platform destroyzatyka2013-04-11 16:14:40
B
44
S
13
G
7
Posts: 338
Reputation: 10,379

Post » Thu Apr 11, 2013 4:17 pm

@zatyka

I can't test it out right now but that makes perfect sense. Thanks!
B
40
S
12
G
7
Posts: 603
Reputation: 7,646

Post » Thu Apr 11, 2013 4:57 pm

Um, why do you need the function?
If you are changing that objects variable you can just compare it, and use that as a trigger.
No need for all the uid stuff. The object is automatically picked by its variable.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Thu Apr 11, 2013 5:02 pm

@newt

It's not just destroying that I'll be doing. I plan on having a bunch of functions that do different things depending on the trigger variable. I guess I could just have trigger = 1, trigger = 2, ... subevents. In my head this seemed like it would reduce the amount of events I would be using. (I have the free version so I have to watch my events)
B
40
S
12
G
7
Posts: 603
Reputation: 7,646

Post » Thu Apr 11, 2013 5:42 pm

First of all why can't you destroy the object from the initial event?
It looks like its picked by the collision.

Second you would need a sub event to destroy it since you cant pick to destroy from actions.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Thu Apr 11, 2013 5:53 pm

@newt

I don't want to just destroy every platform when the player touches it. Each one can do different things depending on what trigger equals. So most of them will = 0 meaning it wont do anything on contact. 1 means it will delete when touched, 2 would make it disappea for 5 seconds for example. I get now that functions wont save on events and will just over complicate it. I'm just going to make sub events of on collision.
B
40
S
12
G
7
Posts: 603
Reputation: 7,646


Return to How do I....?

Who is online

Users browsing this forum: Baidu [Spider], BinaryPanda, MarkThomas and 19 guests