Help me with this activity!

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
MMH
Posts: 2
Joined: Thu Oct 26, 2017 4:08 pm

Help me with this activity!

Post by MMH » Sun Oct 29, 2017 11:56 pm

Hi everyone! I´ve been trying to make this activity where you should put three fields and a button in the fields you should specify the angles of a traingle, and when you hit the button, an image of the triagle should appear, it was working properly, and I closed the file. I do not know why now it is not working, it shows me this error.
***button "What is?": execution error at line 7 (Operators +: error in left operand), char 1***

this is the code
on mouseUp

put field "first" into x
put field "second" into y
put field "third" into z

if x+y+z=180
then set the visible of img "error" to FALSE

if x+y+z=180 and x=60 and y=60 and z=60
then set the visible of img "equilateral(1).png" to TRUE
else
set the visible of img "equilateral(1).png" to FALSE


if x+y+z=180 and x=y or y=z or x=z
then set the visible of img "isosceles" to TRUE
else
set the visible of img "isosceles" to FALSE


if x+y+z=180 and x=90 or y=90 or z=90
then set the visible of img "recto" to TRUE
else
set the visible of img "recto" to FALSE


if x+y+z=180 and x<>y and x<>z and y<>z
then set the visible of img "escaleno" to TRUE
else
set the visible of img "escaleno" to FALSE


if x + y + z <> 180
then set the visible of img "error" to TRUE

end if
end if
end if
end if



end mouseUp

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Help me with this activity!

Post by Klaus » Mon Oct 30, 2017 10:45 am

Déjà vue? viewtopic.php?f=7&t=30057&p=159687#p159687

It is good style to first answer other unanswered threads of yours! 8)
BTW, your code compiled without error on my machine.

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

Re: Help me with this activity!

Post by [-hh] » Mon Oct 30, 2017 10:52 am

This is probably homework. He/she learned nothing from the answers. Poor Klaus.
shiftLock happens

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Help me with this activity!

Post by Klaus » Mon Oct 30, 2017 12:09 pm

Then we have three of them currently.
O tempora, o mores! 8)

MaxV
Posts: 1579
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Help me with this activity!

Post by MaxV » Fri Dec 01, 2017 1:24 pm

Your code works, but an end if is missing:

########CODE to copy and paste#######
on mouseUp
put field "first" into x
put field "second" into y
put field "third" into z
if x+y+z=180 then set the visible of img "error" to FALSE

if x+y+z=180 and x=60 and y=60 and z=60 then
set the visible of img "equilateral(1).png" to TRUE
else
set the visible of img "equilateral(1).png" to FALSE

if x+y+z=180 and x=y or y=z or x=z then
set the visible of img "isosceles" to TRUE
else
set the visible of img "isosceles" to FALSE

if x+y+z=180 and x=90 or y=90 or z=90 then
set the visible of img "recto" to TRUE
else
set the visible of img "recto" to FALSE

if x+y+z=180 and x<>y and x<>z and y<>z then
set the visible of img "escaleno" to TRUE
else
set the visible of img "escaleno" to FALSE

if x + y + z <> 180 then
set the visible of img "error" to TRUE
end if
end if
end if
end if
end if
end mouseUp
#####END OF CODE generated by http://tinyurl.com/j8xf3xq with livecode 9.0.0-dp-10#####
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Help me with this activity!

Post by Klaus » Fri Dec 01, 2017 1:31 pm

Buongiorno Max,

you are spoiling almost all of our well-thought pedagogical approaches! :D


Best

Klaus

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7229
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Help me with this activity!

Post by jacque » Fri Dec 01, 2017 6:05 pm

This handler begs for a switch statement.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Help me with this activity!

Post by bogs » Fri Dec 01, 2017 10:07 pm

A switch statement, or just some clean up.

Code: Select all

on mouseUp
    lock screen
    set the visible of img "error" to TRUE
    put field "first" into x
    put field "second" into y
    put field "third" into z
// the following assumes all triangle images have something in common, 
// if so, just set the visible of all images you want from the start...
    repeat with x=1 to the number of images on card "yourCard"
        if image x contains "commonIdentifier" then
          set the visible of image x to false
        end if    
    end repeat
// then use switch/case or else if to determine visibility...
    if x+y+z=180
     then set the visible of img "error" to FALSE    
        if x+y+z=180 and x=60 and y=60 and z=60
          then set the visible of img "equilateral(1).png" to TRUE
        else if x+y+z=180 and x=y or y=z or x=z
          then set the visible of img "isosceles" to TRUE
        else if x+y+z=180 and x=90 or y=90 or z=90
          then set the visible of img "recto" to TRUE
        else if x+y+z=180 and x<>y and x<>z and y<>z
          then set the visible of img "escaleno" to TRUE
/* this test is not needed because to get into this loop
  we already know x + y + z = 180...
       else if x + y + z <> 180
         then set the visible of img "error" to TRUE */ 
        end if
    end if
    unlock screen
end mouseUp
The repeat I used there could be done a lot better, and probably without repeat at all, but I'll leave that as homework :)
Image

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”