Page 1 of 1

IF statments To Jump to different areas in the script.

Posted: Tue Nov 18, 2014 5:42 pm
by smith8867
I am a new coder with live code and we have been giving homework to create a simple program that gets user data and displays it in an output. The 1 thing we have to do though is verify data with IF statements and I am struggling.
I will post show the code below of what I have done so far, I have commented what I would like to do, but I just cannot seem to figure out how to do it.

Code: Select all

//Variables that will be used.
global username, password1, password2, email, gender, dob

on mouseUp
   get_user_data
   display_result
end mouseUp

on get_user_data
   ask "What is your name?"
   put it into username
   
   ask "Please enter a password you would like to use."
   put it into password1
   ask "Please re-enter the same password so we can verify it"
   
   if password1 = password2
   then //jump to part in this scirpt
   else answer "The passwords you entered did not match, please try again." then 
   //jump back up to asking for password
end get_user_data

Re: IF statments To Jump to different areas in the script.

Posted: Tue Nov 18, 2014 6:18 pm
by magice
Since this is homework I'm not going to give you a complete answer, just a hint. Look at "command" in the LC dictionary.

Edit: I just realized they still haven't added command to the dictionary, so try "on" which is a synonym.

Re: IF statments To Jump to different areas in the script.

Posted: Tue Nov 18, 2014 8:25 pm
by dunbarx
Hi.

The syntax for doing what you want sort of goes like this:

Code: Select all

if "truth" = 42 then
  tellHermann
else
  relax
end if

on tellHerman
  answer "What gives???"
end tellHerman

on relax
  answer "Whew"
end relax
Function and command calls are made by name. This is in contrast to, say Basic, where you might "jump" to a particular location. (Or even a line number. Is this still is use?) Anyway, it is important that you play with this. A lot.

Craig Newman

Re: IF statments To Jump to different areas in the script.

Posted: Wed Nov 19, 2014 12:40 am
by Simon
And to add...
I see you put something into username and password1
But there is still one missing. :)

Simon

Re: IF statments To Jump to different areas in the script.

Posted: Wed Nov 19, 2014 4:02 am
by [-hh]
Recently I searched a developer name, that jacque mentioned. I had about a billion of very similar results, of sort I don't like very much. So I prepared to see pure horror when searching for the "???" that Craig mentioned, because I don't know what "???" is. You won't believe it and I couldn't believe it: NO HITS (in words: zero hits) when searching with Google. Not even Craig's post above was found ...

Craig, who stole the question marks?? (<-- Even these two will not be be found by Google.)

Simon, there is no use in trying to think about sha-42 or asking for his password2, here it is, "???", the one you can even post here, will not be found, just try ...

Re: IF statments To Jump to different areas in the script.

Posted: Wed Nov 19, 2014 5:41 am
by dunbarx
Sorry, Hermann, those extra "?" are idiomatic for native English speakers, and just mean a really big question.

Like "Yipes!!!!" means 42 = "true".

Craig

Re: IF statments To Jump to different areas in the script.

Posted: Wed Nov 19, 2014 6:22 am
by [-hh]
Hi Craig.

I use this too and as a young man I was even able to remember what question mark number 42 on my third sticky meant. Now only three on one sticky are too much :-(

(Time to go to bed, sorry, it's early morning here, just before the dawn.)
Hermann

Re: IF statments To Jump to different areas in the script.

Posted: Wed Nov 19, 2014 11:04 am
by smith8867
dunbarx wrote:Hi.

The syntax for doing what you want sort of goes like this:

Code: Select all

if "truth" = 42 then
  tellHermann
else
  relax
end if

on tellHerman
  answer "What gives???"
end tellHerman

on relax
  answer "Whew"
end relax
Function and command calls are made by name. This is in contrast to, say Basic, where you might "jump" to a particular location. (Or even a line number. Is this still is use?) Anyway, it is important that you play with this. A lot.

Craig Newman
Thanks Craig, This is exactly what i was looking for!

Re: IF statments To Jump to different areas in the script.

Posted: Wed Nov 19, 2014 12:02 pm
by [-hh]
Hi 'smith8867', probably 8/8/67 or 6/7/88 is your birthday, so this is NOT your homework?
Magice, Craig and Simon have sometimes very black british humour (although at least two of them are not from MontyPython).

You could start with the following and come back They all here will help you as they helped me when I was a very beginner (and wasn't able to finish my homework).

Code: Select all

on mouseUp
  repeat with j=1 to 4
    put get_user_data(j, line 1 of uPasswd) into uPasswd
    if line 1 of uPasswd is "Seems to be OK"  then
      put line 2 of uPasswd into line 1 of uData
      exit repeat
    else
      if j=4 then
        answer "Not very funny."
        exit mouseUp
      end if
    end if
  end repeat
  # .. similar for other data and other lines of uData
  put uData into field "safe place"
end mouseUp

function get_user_data nbOfTrials, askStrg
   ask askStr & CR & "Please enter a password (trial" && nbOfTrials && "out of maximal four)"
   put it into password1
   ask "Please re-enter the same password so we can verify it"
   put it into password2
   -- is not casesensitive, also 2*21 = 1+41 ... Still a lot to do here
   if password1 = password2 and passwd1 is not empty then 
     return "Seems to be OK" & CR & passwd2
   else
     return "The passwords did not match, please try again."
   end if
end get_user_data
Magice, please, how do you know this is his homework? I never had to do such homework, you can conclude this from my script above, I've to do this better as homework now.

Re: IF statments To Jump to different areas in the script.

Posted: Wed Nov 19, 2014 1:07 pm
by Klaus
[-hh] wrote:Magice, please, how do you know this is his homework?
Quick shot:
Maybe because Mr. Smith mentioned this fact in his very first sentence? 8)

Re: IF statments To Jump to different areas in the script.

Posted: Wed Nov 19, 2014 1:25 pm
by [-hh]
Yes. He said. But how do you know it *is* his homework?
May be he pretended this only, because this is in fact a non-trivial, difficult question: "How to jump to different areas in the script?" Read 'script' here as 'handler'.
I saw some discussions about that and first thought this is once again one about that. None of these discussions did end in a satisfactory solution/answer.
Have you a special trick in your treasure chest for ' How to jump within one handler to "marks"? '

Re: IF statments To Jump to different areas in the script.

Posted: Wed Nov 19, 2014 4:45 pm
by dunbarx
Am I being accused of being British???

I grew up in Texas!!!!

If you want black British humour, say almost anything to Colin.

Craig

Re: IF statments To Jump to different areas in the script.

Posted: Wed Nov 19, 2014 5:21 pm
by [-hh]
Colin: "Almost anything!"