if variable changes

0 favourites
  • 10 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • How can I set up an event for if instance variable is added to, X happens?

  • system compare variable1 not equal to variable2:

    set variable2 to variable1

    do x

  • Burvey

    There isn't a trigger for this that I've found. (That is, a reactive trigger that will happen whenever the variable changes anywhere. Personally, I want these too, but I can see why they aren't in the software).

    I've been able to handle this in two ways:

    1) Have two variables instead of one. The old value that only gets set in my checker and a "new value" everywhere else. I can compare to see if it got set Every Tick.

    2) Or, I create a function that handles the what I want to do and call it everywhere I change the value.

    Neither is truly reactive, but they work.

  • PixelHero

    It doesn't make a big difference. Method number one would most probably be, what a trigger would also do behind the scenes. So it's as reactive as it can be <img src="smileys/smiley1.gif" border="0" align="middle" />

  • PixelHero

    What I'm trying to do is change the bullet speed each time an enemy is hit. The way I have it now works which is the following:

    If enemy hit is > 0 and <= 10 then set bullet speed to 100

    If enemy hit is > 10 and <= 20 then set bullet speed to 110

    If enemy hit is > 20 and <= 30 then set bullet speed to 120


    It works but it takes a lot of events to do it and is a bit choppy. What I want to do is make it so that each time an enemy is hit, the bullet speed increases by 1. I tried using bullet.Bullet.Speed +1 along with the event that hit's an enemy, but it only works for the specific bullet. I need it to work with all bullets. Any ideas how I can get that to work correctly?

    Thank you.

  • Would something like this work?

    global number bspeed=100

    bullet collides with enemy

    pick all bullet

    ---> add 1 to speed

    ---> set bullet speed to bspeed

    The "pick all" condition can be used so not just the bullet that collided is selected. "bspeed" is a global so when you create new bullets you can set there speed bspeed. Of course that's just an assumption, you could also just omit the global and use bullet.Bullet.Speed +1.

  • Or you could use:

    bulletspeed = 100+floor(enemyhit/10)*10

  • R0J0hound

    Using the global like that did work, but unfortunately for some reason it messed up another part of the game. I guess I'll just leave it as I have it. I just wish it didn't take me 30 events to make it work lol

    Thanks everyone for your input.

  • Or you could use what I wrote.

  • Try Construct 3

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

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

    Just saw that, I'll give that a try.


    After an hour or so of fiddling and changing my code I was able to get a variation of your code to work. Thank you for your help.

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