Computer Science Canada

Whatdotcolour Help!

Author:  mike200015 [ 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

Author:  Frazzydee [ 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

Author:  mike200015 [ Fri Mar 11, 2005 9:18 pm ]
Post subject: 

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

Author:  Frazzydee [ Fri Mar 11, 2005 9:24 pm ]
Post 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

Author:  Cervantes [ Fri Mar 11, 2005 9:34 pm ]
Post 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

Author:  mike200015 [ Fri Mar 11, 2005 9:45 pm ]
Post 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?

Author:  Cervantes [ Fri Mar 11, 2005 9:58 pm ]
Post 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

Author:  Flikerator [ Fri Mar 11, 2005 10:04 pm ]
Post subject: 

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

end if


isnt that the same thing?

Author:  mike200015 [ Fri Mar 11, 2005 10:19 pm ]
Post 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

Author:  mike200015 [ Fri Mar 11, 2005 10:22 pm ]
Post 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?

Author:  Token [ Fri Mar 11, 2005 10:23 pm ]
Post 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

Author:  mike200015 [ Fri Mar 11, 2005 10:30 pm ]
Post 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

Author:  Cervantes [ Sat Mar 12, 2005 7:46 am ]
Post 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

Author:  mike200015 [ Sat Mar 12, 2005 3:49 pm ]
Post subject: 

oo kk yea it doesnt crash nemore.. thanx

Author:  mike200015 [ Sun Mar 20, 2005 2:41 pm ]
Post 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

Author:  Andy [ Sun Mar 20, 2005 9:32 pm ]
Post subject: 

sry guys.. been busy.. wow this problem is alot easier than you guys think simply have a string
code:

var colors :="2 3 4 5 6"
if index(colors, intstr(whatdotcolor(x,y))) not=0 then
    put"yay"
end if

Author:  mike200015 [ Mon Mar 21, 2005 2:59 pm ]
Post subject: 

but the colours that im using in the case are not constants.. its user chosen colours.. and 2nd thing is also im using sum RGB.AddColour, colours Question

Also, if i use an if statement for the whatdotcolour instead of a case;
code:

if whatdotcolour (ballx+5,bally) = ..

after the = i want to put an array, because i have an array of 10 different colours, so how would i do that Question Confused

Author:  Andy [ Mon Mar 21, 2005 3:42 pm ]
Post subject: 

u cant use whatdotcolor for RGB colors... and for ur user selection thing, simply construct the string? how hard is that...

Author:  mike200015 [ Mon Mar 21, 2005 3:50 pm ]
Post subject: 

kk.. thnx.. n wat bout for the 2nd part.. if i use an if statement for whatdotcolour.. and i hav an array of 10 colours.. is thr a way to do sumtin like:
code:
if whatdotcolour (x,y) = colours (1..10)
Question

Author:  Andy [ Mon Mar 21, 2005 3:55 pm ]
Post subject: 

whats wrong wit the method i posted?? just put the numbers in a string and use index

Author:  mike200015 [ Mon Mar 21, 2005 3:58 pm ]
Post subject: 

i would use ur way.. cept i dun understand it lol Sad

Author:  Andy [ Mon Mar 21, 2005 3:59 pm ]
Post subject: 

which part?? do u noe index? intstr? and string?

Author:  mike200015 [ Mon Mar 21, 2005 4:00 pm ]
Post subject: 

i know intstr and string.. dont know index..and also dont get y u made the whatdotcolour into a string?


But also can u do sumtin like:
code:
if whatdotcolour (x,y) = colours (1..10)

since colours is an array 1..10 of colours (int)

Author:  Andy [ Mon Mar 21, 2005 8:17 pm ]
Post subject: 

if u do it in an array.. it is way to inefficient... what index does is it searches the string for an occurance of a substring... if its found, then it returns the location, if its not found, it returns 0. if u have the colors inside a string, you can simply use index to see if the number is inside the string. u use whatdotcolor to find out what the color is, use intstr to change it to a string, then index checks if the color is inside the string, if its not, it will return 0.

Author:  Cervantes [ Mon Mar 21, 2005 8:26 pm ]
Post subject: 

Andy wrote:
if u do it in an array.. it is way to inefficient...

ie.
code:

function checkCollision : boolena
for i : 1 .. upper (coloursArray)
  if whatdotcolour (x,y) = coloursArray (i) then
    result true
  end if
   result false
end for
end checkCollision

This involves doing whatdotcolour many times on the exact same location. That's a little inefficient. Sure, we could do it once and store it to a variable, but then we still have to use that variable over and over again. Andy's way doesn't involve a for loop; it's quick and clean.

Author:  Bacchus [ Mon Mar 21, 2005 8:32 pm ]
Post subject: 

but wat happens if you need to check some double digit colors? like whatdotcolor return 1 and ur looking for colors 11..13 ? lol

Author:  Cervantes [ Mon Mar 21, 2005 9:08 pm ]
Post subject: 

It will work just fine. Note, however, the spaces Andy put between the different numbers. This prevents multi-digit colour numbers like 23 from from making the condition true and entering the if statement. If the string were "234578" then if whatdotcolour (x,y) = 23, the if statement would be entered. With the spaces, however, this is not a problem.

Author:  Bacchus [ Mon Mar 21, 2005 9:11 pm ]
Post subject: 

but if the string was "11 12 13" and whatdotcolro did return 1, index would match the 1 with ne of the numbers in the string?

Author:  Andy [ Mon Mar 21, 2005 9:57 pm ]
Post subject: 

Oooo i see what u mean, then just add a 0 infront of it... have a fuction called add 0, and return a string.. hmm i guess that is slightly more difficult, but yea ur rite, that is a pain..

Author:  Andy [ Tue Mar 22, 2005 8:39 am ]
Post subject: 

wait.. wtf am i talking about... just have this

code:
var colors :=" 2 3 4 5 6 "
if index(colors, " "+intstr(whatdotcolor(x,y))+" ") not=0 then
    put"yay"
end if


just have one space ahead of it and one space behind it.. you can create the colors string by starting wit " " and adding intstr(num)+" " to it every time... this works for sure haha

Author:  Bacchus [ Tue Mar 22, 2005 7:48 pm ]
Post subject: 

ah now that would work, always good to kno a new method for my madness

Author:  mike200015 [ Wed Mar 23, 2005 5:24 pm ]
Post subject: 

ok.. im still a little confused bout the index stuff.. so i have an array of 10 colours, as well as another 10 colours or so that are user chosen, but i only set the colours after the user enters the corresponding number from a list.. example:

These are the first 10 colours.. which are in an array..
code:
var colours : array 1 .. 10 of int := init (40, 50, 60, 70, 80, 90, 100, 110, 120, 130)                   



These are the other 7 colours.. which are user chosen depending on the number you press...
code:
var font3 := Font.New ("Courier New:10:bold")
var colname : array 1 .. 7 of string := init ("Blue", "Red", "Yellow", "Orange", "Black", "Purple", "Green")
var colnamex := 353
Font.Draw ("What colour paddle would you like? ", 3, 373, font3, blue)
        for i : 1 .. 7
            Font.Draw (intstr (i) + "." + colname (i), 3, colnamex, font3, blue)
            colnamex -= 20
        end for


i need to make all these colours here be used with whatdotcolour. So how would i make an index to chek the array colours.. as well as the other colours of the paddle? Confused

Author:  Andy [ Wed Mar 23, 2005 6:46 pm ]
Post subject: 

ok so your string starts off as clr:=" 40 50 60 70 80 90 100 110 120 130 "
then when you want to the other colors, simply store the other color as in a temp, then go clr+=intstr(temp)+" "

Author:  mike200015 [ Wed Mar 23, 2005 7:12 pm ]
Post subject: 

so would i do this for the index.. for the array colours:

code:
var clr:=" 40 50 60 70 80 90 100 110 120 130 "
if index (clr, " "+intstr(whatdotcolor(ballx,bally))+" ") ~= 0 then
    ballx -= 1
end if


sumtin like that?

Author:  mike200015 [ Fri Mar 25, 2005 2:19 pm ]
Post subject: 

Question

Author:  mike200015 [ Fri Mar 25, 2005 2:20 pm ]
Post subject: 

Question

EDIT- woops didnt mean to post that twice

Author:  Cervantes [ Sat Mar 26, 2005 8:24 am ]
Post subject: 

that should be fine. but I don't know why you say,
mike200015 wrote:
for the array colours

because you don't have an array.

Author:  mike200015 [ Sun Mar 27, 2005 11:02 am ]
Post subject: 

i have an array in my game, not the little code that i posted, heres the array, and what i did with it in that code before was just set the array numbers as a constant:

code:
var colours : array 1 .. 10 of int := init (40, 50, 60, 70, 80, 90, 100, 110, 120, 130)   


: