Sheepherder Game Academy

Creating Games? Developing something for fun?

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
sukagambar
Posts: 1
Joined: Mon Apr 13, 2015 4:08 am

Sheepherder Game Academy

Post by sukagambar » Mon Apr 13, 2015 5:13 am

Hi everyone,

I'm a LiveCode newbie. I'm following the Sheepherder Game Academy tutorial. I' halfway into Lesson 3 where we do the code to move the sheeps into the pen. The logic is simple: on mouseDown it will just check if the object under the mouse cursor is a sheep (via checking a custom property on the sheep which is always set to true). If it is then the code will set a flag to true to indicate that user is clicking down on a sheep. Later on in a mouseMove event the code will check if this flag is true. If it is it means the user is trying to drag the sheep into a pen and it will set loc of the sheep to match the loc of the mouse. The flag is just a local (not temporary!) variable called slmASheep. I have declared this as a local variable at the beginning of the script. All this script is put in a card script.

The problem is the flag is never set to true whenever I enter on mouseMove. The flag is set to true correctly in the mouseDown event if I click on top of a sheep. Here is the frustrating thing: my script is full copy + paste from the tutorial page but it still doesn't work! Even more frustrating it was working the first time I run it. But at the time I forgot to copy + paste one line which reset the flag to false. This is needed after the user has put a sheep into a pen. I thought "Okay I just add this 1 line then everything should works". Unfortunately after I've added that line it doesn't work at all. Since the flag is never set to true inside the mouseMove even the dragging effect doesn't work. I've tried to remove that line and it still doesn't work.

Here is my card script. It is a complete copy + paste from the tutorial page. I just tidy up the indentation. I can't seem to upload my livecode file. It said "Extension is not allowed".

Code: Select all


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 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 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, 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
   put false into sImASheep
   if intersect (the target, Graphic "pen", 255) and the cIsSheep of the target is true then
      delete the target
   end if
   set the backgroundcolor of the graphic "pen" to "blue"
end mouseRelease


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

Re: Sheepherder Game Academy

Post by LCNeil » Tue May 05, 2015 11:18 pm

Hi Sukagambar,

The local variable that you've declared at the top of your script is "slmASheep" when it should be "sImASheep"

The difference here is the lower case "l" instead of upper case "I". If you change this then the script should work as expected.

Kind Regards,

Neil Roger
--
LiveCode Support Team ~ http://www.livecode.com
-

hudsonj
Posts: 3
Joined: Fri Apr 29, 2011 9:44 pm

Re: Sheepherder Game Academy

Post by hudsonj » Thu Dec 10, 2015 6:36 pm

My student can not move the sheep. In LiveCode version 8 the set property contents to true is different than version 7. I went back to version 7 with his file and set the property and now the sheep will move. Tomorrow I plan to try this file back in version 8.

Any suggestions for how to set the Property Contents to "true" in version 8?

Post Reply

Return to “Creating Games”