Shop OBEX P1 Docs P2 Docs Learn Events
How to create a "range". Help with code — Parallax Forums

How to create a "range". Help with code

TonyATonyA Posts: 226
edited 2007-07-06 20:22 in Propeller 1
I am using x := x + 1 to increment the value of a variable "x".
And x := x - 1 to decrement.

How can I create a "range" for this?

(Suppose the value of x must·stay within the range of 1 to 10)

Thanks.
Tony

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-06 13:41
    How about: x := (x+1) <# 10 or x := (x-1) #> 1
  • TonyATonyA Posts: 226
    edited 2007-07-06 13:58
    I see. Thank you.

    Unrelated to the above range question, however I was also wondering if you could do something like this in Spin.

    I have:

    snd.StopSound(0) 'stop sound on channel 0

    snd.StopSound(1) 'stop sound channel 1

    snd.StopSound(2) 'stop sound, channel 2

    Is it possible to do something like this:

    snd.StopSound(0,1,2) ' stop channels 0,1 and 2 at the same time?

    Thanks.
    Tony
  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-06 14:29
    No

    You could go into the sound object and add another method that does what you want, but you can't just add extra parameters and expect that the compiler would be able to figure out what you want to do with the extra information. There are some programming languages that will allow you to do things like this, but they have very specific rules about how the extra parameters are to be interpreted.
  • TonyATonyA Posts: 226
    edited 2007-07-06 14:39
    I see what you're saying. I would have to modify the sound driver. I think I'll leave it for now.

    Thanks.
    Tony
  • TonyATonyA Posts: 226
    edited 2007-07-06 20:22
    I came across this in the Hydra manual:

    repeat channel from 0 to 5 'Stops all channels
    snd.StopSound(channel)

    Works great. I must have over looked it during the first 100 times reading that chapter.

    Thanks.
Sign In or Register to comment.