Instance variable not picking instances

Get help using Construct 2

Post » Sun Mar 02, 2014 10:24 pm

I have a very simple line of code:

Code: Select all
[EVENT]                                     [ACTION]

Sprite1.TimerVar > 0
>>>>>    Every 0.1 Seconds    ....    Subtract 1 from Sprite1.TimerVar

Else
Sprite1.TimerVar = 0

>>>>>     Trigger Once    ....    Set Platform Enabled
>>>>>     On Platform Landed    ....    Set Sprite1.TimerVar to Sprite1.TimerMax, Set position to Sprite1.DefaultPosX & PosY


What this could SHOULD do, is for each sprite1 that reaches a timer of 0, the platform should become enabled. I've done some tests, and the Timer is getting set to the TimerMax variable for each individual sprites, each sprite is being reset to their respective locations, but it waits until only ONE of the sprites reaches a timer of 0 and then they all fall together instead of individually like they're supposed to.

I don't understand why it's picking the instances for the "On Platform Landed" event, but not for the Sprite1.Timer instance variable.....can anyone shed some light on this?
B
40
S
12
G
1
Posts: 533
Reputation: 4,149

Post » Mon Mar 03, 2014 6:35 am

You have to wrap it up in foreach sprite1
insert events
else (this is optional)
do something else.

Sprite is singlular and will only do the first instance of first sprite.
Foreach loops through each instance of the sprite1. Hence instance variable, and instance variable of a particular instance of that sprite1

I just did something similiar, not time but locations of sprites moving and touching other objects.
This is how I understand it, and it works for me (using the foreach).
It takes some trial and error getting the sequence right with the flow of events too.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,718

Post » Mon Mar 03, 2014 6:46 am

Another idea is to try removing the else condition. As I recall the else will only be run if nothing was picked in the event above.
B
92
S
32
G
110
Posts: 5,295
Reputation: 71,501

Post » Mon Mar 03, 2014 7:59 am

R0J0hound wrote:Another idea is to try removing the else condition. As I recall the else will only be run if nothing was picked in the event above.



This, you can even stuff multiple picks in a single event, if 1 of the picks fails to pick anything, the else will be used.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Mon Mar 03, 2014 8:05 am

@DUTOIT, @ R0j0hound, @lennaert - thanks for the replies. I've tried For Each, removing the else, and a magnitude of other stuff before I posted. I did, however figure it out in case you guys were curious.

For some reason I had to switch the "Timer > 0" with the "Timer = 0". Apparently due to the "Timer = 0" event having an "Else" attached to it, it wasn't able to pick the instance, like you stated. I was, however, able to keep my Else :) Strange, but at least it's solved. Thanks again!
B
40
S
12
G
1
Posts: 533
Reputation: 4,149

Post » Mon Mar 03, 2014 8:10 am

Glad it is solved. I spent a fair amount of time getting my own correct. Amazing how a little thing can bring it to a halt.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,718

Post » Mon Mar 03, 2014 8:15 am

@DUTOIT - So true. I still haven't figured out For Each. I just try putting it in every event until it works :P
B
40
S
12
G
1
Posts: 533
Reputation: 4,149

Post » Mon Mar 03, 2014 8:17 am

ome6a1717 wrote:@DUTOIT - So true. I still haven't figured out For Each. I just try putting it in every event until it works :P


Lol, I did that too for wait 0.5 seconds. I was almost pulling my hair out trying to get a object to wait a beat, and eventually just added it all the way up the foreach sequence of events till I found the right spot.

I'm still trying to understand why it only works where it works. Will have to ponder it over a whiskey one night.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,718


Return to How do I....?

Who is online

Users browsing this forum: Artcadev, brunopalermo, Euduardo, Google [Bot], Jackriduk and 26 guests