Walk the Dog!
Video Tutorial
Click here for a YouTube video of Lloyd building this project.
(Note: For a "crystal clear" video, you may have to manually change the quality settings in YouTube to "720p HD" - just look for the gear symbol in the bottom right-hand corner of the YouTube window.)
LiveCode File for this Project
- Walk the Dog.livecode
Script for the button "Dog"
Important Note: The icon numbers shown below will almost certainly not match the numbers needed in your program. So, be sure to check for the correct numbers (as explained in the video) and update accordingly.
on mouseDown
grab me
set the icon of me to 1007
end mouseDown
on mouseUp
set the icon of me to 1006
end mouseUp
Advanced Script for the button "Dog"
This script checks to see if the dog is walking left, right, or is not moving. The image of the dog changes accordingly.
An important part of this script is a custom function I created titled "checkDogMovement." Notice the following line of code within this custom function:
send checkDogMovement to me in 50 milliseconds
This creates a loop that repeats as long as the variable varDogWalking
is true. I explain this technique in more detail in my explanation with the project "Lunar Hotel Shuttle."
Reminder: The icon numbers shown below will almost certainly not match the numbers needed in your program. So, be sure to check for the correct numbers (as explained in the video) and update accordingly.
global varx1, varx2, vary1, vary2, varDogWalking
on checkDogMovement
//if dog goes right, use 1007
//if dog goes left, use 1011
if varDogWalking is true then
put item 1 of the location of button "dog" into varx1
put item 2 of the location of button "dog" into vary1
if varx1 < varx2 then set the icon of me to 1011
if varx1 > varx2 then set the icon of me to 1007
if varx1 = varx2 and vary1 = vary2 then set the icon of me to 1006
if varx1 = varx2 and vary1 <> vary2 then set the icon of me to 1007
put item 1 of the location of button "dog" into varx2
put item 2 of the location of button "dog" into vary2
send checkDogMovement to me in 50 milliseconds
end if
end checkDogMovement
on mouseDown
put item 1 of the location of button "dog" into varx1
grab me
put true into varDogWalking
checkDogMovement
end mouseDown
on mouseUp
put false into varDogWalking
set the icon of me to 1006
end mouseUp