Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Whatdotcolour Help!
Index -> Programming, Turing -> Turing Help
Goto page 1, 2, 3  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
mike200015




PostPosted: Fri Mar 11, 2005 9:09 pm   Post subject: Whatdotcolour Help!

I am using whatdotcolour, and im doing an if statement:
code:

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:

code:

if whatdotcolour (x,y) = 2 or whatdotcolour (x,y) = 3 or whatdotcolour (x,y) = 4...
..
..
end if
Sponsor
Sponsor
Sponsor
sponsor
Frazzydee




PostPosted: Fri Mar 11, 2005 9:13 pm   Post subject: Re: Whatdotcolour Help!

could you use a case select statement?

code:

case whatdotcolour(x,y) of
label 2,3,4,5,6:
...
end case
mike200015




PostPosted: Fri Mar 11, 2005 9:18 pm   Post subject: (No subject)

possibly.. but i have no idea what that is? Confused
Frazzydee




PostPosted: Fri Mar 11, 2005 9:24 pm   Post subject: (No subject)

It should work if you use case instead of if:

Instead of:
code:

if whatdotcolour (x,y) = 2 or whatdotcolour (x,y) = 3 or whatdotcolour (x,y) = 4...
..
..
end if


Use:
code:

case whatdotcolour (x,y) of
label 2,3,4:   %just took the numbers from above, use anything you want
...
end case
Cervantes




PostPosted: Fri Mar 11, 2005 9:34 pm   Post subject: (No subject)

Also, you might want to check if a whatdotcolour comparison is false. Say you want to detect a collision with anything:
code:

if not whatdotcolour (x, y) = backgroundColour then
...
end if
mike200015




PostPosted: Fri Mar 11, 2005 9:45 pm   Post subject: (No subject)

Cervantes wrote:
Also, you might want to check if a whatdotcolour comparison is false. Say you want to detect a collision with anything:
code:

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




PostPosted: Fri Mar 11, 2005 9:58 pm   Post subject: (No subject)

mike200015 wrote:
Cervantes wrote:
Also, you might want to check if a whatdotcolour comparison is false. Say you want to detect a collision with anything:
code:

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).
code:

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
code:

label >= 4 and <= 10
Flikerator




PostPosted: Fri Mar 11, 2005 10:04 pm   Post subject: (No subject)

code:
if whatdotcolour (x, y) not= colourback then

end if


isnt that the same thing?
Sponsor
Sponsor
Sponsor
sponsor
mike200015




PostPosted: Fri Mar 11, 2005 10:19 pm   Post subject: (No subject)

Flikerator wrote:
code:
if whatdotcolour (x, y) not= colourback then

end if


isnt that the same thing?

yea.. same thing.. Cervantes jus wrote colourback as backgroundColour

EDIT

o wait.. i just realized that you moved the not over to beside the = ... i think its the same.. not totaly sure
mike200015




PostPosted: Fri Mar 11, 2005 10:22 pm   Post subject: (No subject)

Cervantes wrote:


code:

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


so in this case variable would be a string right?
Token




PostPosted: Fri Mar 11, 2005 10:23 pm   Post subject: (No subject)

wow, wheres Andy when you need him, okay i have an idea but i dont know if it will be efficent enough, what you could do is create an array, this is just what i'd do because i just recently realised how usefull they are, so you could create an array and asign a color to each variable like so

code:

var banana : array 1 .. 5 of int

for i : 1 .. 5
    banana (i) := i + 1
end for

i used the variable name banana because i had no idea what your program actually is, although i guessed it is some sort of snake game

but anyways now those arays are set to the values that the will trigger the if statement so now all that you have to do is create your if statement within a for statement like so

code:

for i : 1 .. 5

    if whatdotcolor (x, y) = banana (i) then
        put "you have entered the if statement!"
    end if
end for


tadum! hope that helps
mike200015




PostPosted: Fri Mar 11, 2005 10:30 pm   Post subject: (No subject)

lol yea.. don't know where Andy is.. but anywase.. what u suggested is a good idea, except i dont think it will work in my case, but thanx anyway Token. Smile


i used the case.. but when i ran it i got an error saying "Compile time expression expected", and it highlighted one of the things i wrote after label. I wrote:
code:

case whatdotcolour (x,y) of
label 2,col:
...
end case

and it highlighted the variable col.. why did that happen? Confused
i took out the variable, and the case works, but then when i run the game, and theres a collision, then thrs an error, and it says: "case selector is out of range" Question
Cervantes




PostPosted: Sat Mar 12, 2005 7:46 am   Post subject: (No subject)

If you want to keep the col, you're going to have to make it a constant.
code:

const col := 8


Also, the reason you are getting "Case selector is out of range" is because whatdotcolour (x,y) is not always equal to 2 or col. There's no other alternative, so it crashes. You need to give it the alternative.
code:

colourback (6)
cls
var x, y := 100
const col := 10
case whatdotcolour (x, y) of
    label 2, col :
        put "yay"
    label :
        put "booo"
end case
mike200015




PostPosted: Sat Mar 12, 2005 3:49 pm   Post subject: (No subject)

oo kk yea it doesnt crash nemore.. thanx
mike200015




PostPosted: Sun Mar 20, 2005 2:41 pm   Post subject: (No subject)

im adding a new part to my game.. so im addin to this old post.. anyways.... ok so im using a case with whatdotcolour.. and i need to have a variable in thr, for the paddle colour, because the user selects their own paddle colour, and i cant make it a constant:
code:
case whatdotcolour (ballx + 11, bally) or whatdotcolour (ballx - 11, bally) of                 
label 40, 50, 60, 70, 80, 90, 100, 110, 120, 130 :                                                                          xmod := -xmod
                label padcol :
                    xmod := -xmod
                label :
                    ballx += xmod
            end case
case whatdotcolour (ballx, bally + 11) or whatdotcolour (ballx, bally - 11) of                           label 40, 50, 60, 70, 80, 90, 100, 110, 120, 130 :                                                                ymod := -ymod
               label padcol :
                    ymod := -ymod
                label :
                    bally := ymod
            end case

is there anyway to keep the padcol variable in thr?, or do i need to switch it for the colours that the user can choose? Confused
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 3  [ 38 Posts ]
Goto page 1, 2, 3  Next
Jump to:   


Style:  
Search: