Global Variable is not subtracting after pressing button

0 favourites
  • 14 posts
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • I'm trying to reset a variable to zero after pressing keyboard button. In this case, clicking until zero. When I click to zero, the text correctly displays counting down from five. When I use the button, which divides the reset time by two, and ceils the value. But the variable does not subtract, so clicking until zero is the only solution which works properly? What am I doing wrong?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Even events like this don't work.

  • I think it's because that second "Every 1.0 seconds" condition is under a triggered event so will only happen once when the key is pressed. Try replacing "On R pressed" with a "Key is down" condition.

  • Change it to "R" is down instead of pressed.

    Edit: Sorry, didn't see that you had already got the answer from citron2010

  • citron2010 & TomoloGames , I just tried this, it doesn't work sadly. My value is 5/2 and ceiled to 3, so even with your suggestions, the text display is locked at 3.

  • Your "Every 1.0 seconds" is a subevent. If you press R it will start to wait for 1 second and it will start every tick as long you press R. So your subenvent will not executed. If you release R the subevent won't be executed at all.

    Make it an event not a subevent.

  • Asmodean, I got it to work. This is the event sheet. But I rather just press the button.

    I don't see why just pressing the button, which sets the boolean, and while boolean is true, automatically subtract from the variable. And when variable is zero, just reset everything. I'm trying to build a top-down shooter, and while thinking about it, the logic I formed doesn't seem bad, but I'm doing something wrong. Sigh.

    The normal ammo system, when shooting bullet amount until zero, resets properly, and does the countdown from 5, but when pressing the reload button, pressing R, is supposed to countdown from the reload time, but instead the value stays static, and does not calculate.

    Holding the R button down, does subtract properly until zero, and resets the bullet counter. But most games just allow you to press R, and forget about the reloading system. What am I doing wrong?

  • I like how you have done it. It's really neat and tidy.

    I don't understand what you mean with: I rather just press the button.

    Don't you want an automatic and a manual reload?

  • Don't you want an automatic and a manual reload?

    AsmodeanYeah. The player will move via WASD, and holding the R button down while simultaneously also pressing WASD, doesn't seem realistic. Like press once, and done. Instead of holding R down.

  • Like press once, and done. Instead of holding R down.

    Now I understand. But it should work. Only press R once should work.

  • > Like press once, and done. Instead of holding R down.

    Now I understand. But it should work. Only press R once should work.

    Eh, but it doesn't lol. Anyways, I'm appreciative of the help, it was useful. Need to keep playing with it so eventually everything works.

  • Are you sure it's not another problem? It works fine for me.

  • Are you sure it's not another problem? It works fine for me.

    AsmodeanHonestly, I think something in my current project is blocking it from working properly. I made another project, playing with it and yeah, works as intended. Thanks for seeing if it works for you also.

    Jubilee commences. Now, just need to find out what is blocking the event from working.

  • Asmodean , thank you very muchhh, I finally got it working. Just to show you the new and improved event page.

    Honestly, I'm not sure why the previous version didn't work. Maybe I had two booleans and the event page was confused? Or having two different end events both asking to reset reload values when reload is zero. Anyways, it works now that the events point back to only one reload value, and utilizing one boolean.

    I probably need to understand sub-events better and when to use them lol.

    Hopefully other people will find this useful!

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