sheep herder code flaws

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
chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

sheep herder code flaws

Post by chris25 » Tue Dec 10, 2013 2:24 pm

I accessed the sheep herder game, code, pdf and video via the "hour of code" website and tutorials that are going on around the world at the moment. There is a problem with the intersect code from PDF 2 video 2
Line 9 gives a missing factor error (line 10 I corrected there was a missing bracket from the pdf); I have tried "bounds" "opaque pixels" and 255 without the quotes since I read they are not required anymore. I have read previous posts but can not find any more ideas. My LC version is 6.1.2 community ed.
Chris

Code: Select all

on sheepGenerate  -- Only just lines A B C of this generate new btns every mouseup
   lock screen
   repeat with x=1 to sLevel
      repeat
         clone btn "templateSheep" --A
         set the name of the last btn to ("sheep" & x)
         set the loc of last btn to random(320), random(480) --B
         set the visible of the last button to true --C
         if intersect (btn ("sheep" & x),grc "pen" , "255") is false and
         intersect (btn ("sheep"&x), grp "groupControls" , "0") is false then
            exit repeat
         end if
         delete btn ("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 left 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

LCNeil
Livecode Staff Member
Livecode Staff Member
Posts: 1223
Joined: Wed Oct 03, 2012 4:07 pm

Re: sheep herder code flaws

Post by LCNeil » Tue Dec 10, 2013 3:06 pm

Hi Chris,

It looks like there is a formatting error in the PDF. The following script should be accross a single line and not two-
if intersect (btn ("sheep" & x),grc "pen" , "255") is false and intersect (btn ("sheep"&x), grp "groupControls" , "0") is false
With this change, you code should now apply.

I will put in a request to have this amended in the PDF

Kind Regards

Neil Roger
--
RunRev Support Team ~ http://www.runrev.com
LiveCode – Realize fast, compile-free coding

--

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: sheep herder code flaws

Post by chris25 » Tue Dec 10, 2013 3:22 pm

thankful to you
kind regards
chris

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: sheep herder code flaws

Post by chris25 » Tue Dec 10, 2013 3:34 pm

I should perhaps note that there are two too many 'end if's' in the sheepGenerate handler from pdf number 2. Just mentioning in case overlooked.
regards
chris

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: sheep herder code flaws

Post by chris25 » Tue Dec 10, 2013 6:19 pm

Believe me I have gone through the video lesson number 3 twice, have searched the forums. The problem now is that whenever I move the mouse inside the actual stack I get this error: can not set property, in the following where the location of the target is set to the mouse.

I understand the problem, but have no idea how to go about finding what exactly is wrong. The mouse entering the actual stack even before the start button is pressed means that the target is the stack, and not the sheep button. The cIsSheep property is in the button, it is set to true, the spelling has been checked. The sImASheep variable is declared at the top of the script. Everything appears to be in order. The pdf and my code do not differ.

Code: Select all

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

LCNeil
Livecode Staff Member
Livecode Staff Member
Posts: 1223
Joined: Wed Oct 03, 2012 4:07 pm

Re: sheep herder code flaws

Post by LCNeil » Tue Dec 10, 2013 8:20 pm

It sounds like you tested your mouseMove/mouseDown handlers before coding the required mouseRelease handler which puts puts "false" into sImASheep and in turn will alway execute the mouseMove hanlder.

What you will need to do is suppress messages within the LiveCode IDE (Message Icon in the toolbar), ensure you have the needed mouseRelease/mouseUp handlers and then enable messages again.

This should allow you to move the mouse about the stack without any error being thrown

Kind Regards

Neil Roger
--
RunRev Support Team ~ http://www.runrev.com
LiveCode – Realize fast, compile-free coding

--

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: sheep herder code flaws

Post by chris25 » Tue Dec 10, 2013 8:37 pm

Hallo Neil, No I can promise you that I had all that in already absolutely, I have been taking this very very slow to absorb every detail. However I can tell you that it works. I kept going through stuff over and over again. Once I posted the message to you I shut down LC completely (after 3 hours of it being up) and went to watch some programming videos. Just checked your message, re-started LC and then saw that everything is now working. So as always I put this down to something odd in memory because for example the mousemove handler was being activated even with the edit pointer tool, (not the edit Run tool), the groupedcontrols would move by themselves during this time. So basically LC needed to shutting down and now it works. Sorry to have bothered you, I usually shut down LC when things like this happen but just did not do it this time.
Kind regards
chris

LCNeil
Livecode Staff Member
Livecode Staff Member
Posts: 1223
Joined: Wed Oct 03, 2012 4:07 pm

Re: sheep herder code flaws

Post by LCNeil » Tue Dec 10, 2013 8:42 pm

Hi Chris,

Its no problem. We are here to help :) I'm glad you managed to resolve the issue yourself.

Kind Regards

Neil Roger
--
RunRev Support Team ~ http://www.runrev.com
LiveCode – Realize fast, compile-free coding

--

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”