Shop OBEX P1 Docs P2 Docs Learn Events
ENUM — Parallax Forums

ENUM

PET V2.2PET V2.2 Posts: 2
edited 2008-12-20 12:33 in Propeller 1
Hey together

I have a little problem.
How can I use ENUMs in the SPIN language.
I can find it in the manual that it should work.
But i can't find how?

i'm looking for a examble like in C:

enum Modus {play, stop};

Thanks for helping

Comments

  • soshimososhimo Posts: 215
    edited 2008-12-20 10:54
    Enumerations are declared in a CON section. You precede the labels with the first number in the series. I don't think there is any way to do a non-sequential enumeration (e.g powers of 2). Here is an example (out of the manual):

    CON 'Declare modes of operation
       #0
       RunTest 'Run in test mode
       RunVerbose 'Run in verbose mode
       RunBrief 'Run with brief prompts
       RunFull 'Run in full production mode
    
    



    Using those declarations you can do something like this:
    case Mode
       RunTest : <test code here>
       RunVerbose : <verbose code here>
       RunBrief : <brief code here>
       RunFull : <full code here>
    
    



    or

    if Mode > RunVerbose
       <brief and full here>
    
    



    Using your example

    CON
       #0
       play
       stop
    
    VAR
       long Mode
    
    PUB DoAction
    
       Case Mode
          play : doplay   ' call the play function
          stop : dostop   ' call the stop function
    
    

    Post Edited (soshimo) : 12/20/2008 11:03:21 AM GMT
  • PET V2.2PET V2.2 Posts: 2
    edited 2008-12-20 11:13
    ok thanks a lot

    I think in the examble you have first to set the modus before you can use your case function.
    But i know now how it works.
    I didn't think how i can do it with two seperate deifnitions.

    thanks
  • soshimososhimo Posts: 215
    edited 2008-12-20 12:33
    Yes, you are correct, you have to set the modus variable's value - either through initialization, a calculation based on the current state, etc... The skies the limit, but you do need to assign the variable a value for it to be meaningful.
Sign In or Register to comment.