Wild variable! Variable amok!

Posted By: deianthropus

Wild variable! Variable amok! - 10/05/10 01:47

I have initialized a variable, and assigned a debug variable to it just to watch the value. I have an error() function to break up the frames. After 2 frames, the initialized variable jumps to 94700! WTF is up with this?
Posted By: PadMalcom

Re: Wild variable! Variable amok! - 10/05/10 07:33

Sounds like you are assigning an address/a pointer? It would be easier for us to help you if you post your source code.
Posted By: deianthropus

Re: Wild variable! Variable amok! - 10/05/10 16:22

Sorry for the vagueness; I was pressed for time last night. It would be difficult to post the source code, as it is broken into several includes, but the relevant lines of code are:


Code:
//debugvars[] is an array of variables to send through
//my debug_display function using digits(). 
//That part works fine.

function myfunc(ENTITY* obj)//obj is used in the functions that are currently disabled
{
var zmot;
debugvars[11]=zmot;

while (1)
 {
 //functions that set and respond to zmot, 
 //currently commented out
 debugvars[11]=zmot;
 error("step break");
 wait(1);
 }

}



again, the variable does initialize to 0, but after several steps unexpectedly jumps to 94700, or a close number. Most often it is 94700.

NOTE: this is not the actual code, just a selection of relevant lines in a similar format (the variable is defined in a function). The function is called once when a script that creates an entity loads:

Code:
function init_ent()
{
myobj=ent_create(blah, blah, blah,parameters,not the issue, entity is fine);
myfunc(myobj);

}


Posted By: Lukas

Re: Wild variable! Variable amok! - 10/05/10 16:37

The variable "zmot" is NOT initialized anywhere. Try using var zmot = 0; instead of var zmot;
Posted By: deianthropus

Re: Wild variable! Variable amok! - 10/05/10 20:52

Originally Posted By: Lukas
The variable "zmot" is NOT initialized anywhere. Try using var zmot = 0; instead of var zmot;


Duh. That would work, since I am running the while() loop within the function, instead of an earlier script wherein the function was itself called within a while script running the content of the loop once per call. I don't know why I didn't think of that when I changed it to the format as I've described here. lol. thanks. I'll let you know.
© 2024 lite-C Forums