Shop OBEX P1 Docs P2 Docs Learn Events
Including a file within several object files — Parallax Forums

Including a file within several object files

RogerInHawaiiRogerInHawaii Posts: 87
edited 2009-02-25 04:28 in Propeller 1
I have several objects each of which make use of the same set of constants, defined in their individual CON blocks. Something like...

CON
 
   Black = 0
   WHITE = 1
   RED = 2
   BLUE = 3

Since these same constants are used in several different objects I've had to duplicate the CON block in each of the object's .spin files. But this is a bit "dangerous" in the event that I change one or more of the values. What I'd really like to do is to have these values defined in a single, separate file (perhaps, MyColors.txt) and to somehow have them explicitly included within the various object's files.

In C or C++ I'd simply use a #include directive. Is there something comparable in Spin?

I came across the FILE directive, but that doesn't actually do what I need.

Comments

  • grasshoppergrasshopper Posts: 438
    edited 2009-02-25 03:23
    I think you can use the # as well. You'll need to supply more code, i.e. objects name that holds the constants.

    **Edited

    Some thing like this

    OB1 = Objects name that holds constants
    OB1#Blue
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Those who criticize our generation forget who raised it.

    Post Edited (grasshopper) : 2/25/2009 3:29:50 AM GMT
  • mctriviamctrivia Posts: 3,772
    edited 2009-02-25 03:26
    if they don't have to be constants you could create an object that returned those values.

    PUB getVar(varNum)
    case ubMenuState1
    0:
    return con0
    1:
    return con1
    2:
    return con 2
  • RogerInHawaiiRogerInHawaii Posts: 87
    edited 2009-02-25 04:28
    Both good ideas.

    Thank you.
Sign In or Register to comment.