Shop OBEX P1 Docs P2 Docs Learn Events
Storing global references between Spin objects — Parallax Forums

Storing global references between Spin objects

RandyyRandyy Posts: 3
edited 2013-03-29 02:08 in Propeller 1
Hello all,

I've been beating my head against the wall for a week now with a problem. Searched forums, but I can't find a solution. Hopefully someone can help.

Simplifying my problem, I have two objects, the main object and a support object with several public methods. I can pass a reference to the .start method in the support object and successfully refer to it via Long[reference], both writing and reading from WITHIN the method. I can't seem to save that reference however for use from other methods in the object. I've tried
myGlobal := reference 
    and 
myGlobal := Long[reference]
, both with and without the @ sign, and my other methods don't seem to be able to read or write to the main object's variable. Can anybody tell me what I'm doing wrong?

Comments

  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2013-03-28 09:31
    In the parent object you have this:
    VAR
      LONG reference ' could be a local variable too, if you aren't starting a second cog using the variable
    
    PUB Main
      SUB.start(@reference)
    

    In the child object you have this:
    VAR
      LONG refAddr
    
    PUB start (ref) ' pass the address to the variable as the parameter
      refAddr := ref ' store address to global variable
      dothings(ref) ' or pass it to methods...
    
    PUB dostuff
      LONG[refAddr] := 5
      display(LONG[refAddr])
    
    PUB dothings (ref)
      display(LONG[ref])
      LONG[ref] := 12
    

    hope that helps.
  • RandyyRandyy Posts: 3
    edited 2013-03-28 09:41
    Thank you in advance (away from my Prop right now). It seems like I was doing this, but maybe not quite. In your example, I could get .start and .dothings working, but .dostuff was the problem. I'll try it tonight and report back.
  • RandyyRandyy Posts: 3
    edited 2013-03-29 02:08
    It worked! Thank you!
Sign In or Register to comment.