Sheep Hander problem

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
zhangyouwen
Posts: 11
Joined: Tue Mar 31, 2015 2:14 pm

Sheep Hander problem

Post by zhangyouwen » Tue Mar 31, 2015 2:24 pm

Hi, I am currently following Sheep Herder Lesson in Livecode Academy. I had a problem that when move the sheep on top the pen the pen only change color once and the sheep will not be deleted. Also when move the sheep away from the pen, the color of the pen will stay with blue instead of change back to red. Which is really weird because I used the exact code that the lesson provided.

Here is my card script:

Local sLevel, slmASheep

on levelIncrease
put empty into sLevel
add 10 to sLevel
sheepGenerate
end levelIncrease

on sheepGenerate
lock screen
repeat with x = 1 to sLevel
repeat
clone button "templateSheep"
set the name of the last button to ("sheep"& x)
set the loc of the last button to random(320), random(480)
set the visible of the last button to true
if intersect (button("sheep"&x),graphic"pen",255) is false and intersect (button("sheep"&x),group"groupControls",0) is false then
exit repeat
end if
delete button ("sheep"&x)
end repeat
if the top of button ("sheep"&x) < the top of this card then
set the top of button ("sheep"&x) to the top of this card
end if
if the left of button ("sheep"&x) < the left of this card then
set the left of button ("sheep"&x) to the left of this card
end if
if the right of button ("sheep"&x) > the right of this card then
set the right of button ("sheep"&x) to the right of this card
end if
if the bottom of button ("sheep"&x) > the bottom of this card then
set the bottom of button ("sheep"&x) to the bottom of this card
end if
end repeat
unlock screen
end sheepGenerate

on mouseMove
if sImASheep is true then
set the loc of the target to the mouseLoc
if intersect (the target, Graphic "pen", 255) and the cIsSheep of the target is true then
set the backgroundcolor of the graphic "pen" to "red"
else
set the backgroundcolor of the graphic "pen" to "blue"
end if
end if
end mouseMove

on mouseUp
mouseRelease
end mouseUp

on mouseRelease
if intersect (the target, graphic "pen",255) and the cIsSheep of the target is true then
sheepDelete the target
end if
set the backgroundcolor of the graphic "pen" to "blue"
end mouseRelease
function sheepLeft
local tCount
repeat with x = 1 to the number of buttons of me
if the cIsSheep of button x of me is true then
add 1 to tCount
end if
end repeat
return tCount
end sheepLeft

on sheepDelete pTarget
local tCounts
delete pTarget
put field "sheepcount" + 1 into field "sheepcount"
put sheepLeft() into tCounts
if tCounts < 2 then
levelIncrease
end if
end sheepDelete

the attachment is my original app, please take a look and help me out with the problem, thank you! :D

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

Re: Sheep Hander problem

Post by jacque » Tue Mar 31, 2015 4:34 pm

Are you sure you included all the handlers? I don't see anything that determines whether the object is a sheep or not. There may be a mouseDown missing, or something else that puts true into sImASheep.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

zhangyouwen
Posts: 11
Joined: Tue Mar 31, 2015 2:14 pm

Re: Sheep Hander problem

Post by zhangyouwen » Wed Apr 01, 2015 7:34 pm

jacque wrote:Are you sure you included all the handlers? I don't see anything that determines whether the object is a sheep or not. There may be a mouseDown missing, or something else that puts true into sImASheep.
Can you please help me? I have no idea on how to fix it, perhaps please look at the app that I uploaded. Thank you!

sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Re: Sheep Hander problem

Post by sefrojones » Wed Apr 01, 2015 8:21 pm

It looks like your attachment didn't actually get attached, as I believe you will need to have a certain amount of posts before you can attach a file. You can always post a link to your stack hosted on dropbox/google drive/mega/wherever until you are allowed to post attachments.

--Sefro

zhangyouwen
Posts: 11
Joined: Tue Mar 31, 2015 2:14 pm

Re: Sheep Hander problem

Post by zhangyouwen » Tue Apr 07, 2015 2:15 pm

sefrojones wrote:It looks like your attachment didn't actually get attached, as I believe you will need to have a certain amount of posts before you can attach a file. You can always post a link to your stack hosted on dropbox/google drive/mega/wherever until you are allowed to post attachments.

--Sefro
Hey, I just sent you a message with the link of my file on dropbox, please take a look thank you.

sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Re: Sheep Hander problem

Post by sefrojones » Tue Apr 07, 2015 8:31 pm

In your script, you are checking the cIsSheep, but in your template sheep button the custom property is misnamed as cLsSheep. (I capitalized the L here, but in your template button it is lower case)


Hope that helps!

--Sefro

zhangyouwen
Posts: 11
Joined: Tue Mar 31, 2015 2:14 pm

Re: Sheep Hander problem

Post by zhangyouwen » Wed Apr 08, 2015 7:55 pm

sefrojones wrote:In your script, you are checking the cIsSheep, but in your template sheep button the custom property is misnamed as cLsSheep. (I capitalized the L here, but in your template button it is lower case)


Hope that helps!

--Sefro
It worked thank you so much!! :D :D :D

rookienr101
Posts: 4
Joined: Sun Aug 09, 2015 10:30 am

Re: Sheep Hander problem

Post by rookienr101 » Sun Aug 09, 2015 10:54 am

Hi
Am trying to follow the Sheep Herder course. Works fine till I get to the mouseDown etc handlers/code. Then it all fails. For some reason my code does not move anything. I can click start ok, but the sheep don't react at all. In other words, I cannot click/drag anything.

However, I also tried copy/pasting the code provided with the course. Still no interaction with the sheep? Even after correcting one missin "n" in mouseDow...

What is wrong with the code in the course or why doesn't it work for me? Can anybody provide any clues?

Thanks for any help!

The code from the course is of course as follows:
"Sheepherder Lesson 3"

Local sLevel, sImASheep

on levelIncrease
--put empty into sLevel
add 1 to sLevel
sheepGenerate
end levelIncrease

on sheepGenerate
lock screen
repeat with x = 1 to sLevel
repeat
clone button "templateSheep"
set the name of the last button to ("sheep"& x)
set the loc of the last button to random(320), random(480)
set the visible of the last button to true
if intersect (button("sheep"&x),graphic"pen","255") is false and intersect(button("sheep"&x),group"groupControls","0") is false then
exit repeat
end if
delete button ("sheep"&x)
end repeat
if the top of button ("Sheep"&x) < the top of this card then
set the top of button ("Sheep"&x) to the top of this card
end if
if the left of button ("Sheep"&x) < the left of this card then
set the left of button ("Sheep"&x) to the left of this card
end if
if the right of button ("Sheep"&x) > the right of this card then
set the right of button ("Sheep"&x) to the right of this card
end if
if the bottom of button ("Sheep"&x) > the bottom of this card then
set the bottom of button ("Sheep"&x) to the bottom of this card
end if
end repeat
unlock screen
end sheepGenerate

on mouseMove
if sImASheep is true then
set the loc of the target to the mouseLoc
if intersect (the target, Graphic "pen", 255) and the cIsSheep of the target is true then
set the backgroundcolor of the graphic "pen" to "red"
else
set the backgroundcolor of the graphic "pen" to "blue"
end if
end if
end mouseMove

on mouseUp
mouseRelease
end mouseUp

on mouseRelease
if intersect (the target, graphic "pen",255) and the cIsSheep of the target is true then
sheepDelete the target
end if
set the backgroundcolor of the graphic "pen" to "blue"
end mouseRelease

function sheepLeft
local tCount
repeat with x = 1 to the number of buttons of me
if the cIsSheep of button x of me is true then
add 1 to tCount
end if
end repeat
return tCount
end sheepLeft

on sheepDelete pTarget
local tCounts
delete pTarget
put field "sheepcount" + 1 into field "sheepcount"
put sheepLeft() into tCounts
if tCounts < 2 then
levelIncrease
end if
end sheepDelete

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”