Page 1 of 1

Sheep Hander problem

Posted: Tue Mar 31, 2015 2:24 pm
by zhangyouwen
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

Re: Sheep Hander problem

Posted: Tue Mar 31, 2015 4:34 pm
by jacque
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.

Re: Sheep Hander problem

Posted: Wed Apr 01, 2015 7:34 pm
by zhangyouwen
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!

Re: Sheep Hander problem

Posted: Wed Apr 01, 2015 8:21 pm
by sefrojones
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

Re: Sheep Hander problem

Posted: Tue Apr 07, 2015 2:15 pm
by zhangyouwen
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.

Re: Sheep Hander problem

Posted: Tue Apr 07, 2015 8:31 pm
by sefrojones
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

Re: Sheep Hander problem

Posted: Wed Apr 08, 2015 7:55 pm
by zhangyouwen
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

Re: Sheep Hander problem

Posted: Sun Aug 09, 2015 10:54 am
by rookienr101
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