Instance variable craziness

Get help using Construct 2

Post » Tue Oct 27, 2015 1:06 am

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?
B
5
Posts: 8
Reputation: 243

Post » Tue Oct 27, 2015 1:32 am

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?)
B
226
S
60
G
33
Posts: 902
Reputation: 39,975

Post » Tue Oct 27, 2015 3:22 pm

How? I'd link you to the file on Drive, but I don't have enough rep to post links :(
B
5
Posts: 8
Reputation: 243

Post » Tue Oct 27, 2015 8:29 pm

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 )
B
226
S
60
G
33
Posts: 902
Reputation: 39,975

Post » Tue Oct 27, 2015 11:17 pm

https: / / drive.google.com/folderview?id=0B_WkGaRmOmjwUlRrSEpqeFMwcDA&usp=sharing
take out the spaces between the slashes
B
5
Posts: 8
Reputation: 243

Post » Wed Oct 28, 2015 5:17 am

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.
B
226
S
60
G
33
Posts: 902
Reputation: 39,975

Post » Wed Oct 28, 2015 6:31 am

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.
Check out my completed games on the Arcade! Capt. Doe Save the Universe! & Clicker Wizard!
B
65
S
17
G
8
Posts: 635
Reputation: 9,331


Return to How do I....?

Who is online

Users browsing this forum: MadSpy and 3 guests