Instance variable craziness

0 favourites
  • 7 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • I'm making a top-down zombie shooter game, and I want to add a money variable, which is supposed to add five when a zombie is killed and subtract five when the player reloads his weapon. It subtracts 490 instead of five when the weapon is reloaded. Setting it to one makes it subtract 90. It's not a browser issue, as it happens on both Chrome and IE. I've switched it to a global variable, renamed it, and still no dice. Can anyone help?

  • Sounds like it's either firing that event 90 times each time you reload, or it's somehow counting something and adding it all instead of 1. (less likely since you tried global too.)

    Can you show use an example of how it works, so we can see where it might be defying logic?

    (crop out events needed to make it do the same in another Capx?)

  • How? I'd link you to the file on Drive, but I don't have enough rep to post links

  • You can post the URL, just leave out the colon or the slashes for us to fill in.

    (you can probably get to 500 rep real fast too. See the easier rep to earn here: https://www.scirra.com/me/rep )

  • https: / / drive.google.com/folderview?id=0B_WkGaRmOmjwUlRrSEpqeFMwcDA&usp=sharing

    take out the spaces between the slashes

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The problem is the "wait 2 seconds."

    Everything after that action waits 2 seconds before executing, including the "Set Ammo to 10"

    The rest of the game continues while those actions following the "wait" are waiting to execute. So since the Ammo is still 0, and the animation is still 9mm, that event is triggered every tick for two seconds, until the ammo is set to 10, which prevents the event from executing anymore. However there is a whole set of waits built up, so all those actions after the wait continue every tick for 2 seconds more, as all those waits run out.

    I moved the "Set Ammo to 10" above the wait, and it seemed to work.

  • You obviously feeding the variable some trash somewhere. Make sure you initialize the variable when the game starts so it doesn't carry old data (in on start event yourVar=0). Yes, I know it gets set 0 when you make it but I have ran into issues when reloading game w/o restarting where I expected it to 0 and it didn't... so I always 0 my important ones On Start now.

    Second go through every event and action where you reference the variable and make sure its logical (the search in events makes this easy but might be a pro thing).

    If its still wonky they make a debug textbox on your screen and have it show variable every tick, you might spot where its going sideways then.

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