figuring out this language

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!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: figuring out this language

Post by Klaus » Thu Feb 18, 2016 10:57 am

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! :D
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

ethanCodes
Posts: 46
Joined: Sun Feb 14, 2016 9:08 am

Re: figuring out this language

Post by ethanCodes » Fri Feb 19, 2016 1:47 am

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.

ethanCodes
Posts: 46
Joined: Sun Feb 14, 2016 9:08 am

Re: figuring out this language

Post by ethanCodes » Fri Feb 19, 2016 1:55 am

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! :D
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

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: figuring out this language

Post by Simon » Fri Feb 19, 2016 1:55 am

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 used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: figuring out this language

Post by Simon » Fri Feb 19, 2016 1:59 am

Oh I see what Craig was talking about

Code: Select all

put random(100) into rand
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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

ethanCodes
Posts: 46
Joined: Sun Feb 14, 2016 9:08 am

Re: figuring out this language

Post by ethanCodes » Fri Feb 19, 2016 2:16 am

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?

ethanCodes
Posts: 46
Joined: Sun Feb 14, 2016 9:08 am

Re: figuring out this language

Post by ethanCodes » Fri Feb 19, 2016 2:43 am

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.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: figuring out this language

Post by Simon » Fri Feb 19, 2016 3:03 am

The random number is not working correctly.
You'll have to declare rand as a local variable

Code: Select all

local rand
on openCard
put....
And yeah, you don't need the repeat, as long as they always push Submit

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

ethanCodes
Posts: 46
Joined: Sun Feb 14, 2016 9:08 am

Re: figuring out this language

Post by ethanCodes » Fri Feb 19, 2016 3:21 am

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

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: figuring out this language

Post by Simon » Fri Feb 19, 2016 3:38 am

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

ethanCodes
Posts: 46
Joined: Sun Feb 14, 2016 9:08 am

Re: figuring out this language

Post by ethanCodes » Fri Feb 19, 2016 3:46 am

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!

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: figuring out this language

Post by Simon » Fri Feb 19, 2016 4:32 am

Glad you got it working...
I see I screwed up again by not putting quotes around field Input

Code: Select all

put field "Input" into guess
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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Post Reply