Shop OBEX P1 Docs P2 Docs Learn Events
Question about addressing in spin — Parallax Forums

Question about addressing in spin

Zap-oZap-o Posts: 452
edited 2011-04-07 20:34 in Propeller 1
I am not sure how to describe this so please forgive me if it doesn’t make since the first go around. The best way I can describe my problem is that I have an object and it contains a variable. This variable is a long labeled ZTOLL that is manipulated from time to time (read and written to). I also have a second object that wants to read from ZTOLL and also write to ZTOLL as well. Is this possible? Should I be using the @ or @@ symbols? I have read the book on the two operators and cant seem to grasp the concept and I am not entirely sure this is even the right thing to use for this. What do you think? Thanks in advance.

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2011-04-07 20:34
    Basically:
    1. export address of said variable from the first object (e.g. return @ZTOLL)
    2. communicate said address to the second object
    3. access variable (e.g. long[address] := NEGX)
    ' method in 1st object
    
    PUB getAddress
      return @ZTOLL
    
    ' method(s) in 2nd object
    
    PUB doSomething
      long[address] += 1
    
    VAR
      long  address
    
    PUB setup(incoming)
      address := incoming
    
    ' usage in main object
    
      addr := object_1.getAddress
      object_2.setup(addr)              ' communicate address
      object_2.doSomething
    
Sign In or Register to comment.