Shop OBEX P1 Docs P2 Docs Learn Events
? on two objects calling each other — Parallax Forums

? on two objects calling each other

codemonkeycodemonkey Posts: 38
edited 2007-04-18 22:50 in Propeller 1
Being new to the Propeller, I'd like to be able to call back and forth between objects in separate·cogs. When i try to define as i think i should i get a "circular reference". Some brief abstracted code:

'Master·object
OBJ Bottom : "servant"
PUB Main()
· Bottom.Start()
PUB SomethingHappened()
··/etc.

'Servant·object
OBJ Top : "master"
PUB Start()
· /etc.
PUB Main()
· Top.SomethingHappened()

I didn't see way to pass references to objects. Any suggestions??

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-04-18 22:01
    Currently, there's no way to do this. If you can possibly move "SomethingHappened" to a lower level object and not use any VAR section variables (use DAT space only), you can then refer to the resulting object (say SubObject) from both Master and Servant. Since there are no VARs, you really only have one instance of Something Happened.
  • codemonkeycodemonkey Posts: 38
    edited 2007-04-18 22:12
    Thanks for a quick answer Mike. I was afraid that was the answer. Oh well, time to cook up a batch of spaghetti code. But you brought to mind a new question with regard to Var vs. Dat for storage: Is one "better" than the other?
  • Mike GreenMike Green Posts: 23,101
    edited 2007-04-18 22:50
    1) The formats are different (for writing it). In the VAR section, you have what look like high-level language declarations including type and size of arrays. In the DAT section, you have labels. The labels do have an implicit type which is set by the size keyword on the line (byte, word, long). There is no real array size except for the number of values listed, but there's nothing that checks for you.

    2) DAT is really intended for assembly language and tables of constants, but there's nothing to prevent you from changing
    one of the "initialized variables" to some other value.

    3) Every "instance" of the object has a private copy of the VAR section(s), but there is only one copy of the code and any DAT section(s).
Sign In or Register to comment.