
-----------------------------------
mike200015
Fri Mar 11, 2005 9:09 pm

Whatdotcolour Help!
-----------------------------------
I am using whatdotcolour, and im doing an if statement:

if whatdotcolour (x,y) = 2 then 
...
...
end if

is there an easier way to make: 

if whatdotcolour (x,y) = many colours(2,3,4,5,6) instead of having to do:


if whatdotcolour (x,y) = 2 or whatdotcolour (x,y) = 3 or whatdotcolour (x,y) = 4...
..
..
end if


-----------------------------------
Frazzydee
Fri Mar 11, 2005 9:13 pm

Re: Whatdotcolour Help!
-----------------------------------
could you use a case select statement?


case whatdotcolour(x,y) of
label 2,3,4,5,6:
...
end case


-----------------------------------
mike200015
Fri Mar 11, 2005 9:18 pm


-----------------------------------
possibly.. but i have no idea what that is? :?

-----------------------------------
Frazzydee
Fri Mar 11, 2005 9:24 pm


-----------------------------------
It should work if you use case instead of if:

Instead of:

if whatdotcolour (x,y) = 2 or whatdotcolour (x,y) = 3 or whatdotcolour (x,y) = 4...
..
..
end if 


Use:

case whatdotcolour (x,y) of
label 2,3,4:   %just took the numbers from above, use anything you want
...
end case


-----------------------------------
Cervantes
Fri Mar 11, 2005 9:34 pm


-----------------------------------
Also, you might want to check if a whatdotcolour comparison is false.  Say you want to detect a collision with anything:

if not whatdotcolour (x, y) = backgroundColour then
...
end if


-----------------------------------
mike200015
Fri Mar 11, 2005 9:45 pm


-----------------------------------
Also, you might want to check if a whatdotcolour comparison is false.  Say you want to detect a collision with anything:

if not whatdotcolour (x, y) = backgroundColour then
...
end if

so does that mean if theres a collision with any other colour, other than the backroound colour then ... ?


also, what does the case and label actually do?

-----------------------------------
Cervantes
Fri Mar 11, 2005 9:58 pm


-----------------------------------
Also, you might want to check if a whatdotcolour comparison is false.  Say you want to detect a collision with anything:

if not whatdotcolour (x, y) = backgroundColour then
...
end if

so does that mean if theres a collision with any other colour, other than the backroound colour then ... ?


also, what does the case and label actually do?
Yes, if (x,y) is a colour other than backgroundColour, it will enter the if statement.
A case construct is much like an if statement, but easier, in some situations.  (such as this).

case variable of
   label "value 1" :
      put "value 1 it is!"
   label "second value"
      put "second value, then?"
   label "Simon and Garfunkel"
      put "yeah! w00t w00t"
   label :
       "put "boring"
end case

The case construct looks at variable, trys to match it to they various labels.  If it does match it (ie. variable = "value 1" etc.) then it enters that label and executes the code (in this case, if variable = "value 1" it enters the code inside the first label, which is put "value 1 it is!").  If it can't match it, it goes to the label :, which is like an else.
But note that you can't do things like

label >= 4 and 