Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Variable keeps resetting back to zero, causing code to become bugged up =(

Author
Message
anwserman
15
Years of Service
User Offline
Joined: 20th May 2011
Location: Wisconsin
Posted: 20th Jul 2011 12:09 Edited at: 20th Jul 2011 13:32
Ok, before you even attempt to look at this code, here is a video that I have uploaded to YouTube that visually describes the problem.

http://www.youtube.com/watch?v=JHIz5ihp7Lw

And here's the problem. Even though within my code I have nested if statements, they still get run even though - in my eyes and what I have outputted in my Dark Basic console window - it shouldn't.

In a nutshell, I set a variable called 'failed' to the value '1'. Yet, later in my code, I test to see what the value is, and it comes back as '0', causing code to incorrectly run.

Nothing else within my code besides this function (I searched) modifies this variable, unless its part of a blanket reset of ALL variables - meaning everything would get reset and nothing would happen anyway.

Here's my code, I have it commented the best I can.



This, with watching the video I have posted, should clearly state the problem that I'm having. When I fail a tag, the sprites go off screen. They do go offscreen like they should, but then play the 'success' sound and continue onward, even though they shouldn't.

If I get rid of the 'success' portion of the code - these lines here especially:

the problem ceases to exist. However, it also means I cannot continue tagging, period, which is a whole new problem.

Anyone else have sharp eyes and might have a suggestion for me?

EDIT: Solution found. Reason? Incorrect input.
I was inputting a value of "0" into "tagOrder" above. However, the indexes in the data system start off at 1. Thus, setting it would create an 'automatic' finish, so if the person screwed up a tag, it would load up a 'automatic' finish, increase the value by one, and then load to the next. So it seemed to me like it was starting off at 1 each time, but really it wasn't.

In essence, because it only took (1) frame for this to occur, I didn't see it anything flicker or whatnot with my own eye. In addition, because this condition existed for one frame, it was neigh impossible to debug until I started ripping out additional chunks of code until I started narrowing down possibilities.

So, lesson learned here: Sanitize your inputs.

Login to post a reply

Server time is: 2026-07-10 15:31:03
Your offset time is: 2026-07-10 15:31:03