Code: Select all
on mouseUp
if field = random(100) then results = "Amazing! You guessed it!"
Else if field < random(100) then results = "Nope! Too low!!"
Else if field > random(100) then results = "Oops! Too high!"
end mouseUp
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Code: Select all
on mouseUp
if field = random(100) then results = "Amazing! You guessed it!"
Else if field < random(100) then results = "Nope! Too low!!"
Else if field > random(100) then results = "Oops! Too high!"
end mouseUp
Code: Select all
on mouseup
verifNumber
end mouseup
Code: Select all
on mouseup
doNewNumberToGuess
end mouseup
Code: Select all
local sNumberToGuess
on opencard
doNewNumberToGuess
end opencard
on doNewNumberToGuess
put getNumberToGuess(100) into sNumberToGuess
end doNewNumberToGuess
function getNumberToGuess pNumber
return random(pNumber)
end getNumberToGuess
on verifNumber
ask "Type one number between 1 to 100"
if isNumber(it) is false then
answer "I need a number"
exit verifNumber
end if
if it = sNumberToGuess then put "Amazing! You guessed it!" into tAnswerResult
if it < sNumberToGuess then put "Nope! Too low!!" into tAnswerResult
if it > sNumberToGuess then put "Oops! Too high!" into tAnswerResult
answer tAnswerResult
end verifNumber
I have always used C# or Java before.
Code: Select all
local sNumberToGuess, sMaxNumberOfTries, sCuuentTryNumber
on mouseUp
startGame
end mouseUp
command startGame
-- initialize game variables
local tRanMin, tRanMax
put field "RanMin" into tRanMin
put field "RanMax" into tRanMax
put tRanMin + random(abs(tRanMax - tRanMin)) into sNumberToGuess
put field "TryMax" into sMaxNumberOfTries
put 1 into sCuuentTryNumber
-- ask first guess
askForNumber
end startGame
command askForNumber
-- do we have any tries left?
if sCuuentTryNumber > sMaxNumberOfTries then
-- quit game
answer "You lost! the number was" && sNumberToGuess & "."
exit askForNumber
end if
-- ask for input
local tGuess
ask "Try" && sCuuentTryNumber && ": What is your guess?"
put it into tGuess
-- player is bored or clicked on Cancel button?
if tGuess is empty then
-- quit game
exit askForNumber
end if
-- is the input valid?
if tGuess is not a number then -- maybe we should chech if it's a positive iteger?
-- ask again with same sCuuentTryNumber
askForNumber
end if
-- we have a number!
if tGuess = sNumberToGuess then
answer "Congratulations! You win i" && sCuuentTryNumber && "try!"
exit askForNumber
else if tGuess > sNumberToGuess then
answer "Too High!"
else
answer "Too Low!"
end if
-- increment the current try number and roll again!
add 1 to sCuuentTryNumber
askForNumber
end askForNumber
Code: Select all
on mouseUp
put random(100) into theNumber
put random(100) into theNumber2
if theNumber = theNumber2 then
answer "Matched"
end if
if theNumber < theNumber2 then
answer "Too Low"
end if
if theNumber > theNumber2 then
answer "Too High"
end if
end mouseUp
Code: Select all
local sNumberToGuess, sMaxNumberOfTries, sTryCounter
-- changed sTryCounter (prev. sCuuentTryNumber, too long and with a typo)
on mouseUp
startGame
end mouseUp
command startGame
-- initialize game variables
local tRanMin, tRanMax
put field "RanMin" into tRanMin
put field "RanMax" into tRanMax
put tRanMin + random(abs(tRanMax - tRanMin)) into sNumberToGuess
put field "TryMax" into sMaxNumberOfTries
put 1 into sTryCounter
-- ask first guess
askForNumber
end startGame
command askForNumber
-- do we have any tries left?
if sTryCounter > sMaxNumberOfTries then
-- quit game
answer "You lost! the number was" && sNumberToGuess & "."
exit to top
-- exit askForNumber caused a bug. If it wasn't caled on the firdst try, then the first guess call was still alive.
end if
-- ask for input
local tGuess
ask "Try" && sTryCounter && ": What is your guess?"
put it into tGuess
-- player is bored or clicked on Cancel button?
if tGuess is empty then
-- quit game
exit to top
end if
-- is the input valid?
if value(tGuess) is not a number then -- maybe we should chech if it's a positive iteger?
-- ask again with same sTryCounter
askForNumber
end if
-- we have a number!
if tGuess = sNumberToGuess then
answer "Congratulations! You win in" && sTryCounter && "tries!"
exit to top
else if tGuess > sNumberToGuess then
answer "Too High!"
else
answer "Too Low!"
end if
-- increment sTryCounter and roll again!
add 1 to sTryCounter
askForNumber
end askForNumber
if you are still interested, you could check the link I posted above:bhh32 wrote:...I don't understand it at all, and there are really no good tutorials out there for it that I can find....
If it helps, I once tried to learn C++ and it took me 2 days to write a single line of code that would compile. It's all in what you're used to.bhh32 wrote:Hi OP,
I too and used to languages such as C#, Java, and C++. This LiveCode language is driving me up the wall.
This is the tutorial I'm pointing for any experienced developer wanting to learn about LiveCode:jacque wrote: And don't give up. Once the penny drops it all falls into place at once.
Code: Select all
put random(100) into rand
on mouseUp
put field Input into guess
repeat while guess is not rand
if rand = guess then
answer "Great job! You guessed it!"
empty field Input
else if guess < rand then
answer "Sorry! You guessed too low!"
empty field Input
else if guess > rand then
answer "Not Quite! Too High!"
empty field Input
end if
end repeat
end mouseUp