Shop OBEX P1 Docs P2 Docs Learn Events
Passing a variable's address from one object to another — Parallax Forums

Passing a variable's address from one object to another

MacGeek117MacGeek117 Posts: 747
edited 2007-12-29 01:02 in Propeller 1
I need to pass two values from one object·to a higher object. Can I pass the addresses of the variables when I start the object:
MyObj.start(@var1, @var2)
 
'in MyObj:
start(_addr1, _addr2)
addr1 := _addr1
addr2 := _addr2

and at a later point use BYTEFILL to pass the values?
bytefill(addr1, somevalue, 1)
bytefill(addr2, somevalue + 26, 1)


RoboGeek

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"I reject your reality and subsitute my own!"

Adam Savage, Mythbusters
www.parallax.com
www.goldmine-elec.com
www.expresspcb.com
www.jameco.com
·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-12-29 00:22
    You certainly can.

    What you've outlined should work fine.
  • MacGeek117MacGeek117 Posts: 747
    edited 2007-12-29 00:26
    SWEET!!!!!!!! Thanks Mike!!!! <insert evil giggle here> (Make that evil laugh!)

    RoboGeek

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "I reject your reality and subsitute my own!"

    Adam Savage, Mythbusters
    www.parallax.com
    www.goldmine-elec.com
    www.expresspcb.com
    www.jameco.com
    ·
  • deSilvadeSilva Posts: 2,967
    edited 2007-12-29 00:28
    It is exactly so. But there are more possibilities...
    First I assume you mean you start a different process in a COG, which will run in a loop, and you to update it, or get results in return.
    Have a look at this example
    PUB main |  varA, varB,  stack[noparse][[/noparse]20]
      COGNEW(newCOG(@varA, @varB), @stack)
    
      ' now you can update varA and varB, e.g.:
    
        REPEAT
            LONG[noparse][[/noparse]varA]++
    
    PUB newCOG(addrA, addrB)
        DIRA[noparse][[/noparse]0]:=1
        REPEAT
            !OUTA[noparse][[/noparse]0]
            LONG[noparse][[/noparse]addrB]++
             WAITCNT(CNT+500+LONG[noparse][[/noparse]addrA])
    
  • MacGeek117MacGeek117 Posts: 747
    edited 2007-12-29 00:43
    No, I'm not starting a new cog, I just need to pass more than one value at the same time. Also, different methods will be passing values, one at a time, of course! If there are easier ways of doing this, I'm open to possibilities!
    RoboGeek

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "I reject your reality and subsitute my own!"

    Adam Savage, Mythbusters
    www.parallax.com
    www.goldmine-elec.com
    www.expresspcb.com
    www.jameco.com
    ·
  • deSilvadeSilva Posts: 2,967
    edited 2007-12-29 00:53
    "Passing values" generally refers to the input side... You need the output side, which is done with "call by refence" parameters , as you do.

    Writing to those parameters is generally done - as I showed you - by dereferencing it with SIZETYPE[noparse][[/noparse]address]; less often using BYTEFILL....

    I was also a little bit confused why you du this:
    addr1 := _addr1
    addr2 := _addr2
    

    ??
  • MacGeek117MacGeek117 Posts: 747
    edited 2007-12-29 01:02
    More than one method will be passing values, so I am saving the address in a global variable.
    The output side has code I will be copywriting, so I don't want to post code quite yet.
    RoboGeek

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "I reject your reality and subsitute my own!"

    Adam Savage, Mythbusters
    www.parallax.com
    www.goldmine-elec.com
    www.expresspcb.com
    www.jameco.com
    ·
Sign In or Register to comment.