Page 2 of 2
Re: figuring out this language
Posted: Thu Feb 18, 2016 10:57 am
by Klaus
Hi Ethan,
ethanCodes wrote:I'm getting a runtime error when trying to empty the field Input. Any ideas?
yes, that magic word is PUT!
Sounds funny, but you need to:
..
put empty into fld "Input"
...
And get used to QUOTE strings like names of objects!
Isn't it this way also in other languages?
And as others already stated, don't let your user get stuck in an endless repeat loop!
Exit the handler if something is not correct and let the user enter a new answer.
Best
Klaus
Re: figuring out this language
Posted: Fri Feb 19, 2016 1:47 am
by ethanCodes
Simon wrote:Hi ethanCodes,
You are going to give yourself a headache.
Look at how your loop never stops (well until the input is correct), it's pretty much going to lock-up the computer. I'd be surprised if you can type a new answer into the "input" field.
Check out "exit repeat" and "on enterInField" in the dictionary.
Simon
Yes I understand that. That was what my question was? It needs to loop until the user answers the correct answer. The problem is it is giving me an error when I hit the submit button.
Re: figuring out this language
Posted: Fri Feb 19, 2016 1:55 am
by ethanCodes
Klaus wrote:Hi Ethan,
ethanCodes wrote:I'm getting a runtime error when trying to empty the field Input. Any ideas?
yes, that magic word is PUT!
Sounds funny, but you need to:
..
put empty into fld "Input"
...
And get used to QUOTE strings like names of objects!
Isn't it this way also in other languages?
And as others already stated, don't let your user get stuck in an endless repeat loop!
Exit the handler if something is not correct and let the user enter a new answer.
Best
Klaus
So how do I get the random number to stay the same number until the correct number is guessed? I don't want it to change every time the button is clicked
Re: figuring out this language
Posted: Fri Feb 19, 2016 1:55 am
by Simon
Hi Ethan,
Have you done what Klaus said?
put empty into fld "Input"
And have you figured out where to put "exit repeat"?
Simon
Re: figuring out this language
Posted: Fri Feb 19, 2016 1:59 am
by Simon
Oh I see what Craig was talking about
That has to go inside a handler maybe "on openCard"
That would only happen once when the card ummm.... opens
So, that answers your question to Klaus.
Simon
Re: figuring out this language
Posted: Fri Feb 19, 2016 2:16 am
by ethanCodes
Simon wrote:Hi Ethan,
Have you done what Klaus said?
put empty into fld "Input"
And have you figured out where to put "exit repeat"?
Simon
I did what Klaus said, but I'm not sure I know what to do with the exit repeat? does it go after they guess the correct number? I mean shouldn't the while statement take care of that?
Re: figuring out this language
Posted: Fri Feb 19, 2016 2:43 am
by ethanCodes
So I realized I guess I don't really need to use repeat right? I mean, if I set rand on the "on openCard", and then use an if statement to change the random number when the right number was guessed, the player can just go on playing as much as they want. I did find another problem though. The random number is not working correctly. I seem to only get the "You guessed to low" response, even if its much larger than 100.
Re: figuring out this language
Posted: Fri Feb 19, 2016 3:03 am
by Simon
The random number is not working correctly.
You'll have to declare rand as a local variable
And yeah, you don't need the repeat, as long as they always push Submit
Simon
Re: figuring out this language
Posted: Fri Feb 19, 2016 3:21 am
by ethanCodes
Ok, I wasn't sure how declaring variables worked on here. So its getting closer, but now the answer is always 0 for some reason. I'm assuming the variable rand is initialized to 0, and for some reason it is not setting a random number to the variable. Here is my updated code:
Code: Select all
local rand
local guess
on openCard
put random(100) into rand
end openCard
on mouseUp
put field Input into guess
if rand = guess then
answer "Great job! You guessed it!"
put random(100) into rand
put empty into field "Input"
else if guess < rand then
answer "Sorry! You guessed too low!"
put empty into field "Input"
else if guess > rand then
answer "Not Quite! Too High!"
put empty into field "Input"
end if
end mouseUp
Re: figuring out this language
Posted: Fri Feb 19, 2016 3:38 am
by Simon
My mistake...
I take it your openCard is in the button script?
Wont work there.
Ok a re-think....
Code: Select all
on mouseUp
if rand is empty then
put random(100) into rand
end if
put field Input into guess
....
See how that will only fire once?
I don't know how you guys do it in other languages but you should start prefixing your variables (e.g. tRand, tGuess) it helps in following them.
Simon
Re: figuring out this language
Posted: Fri Feb 19, 2016 3:46 am
by ethanCodes
Hey that did! Awesome! Well, I'll be honest, I don't really like this language or this system, but I've gotta use it pretty extensively for this class so I guess I'd better get used to it. I learned a lot from this small project. I really appreciate the help! I'm sure I'll be back in a few days with some new questions! I know I need to figure out the whole stack thing...I don't really get all that. Thanks again for the help!
Re: figuring out this language
Posted: Fri Feb 19, 2016 4:32 am
by Simon
Glad you got it working...
I see I screwed up again by not putting quotes around field Input
Always put quotes around strings even if this worked for you this time it's going to come back and bite you soon. LiveCode is forgiving a lot of the time.
As for learning LiveCode, just give it some time and soon you'll be thinking of a way to solve a problem and BANG it'll come to you in an English like form and then you'll see how fun it is.
"How do I find the standard deviation of these three numbers?" hit the dictionary and there it is.
Simon