Question about " if "

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
Nibor
Posts: 18
Joined: Wed Nov 21, 2012 12:13 pm

Question about " if "

Post by Nibor » Fri Nov 30, 2012 9:41 am

Hi guys,
can somebody please give me a hint what could be wrong in this short code ?

if the field "username" is item 3 of group "dguser" in stack "usergroup"
then
if the field "password" is item 3 of group "dguser" in stack "usergroup"
then
close this stack
go to stack "entry"
end if
end if

LiveCode always says error button "login": compilation error at line 3 (if: missing 'then') near "in", char 48

I don't get it.. there is a "then". I tried to write the whole code once more or to restart LiveCode or restart my computer.
Nothing.. always the same error message. I really hope that someone can help me with this.

best regards

Nibor

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Question about " if "

Post by Dixie » Fri Nov 30, 2012 9:58 am

Hi... in your example you need to use 'AND" as you want to evaluate more than one condition ...

Code: Select all

on mouseUp
   if fld "username" = "Boo" AND fld "password" = "Hoo" then
      lock screen
      open stack "entry"
      close stack "whateverTheNameIs"
   end if
end mouseUp
I haven't tested this, just off the top of my head... but it should point you in the right direction..

Dixie

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

Re: Question about " if "

Post by Klaus » Fri Nov 30, 2012 11:02 am

Hi Nibor,

as Dixie said AND:
This line does not make any sense, since "item X of group Y" does not resolve to any TEXT:
...
if the field "password" is item 3 of group "dguser" in stack "usergroup"
...
Only FIELDS (and custom properties, but that will come much later :D ) can resolve to TEXT.

Hint: To be on the safe side, use the official syntax:
1. if field "xyz"...
## not THE field

2. ... OF stack "Y"
## not IN stack, same for cards -> OF card


Best

Klaus

Nibor
Posts: 18
Joined: Wed Nov 21, 2012 12:13 pm

Re: Question about " if "

Post by Nibor » Fri Nov 30, 2012 11:24 am

Thanks to both of you =)

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

Re: Question about " if "

Post by dunbarx » Fri Nov 30, 2012 4:32 pm

Dixie.

You can do the double test in two lines, though I agree it is clunkier. But that would not throw an error.

Craig

Post Reply