mathoperator-keywordlivecode

fixing the greater and less than signs in my math game in livecode


I am using two variables with random numbers from 1-10 in each and I want the user to click on the <= or >= symbol pictures that I used a toolTip in them . All the code is written in the card's script and the methods are called in the needed button or field . I included a picture of my app's interface too . Thank you enter image description here

here is my code can someone please help and spot what's wrong ? Thank you

 local _leftNumberValue 
local _rightNumberValue
local _correctAnswer
local _userAnswerValue
local _userScore
local _numberOfQuestions
on openCard
   PreparingQuestion
end openCard

on PreparingQuestion
   put random(10) into _leftNumberValue 
   put _leftNumberValue  into field "leftNumber"
   put random  (10)  into _rightNumberValue
   put _rightNumberValue  into field "rightNumber" 
   if  _leftNumberValue >=  _rightNumberValue
   then
      put _leftNumberValue  into _correctAnswer
      add 1 to _numberOfQuestions
      put _numberOfQuestions into field "numberOfQuestions"
   end if 
end PreparingQuestion

on CheckUsersAnswer
   put field "userAnswer" into _userAnswerValue
   if _userAnswerValue = _correctAnswer
   then
      if _userScore < 4
      then  
         AddPointsToPlayer
         PreparingQuestion
      else 
         answer "Great Job :) You can move on  to the next level"
      end if 
   end if 
   put empty into field "userAnswer"
end CheckUsersAnswer

on AddPointsToPlayer
   add 1 to _userScore
   put _userScore into field "scoreBoard"
end AddPointsToPlayer

on StartOver 
   put empty into field "numberOfQuestions"
   put 0 into _userScore
   put 0 into _numberOfQuestions
   put _numberOfQuestions into field "numberOfQuestions"
   put _userScore into field  "scoreBoard"
end StartOver

Solution

  • I think you need to explain the play and point of the game. I tried recreating your stack as best I could from the description and code, it seems to work OK, but I'm not sure I fully understand exactly what should be happening or where it's going wrong.

    One point; your CheckUsersAnswer handler only checks for a correct answer, what is supposed to happen if the answer is wrong?

    Update:

    Revised handlers…

    on PreparingQuestion
       put random(10) into _leftNumberValue 
       put _leftNumberValue  into field "leftNumber"
       put random  (10)  into _rightNumberValue
       put _rightNumberValue  into field "rightNumber" 
       
       ## CHANGED: Determine the correct answer…
       if _leftNumberValue > _rightNumberValue then put ">" into _correctAnswer
       if _leftNumberValue < _rightNumberValue then put "<" into _correctAnswer
       if _leftNumberValue = _rightNumberValue then put "=" into _correctAnswer
       
       add 1 to _numberOfQuestions
       put _numberOfQuestions into field "numberOfQuestions"
    end PreparingQuestion
    
    on CheckUsersAnswer
       put field "userAnswer" into _userAnswerValue
       if _userAnswerValue = _correctAnswer then
          if _userScore < 4 then  
             AddPointsToPlayer
             PreparingQuestion
          else 
             answer "Great Job :) You can move on  to the next level"
          end if
          
          ## ADDED: Message for user to try again…
       else
          answer "Wrong answer. Please try again."
       end if 
       put empty into field "userAnswer"
    end CheckUsersAnswer