Problem with VAR
I'm having some very strange symptoms.
I have some variables defined like:
Inside one of my methods I am setting that first variable, _A
If I print out the value of _A (using the FullDuplexSerialPlus to the Serial Terminal) while I'm still inside MyMethod it shows that the value of _A is indeed equal to 9.
But if I print out the value of _A after I exit MyMethod it comes out as 0. In fact, I have another method that just prints out the value of _A. If I call that method FROM WITHIN MyMethod, it also shows that _A is zero. So, if I print out the value of _A directly within MyMethod (with direct calls to the FullDuplexSerial methods) it comes out correctly, but if I call my PrintOutA from within MyMethod, _A comes out as being 0. ?!?!?
This behavior also seems to be rather inconsistent, in that I can successfully set other global variables and have them maintain their values, but SOME of them don't.
Any suggestions?
I have some variables defined like:
VAR
byte _A, _B, _C
Inside one of my methods I am setting that first variable, _A
PUB MyMethod
_A := 9
If I print out the value of _A (using the FullDuplexSerialPlus to the Serial Terminal) while I'm still inside MyMethod it shows that the value of _A is indeed equal to 9.
But if I print out the value of _A after I exit MyMethod it comes out as 0. In fact, I have another method that just prints out the value of _A. If I call that method FROM WITHIN MyMethod, it also shows that _A is zero. So, if I print out the value of _A directly within MyMethod (with direct calls to the FullDuplexSerial methods) it comes out correctly, but if I call my PrintOutA from within MyMethod, _A comes out as being 0. ?!?!?
This behavior also seems to be rather inconsistent, in that I can successfully set other global variables and have them maintain their values, but SOME of them don't.
Any suggestions?

Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
Propalyzer: Propeller PC Logic Analyzer
http://forums.parallax.com/showthread.php?p=788230
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
Propalyzer: Propeller PC Logic Analyzer
http://forums.parallax.com/showthread.php?p=788230
I think I'm going to come out with a line of T-shirts that says "Typos Happen".
Rick
-Phil
Regards,
John
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Necessity is the mother of invention'
Those who can, do.Those who can’t, teach.
I want to correct a detail.
VAR-variables are NOT cog-specific they are object-specific.
This is a big difference ! As long as methods are called from the SAME object(= same *.SPIN-file)
all VAR-variables defined in that *.SPIN-file are accessible even ACROSS cogs !
here is a small democode that shows that
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 VAR long heart_stack[noparse][[/noparse] 20] long CogStack1[noparse][[/noparse] 20] long CogStack2[noparse][[/noparse] 20] long MyTestVar OBJ debug : "FullDuplexSerial" PUB Main 'the FIRST PUB-Method inside a spinfile is ALWAYS the startpoint where the program starts to run debug.start(31, 30, 0, 9600) MyTestVar := 100 debug.str(string("Start MyTestVar=")) debug.dec(MyTestVar) debug.Tx(13) cognew(M1,@CogStack1) cognew(M2,@CogStack2) repeat waitcnt(clkfreq + cnt) debug.str(string("MyTestVar=")) debug.dec(MyTestVar) debug.Tx(13) PUB M1 repeat waitcnt(ClkFreq * 3 + cnt) MyTestVar := 1 PUB M2 repeat waitcnt(ClkFreq * 5 + cnt) MyTestVar := 2best regards
Stefan
Huh? I don't get it.
This same shirt could be adapted for blood bank workers as well: Type Os happen.
-Phil