Problem with VAR
RogerInHawaii
Posts: 87
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
best regards
Stefan
Huh? I don't get it.
This same shirt could be adapted for blood bank workers as well: Type Os happen.
-Phil