Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
I am trying to make this simple program keep score. The user guesses a number between 0-15, and if the guess is correct, then add 2 points, incorrect, take 1 point away. The GUI has a submit button, which all the code is written through, an instruction label, a text box for user input, a "score" label and a score text box starting at 0. I'm not sure why, but if I guess incorrect, it goes down to -1, but won't go further into the negative? I'm not sure why. Here is the code I have so far.
on mouseUp
put the text of fld "fld_guess" into theGuess
put 0 into score --adds the fun of keeping score to the game!
set the randomSeed to the long seconds
put random(15) into theAnswer --changed the range to make it easier, and somewhat less frustrating
if theGuess is theAnswer then
answer "Correct"
add 2 to score --adds 1 point to score if answer is correct
else
answer "Wrong! The correct answer was " & theAnswer & "."
add -1 to score --subtracts 1 point from score if answer is incorrect
end if
put empty into fld "fld_guess"
put score into field "scoreField" --displays the current score
end mouseUp
So I guess I'm not getting this. I put breakpoints in but it doesn't show me anything? Clearly the program is replacing the 0 with 2 or -1, which makes me think that 'add' is not the right keyword to use, but I don't know what else you would use? This language is so screwy. If i'm adding 2 to 2, why is score not 4? If I'm adding -1 to 2, why is score not 1? This doesn't make sense.
on mouseUp
put the text of fld "fld_guess" into theGuess
set the randomSeed to the long seconds
put random(15) into theAnswer --changed the range to make it easier, and somewhat less frustrating
if theGuess is theAnswer then
answer "Correct"
add 2 to score --adds 1 point to score if answer is correct
else
answer "Wrong! The correct answer was " & theAnswer & "."
add -1 to score --subtracts 1 point from score if answer is incorrect
end if
put empty into fld "fld_guess"
put score into field "scoreField" --displays the current score
end mouseUp
and here is the on cardOpen code attached to the card: