IF statments To Jump to different areas in the script.

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

Post Reply
smith8867
Posts: 57
Joined: Tue Nov 18, 2014 5:36 pm

IF statments To Jump to different areas in the script.

Post by smith8867 » Tue Nov 18, 2014 5:42 pm

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

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

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

Post by magice » Tue Nov 18, 2014 6:18 pm

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.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10332
Joined: Wed May 06, 2009 2:28 pm

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

Post by dunbarx » Tue Nov 18, 2014 8:25 pm

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

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

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

Post by Simon » Wed Nov 19, 2014 12:40 am

And to add...
I see you put something into username and password1
But there is still one missing. :)

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

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

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

Post by [-hh] » Wed Nov 19, 2014 4:02 am

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 ...
shiftLock happens

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10332
Joined: Wed May 06, 2009 2:28 pm

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

Post by dunbarx » Wed Nov 19, 2014 5:41 am

Sorry, Hermann, those extra "?" are idiomatic for native English speakers, and just mean a really big question.

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

Craig

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

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

Post by [-hh] » Wed Nov 19, 2014 6:22 am

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
shiftLock happens

smith8867
Posts: 57
Joined: Tue Nov 18, 2014 5:36 pm

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

Post by smith8867 » Wed Nov 19, 2014 11:04 am

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!

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

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

Post by [-hh] » Wed Nov 19, 2014 12:02 pm

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.
shiftLock happens

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

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

Post by Klaus » Wed Nov 19, 2014 1:07 pm

[-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)

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

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

Post by [-hh] » Wed Nov 19, 2014 1:25 pm

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"? '
shiftLock happens

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10332
Joined: Wed May 06, 2009 2:28 pm

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

Post by dunbarx » Wed Nov 19, 2014 4:45 pm

Am I being accused of being British???

I grew up in Texas!!!!

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

Craig

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

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

Post by [-hh] » Wed Nov 19, 2014 5:21 pm

Colin: "Almost anything!"
shiftLock happens

Post Reply