Sheep Hander problem
Posted: 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!
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!
