
-----------------------------------
netninja
Wed Feb 11, 2004 2:40 pm

help with if statement.
-----------------------------------
Help with this please. At the get song part, it says its a bad get statement or something, and I dont understand why. Also, it says sonne (at the top) isnt declared, which i also dont understand. Obviously the program isnt finished, its just the beggining and i dont understand some things that I would like to learn in order to finish it. Of course it will only take half a minute, but im just practicing basics so that i can reach my final destination of making a duckhunt game hehe. Anyway, Im very noob to turing, so i appreciate all help with my errors.



setscreen ("graphics")

var song: array 1..6 of string:=init (sonne, zwitter, bodies, buckdich, ichwill, duhast)

put "sonne"
put "zwitter"
put "bodies"
put "buckdich"
put "ichwill"
put "duhast"
put ""
put "Enter the song you wish to play:"

get song

if song = sonne then
Music.PlayFileLoop ("music/sonne.mp3")
Draw.Text ("Sonne", 0, 0, defFontID, black)
end if

I also tried by making each song an integer instead of string, but that also didnt work.  :lol:

-----------------------------------
Zorg
Wed Feb 11, 2004 3:27 pm


-----------------------------------
You have to declare another variable to store the user's input.
You have also stored the text into the array incorrectly.

Here is how it is done correctly:
var song : array 1 .. 6 of string := init ("sonne", "zwitter", "bodies", "buckdich", "ichwill", "duhast")


  You also need to compare the user's input


var userinput:string
...
...
...
get userinput

if userinput = "sonne" then
    Music.PlayFileLoop ("music/sonne.mp3")
    Draw.Text ("Sonne", 0, 0, defFontID, black)
elsif userinput ="zwitter" then
..
...
...
..
end if

-----------------------------------
santabruzer
Wed Feb 11, 2004 3:29 pm


-----------------------------------
... dude.. why did you do that.. when you could've done this:

setscreen ("graphics")

var song
var songs : array 1 .. 6 of string := init (sonne, zwitter, bodies, buckdich, ichwill, duhast)

for i : 1 .. 6
    put songs (i)
end for
put ""
put "Enter the song you wish to play:"

get song

for i : 1 .. 6
    if song = songs (i) then
        Music.PlayFileLoop ("music/" + songs (i) + ".mp3")
        Draw.Text (songs (i), 0, 0, defFontID, black)
    end if
end for



-----------------------------------
netninja
Wed Feb 11, 2004 3:44 pm


-----------------------------------
:lol:  you ask why i did that??!!?? Because thats my knowledge of turing lol

But thanks alot, ill remember what you said! Thanks,

One more thing: 

at the var songs: error says "syntax error at var, expected ':' "

and at the bottom at  if song = songs (i) then: error says " operands of comparison operators must be scalars, sets, or strings.

Why is that?

-----------------------------------
recneps
Wed Feb 11, 2004 3:53 pm


-----------------------------------
umm... lol maybe because song has no type assigned to it :)

var song thats all it says, its gotta be var song:string or int depending on how its used.

-----------------------------------
netninja
Wed Feb 11, 2004 5:23 pm


-----------------------------------
wow, that was shameful of me, so sorry, 

lol, i cant believe i missed that, i guess my brain just skipped that step because its so basic lol, thanks for pointing it out though.

But why does it say that sonne is not declared?

-----------------------------------
Cervantes
Wed Feb 11, 2004 5:36 pm


-----------------------------------
sonne is just the text contained within the variable songs (1) .  to call it you have to call it like so  songs (1) .

-----------------------------------
netninja
Wed Feb 11, 2004 6:01 pm


-----------------------------------
no, the way santabruzer did it was by making (i) a song, i just cant seem to find the error in the code. I wanted to use that one because it seems more efficient, instead of having to declare 'if' so many times.

setscreen ("graphics") 

var song :string
var songs : array 1 .. 6 of string := init (sonne, zwitter, bodies, buckdich, ichwill, duhast) 

for i : 1 .. 6 
if song = songs (i) then 
    put songs (i) 
end for 

put "" 
put "Enter the song you wish to play:" 

get song 

for i : 1 .. 6 
    if song = songs (i) then 
        Music.PlayFileLoop ("music/" + songs (i) + ".mp3") 
        Draw.Text (songs (i), 0, 0, defFontID, black) 
    end if 
end for 

I just realized that there is two for statements, and two if statements, one of which has no end if. SO i ended the if, but the at the top it still gives the error i said before.

-----------------------------------
Paul
Wed Feb 11, 2004 6:09 pm


-----------------------------------
uh.. first of all the array is string, you have to put quotations in around the words, I don't see them...

var songs : array 1 .. 6 of string := init (sonne, zwitter, bodies, buckdich, ichwill, duhast) 


for i : 1 .. 6 
if song = songs (i) then 
put songs (i) 
end for %