Sheep Hander problem
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 11
- Joined: Tue Mar 31, 2015 2:14 pm
Sheep Hander problem
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!
-
- VIP Livecode Opensource Backer
- Posts: 7237
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Sheep Hander problem
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
HyperActive Software | http://www.hyperactivesw.com
-
- Posts: 11
- Joined: Tue Mar 31, 2015 2:14 pm
Re: Sheep Hander problem
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!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.
-
- Livecode Opensource Backer
- Posts: 447
- Joined: Mon Jan 23, 2012 12:46 pm
Re: Sheep Hander problem
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
--Sefro
-
- Posts: 11
- Joined: Tue Mar 31, 2015 2:14 pm
Re: Sheep Hander problem
Hey, I just sent you a message with the link of my file on dropbox, please take a look thank you.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
-
- Livecode Opensource Backer
- Posts: 447
- Joined: Mon Jan 23, 2012 12:46 pm
Re: Sheep Hander problem
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
Hope that helps!
--Sefro
-
- Posts: 11
- Joined: Tue Mar 31, 2015 2:14 pm
Re: Sheep Hander problem
It worked thank you so much!!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
-
- Posts: 4
- Joined: Sun Aug 09, 2015 10:30 am
Re: Sheep Hander problem
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
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