Instance variable not picking instances

0 favourites
  • 8 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • I have a very simple line of code:

    [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

    [/code:1qs3cr7o]

    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?

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

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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

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

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

  • DUTOIT - So true. I still haven't figured out For Each. I just try putting it in every event until it works

  • DUTOIT - So true. I still haven't figured out For Each. I just try putting it in every event until it works

    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.

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