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

Global Variable

crgwbrcrgwbr Posts: 614
edited 2007-01-09 21:31 in Propeller 1
In one program I am writing, I have a variable declared and constintly·altered one object. I need to access this variable in another object (running in another cog).· How can I constintly access that variable from the second cog?· Do I have to declare the variable somehow in the second object?

Thanks,
crgwbr

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NerdMaster
For
Life

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-01-05 21:55
    You can pass the address of the variable to another object and access it in another object by it's address. Also if you have it arranged as the lower object has the variable, you can encapsulate access of the viariable by making methods within the object to read and write the variable.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • crgwbrcrgwbr Posts: 614
    edited 2007-01-06 01:46
    I'm sorry, but I'm rather new to the propeller, how do you find the adress of the variable? Also, the top object is the one with the variable declairation, therefore I don't think that your second seggestion would work.

    Thanks,
    crgwbr

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    NerdMaster
    For
    Life
  • rokickirokicki Posts: 1,000
    edited 2007-01-06 01:50
    The expression @a returns the address of a variable a.

    The expression long[noparse][[/noparse]a] "fetches" the first long from this address (similarly for byte and word).

    So long[noparse][[/noparse]@a] (for a long variable a) is essentially the same as just a.
  • SailerManSailerMan Posts: 337
    edited 2007-01-06 02:25
    I asked this very same question... Look at this thread from about a month ago.

    Regards,
    Eric

    http://forums.parallax.com/forums/default.aspx?f=25&m=157798
  • crgwbrcrgwbr Posts: 614
    edited 2007-01-06 17:26
    Thanks, Guys. This should help a lot.

    crgwbr

    PS: SailerMan, I live in PA.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    NerdMaster
    For
    Life
  • SailerManSailerMan Posts: 337
    edited 2007-01-07 04:18
    What Part? I am in Altoona.
  • crgwbrcrgwbr Posts: 614
    edited 2007-01-09 21:05
    Ok, now I have an object(in one cog) that knows the address a variable A. Variable A is defined if a different object(in a different cog). How do I use the address information to call up the value stored at that address.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    NerdMaster
    For
    Life
  • CJCJ Posts: 470
    edited 2007-01-09 21:20
    just use one of the following as if they were the variable

    long[noparse][[/noparse]address]
    word[noparse][[/noparse]address]
    byte[noparse][[/noparse]address]

    depending on what the size is.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Who says you have to have knowledge to use it?

    I've killed a fly with my bare mind.
  • crgwbrcrgwbr Posts: 614
    edited 2007-01-09 21:31
    Thanks

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    NerdMaster
    For
    Life
Sign In or Register to comment.