trigger once and instances

0 favourites
  • 12 posts
From the Asset Store
Change the size and position of everything without calculating anything!
  • lucid as well :)

    hi to the community !i need your help.

    for the past 2 days i am trying to figure out what is going on until i stumbled on this thread.http://www.scirra.com/forum/r154-for-each-and-trigger-Once_topic82932.html

    i have for example 3 instances of a scml animation(spriter).it is in a container with a sprite box background and i run it every tick on top of it.

    i have a LOS (line of sight ) behavior on my sprite box

    if "sprite box" has LOS on player----set scml animation to "walk"

    if "sprite box" has NOT LOS on player----set scml animation to "IDLE"

    if i use this, then the animation gets stuck on the first frame (no tweening no nothing)because i think it runs every tick so it resets 60 times per second and plays from the beginning all the time .

    if i add a sub-event "trigger once while true" it works(the animation) up to the moment it switches between LOS and NOT LOS and the reason is in what Ashley said that it is a system condition(the "trigger once") and does not pick instances!so only one instance switches between idle and walk and the rest stay on the previously played animation (wish i knew that 2 days ago :p) maybe i could use uid but that would be a pain to implement if i have 20 instances of my scml in every layout.

    so any ideas on what to do to solve this?

  • And if you add the condition "animation walking is not playing"?

  • why not use an else condition instead of the has not los?

    or am I missing the point?

  • Games

    i lost you there for a moment but thank you for your interest to help me.

    the problem is that for conventional animations (png's) using the platform behavior ashley has programmed conditions that trigger animations (on landed,on stopped etc).

    in my case the system correctly picks every instance change(los ,NOT los) -it is built in ,you don't even have to say "for every"-,every instance variable change everything.

    it even changes the animation as intended but to ONLY ONE INSTANCE at a time. the rest are ignored.

    i hope i was more clear this time

  • LittleStain

    if i use "else" the it does not pick .it just makes them all behave the same.

    my problem lies in the fact that if i do not use "trigger once while true"

    then my animation loops every tick so it gets stuck on the first frame.if i use it it plays fine BUT it does not pick instances so it only triggers for the first instance and the rest of them still play the old animation.

    example. 3 spiders with LOS 600pixels

    if the see you (<600) play "walk" if not (>600) play "idle"

    they cant see you at first so the are all "idle"

    you move closer and all of them see you. only one will play "walk" (using the "trigger once")the other will stay "idle"

    now if you move away only one will play"idle" the rest will stay on animation "walk"

    see my problem? :)

  • Shouldn't they only play the walk animation while walking?

    So wouldn't it be easier to start moving on los and set animation walk when moving?

    I'm under the impression the problem is not where you think it is. This sounds more like a conflicting event issue. Are you setting the animations anywhere else in your event sheet too and are the conditions for that event true aswell?

  • LittleStain

    thank you for your time!

    if i use "else" the it does not pick .it just makes them all behave the same.

    i have a sprite box with path finding behavior that i set invisible and i add "every tick" on top of it my scml(spriter) animation.so the box moves.the "animation"(spider) just moves on top of it and it just changes its animation depending if the "box" is moving or not.since they are in a container every time i spawn a "box" it spawn a spider"animation" on top of it.so if any of the "boxes" has LOS to the player then enable "pathfinding" and move. so play "walk" animation for spider.

    if not "set pathfinding disabled" so it stops and play "spider" animation "idle".

    my problem is that because the "has los" or "does not have los" runs every tick when it is true the animation will loop every tick so it will get stuck on the first frame(it is not frame it is tweening but you get the picture :p).

    if i add a "trigger once while true" it will run fine the animation because it will not loop every tick BUT this command does not pick instance so it will only work on the first available instance. not the rest.

  • Would something like this work?

    for each box

    box has line of sight

    box is not moving along path

    • find path

    For each box

    on path found

    • move along path
    • set animation to walk
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Asley

    lucid

    LittleStain

    unfortunately no my friend.

    my results so far .

    if i use the build in commands for my scml files (on landed,on moved etc)

    it works in all instances correctly.

    if i want to trigger an animation without the above i need to apply the "trigger once while true" so it will not get stuck on the first frame. this workaround works for only one instance perfectly. i can call any animation i want depending on the situation.

    but if i have multiple instances then the "trigger once" does not pick instances and it works only for the first it picks.

    any ideas from the other gurus in here?

    mr. Asley please?

  • You need to add an instance variable to the entity you change the animation on

    In sight> Do stuff + set variable to 1

    Not In sight + Variable=1 > Do stuff, set variable to 0

    This makes it when they are not in sight, that it checks for that variable, and if that variable is 1 (because it was set when they were in sight), then it does stuff and sets the variable to 0

    Since the variable is 0 for that entity next tick, it does not trigger the not in sight actions again. This makes it so it leaves whatever you had set, set.

    This is essentially how the Trigger Once condition works, except you're coding it in-engine for specific entities.

  • Thndr

    you are a life saver!

    so simple and yet I lost 2 days of my life with this.

    sometimes you overthink I guess :p

    I had tried your way before and failed but with your advice I felt confident that this is the right way to go so I experimented a little bit and here is the result for future reference for people who get stuck like me

    dropbox.com/s/mx1vd1132no5va4/Screenshot%202014-02-18%2011.07.24.png

    I owe you a beer!

  • Yeah I wasted like a day or so myself until I did that, trying to figure out how I went wrong since a function kept going off every tick and then suddenly it came to me, seemed backwards, but it works and I can't simplify it more so :D

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