Shop OBEX P1 Docs P2 Docs Learn Events
Problem with VAR — Parallax Forums

Problem with VAR

RogerInHawaiiRogerInHawaii Posts: 87
edited 2009-05-12 15:25 in Propeller 1
I'm having some very strange symptoms.

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

  • jazzedjazzed Posts: 11,803
    edited 2009-05-12 00:28
    Maybe you can create a very short reproduce-by code snippet to share ? It would be very useful to see that.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve


    Propalyzer: Propeller PC Logic Analyzer
    http://forums.parallax.com/showthread.php?p=788230
  • RogerInHawaiiRogerInHawaii Posts: 87
    edited 2009-05-12 00:31
    Yes, it would be nice to be able to do that. But this is one huge program and I'm only encountering it in one particular place in the program. So I really doubt that I can come up with a small snippet that would reproduce it. It's got me baffled.
  • jazzedjazzed Posts: 11,803
    edited 2009-05-12 00:35
    Maybe it's time to try Hanno's ViewPort debugger?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve


    Propalyzer: Propeller PC Logic Analyzer
    http://forums.parallax.com/showthread.php?p=788230
  • PhilldapillPhilldapill Posts: 1,283
    edited 2009-05-12 01:16
    Roger, are you sure that these two places where you "call" _A are in the same cog? Those variables are cog specific, and if you are running two different instances of that code, that could be your problem.
  • RogerInHawaiiRogerInHawaii Posts: 87
    edited 2009-05-12 02:41
    They're in the same cog. But I finally realized the problem. And it was due to a typo! Aaaarrrggghh!

    I think I'm going to come out with a line of T-shirts that says "Typos Happen".
  • CassLanCassLan Posts: 586
    edited 2009-05-12 02:44
    That sounds like a great shirt

    Rick
  • mparkmpark Posts: 1,305
    edited 2009-05-12 05:29
    I think the shirt should have a typo.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-05-12 06:20
    It has two already.

    -Phil
  • QuattroRS4QuattroRS4 Posts: 916
    edited 2009-05-12 08:59
    Nice catch Phil!

    Regards,
    John

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Necessity is the mother of invention'

    Those who can, do.Those who can’t, teach.
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-05-12 11:39
    Hello,

    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 := 2
    
    
    



    best regards

    Stefan
  • mparkmpark Posts: 1,305
    edited 2009-05-12 15:10
    Phil Pilgrim (PhiPi) said...
    It has two already.

    -Phil

    Huh? I don't get it.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-05-12 15:25
    "Happen" is capitalized, and there's no period at the end of the sentence. (Yeah, I know. It's horribly pedantic, isn't it? Moreover, the claim could be made that it's a title or headline.)

    This same shirt could be adapted for blood bank workers as well: Type Os happen. smile.gif

    -Phil
Sign In or Register to comment.