B) This is the Only line of code that make no sense to me out of the whole lot. And happens to be the only line that dishes up a fault (murphys law), I know what it is doing. Once created it gets deleted, fine, that is the sheep, but how on earth does LC know that this parameter is a sheep button when I can not see where it has been given that information in the first place.
I know everyone is busy, so no rush, but would eventually appreciate some guidance please.
Kind regards
chris
Code: Select all
local sLevel, sImASheep, 
on levelIncrease
   --put empty into sLevel
   add 1 to sLevel
   sheepGenerate
end levelIncrease
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), grc "groupedControls" , "0") is false then
            --above must be on one line
            exit repeat
            delete btn ("sheep" & x)
         end if
      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
on mouseDown 
   if the cIsSheep of the target is true then
      put true into sImASheep
      end if
end mouseDown
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
on mouseUp
   mouseRelease
end mouseUp
on mouseRelease
   put false into sImASheep
   if intersect (the target, grc "pen" , 255) and the cIsSheep of the target is true then
      sheepDelete the target
   end if
   set the backgroundcolour of the grc "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 fld "sheepcount" +1 into fld "sheepcount"
   put sheepLeft() into tCounts
   if tCounts < 2 then
      levelIncrease
      end if
end sheepDelete
