Shop OBEX P1 Docs P2 Docs Learn Events
Common Variable — Parallax Forums

Common Variable

Big MikeBig Mike Posts: 2
edited 2009-07-06 20:41 in Propeller 1
I am looking for a way to access variables between the upper program and the variables set out in the objects in that program.· I would like to have a number of variables defined in the top level of the program and then have an object access that data and to have the object write data to some of the variables defined in the upper program. Is there a way of accessing that or will I have to copy the information to and from·that object's variable area.· Any help you can provide is appreciated
·
Thanks: Mike
·
·

Comments

  • KyeKye Posts: 2,200
    edited 2009-07-06 20:17
    Use pointers.

    Just pass the variable addresses to the lower level objects.

    The use word[noparse][[/noparse]address] or byte[noparse][[/noparse]address] or long[noparse][[/noparse]address] to set or read the variable.
    Like...
     
     
    VAR
     
      byte stuff1
      word stuff2
      long stuff3
     
    PUB writeStuff
     
      byte[noparse][[/noparse]@stuff1] := 128
     
      word[noparse][[/noparse]@stuff2] := 32768
     
      long[noparse][[/noparse]@stuff3] := 1231231231
     
     
    PUB readStuff1 
     
      return byte[noparse][[/noparse]@stuff1]
     
    PUB readStuff2 
     
      return word[noparse][[/noparse]@stuff2]
     
    PUB readStuff3 
     
      return long[noparse][[/noparse]@stuff3]
    
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,

    Post Edited (Kye) : 7/6/2009 8:24:08 PM GMT
  • Big MikeBig Mike Posts: 2
    edited 2009-07-06 20:41
    My isue was i needed to know the locaion of a certain variable to use as a reference for an index but what you said made me think of doing it a different way and it worked so thanks.
Sign In or Register to comment.