I was cruising youtube videos featuring LiveCode this week, and I came across this really neat and topical set of videos on making a Christmas themed card or game. I couldn't resist trying it out for myself, and I have to say, I got a surprising amount of satisfaction out of the very very simple app I've just created. As some of you know, I'm not really a coder, although working here for so long I do seem to have absorbed some of the basics accidentally...
I thought you might enjoy it too, especially as there is a strong tutorial theme this week, and we have a lesson on Variables for you. This simple first part of the game has several variables in action to help you grasp the concept.
You can download my part 1and part 2 stacks here, together with the assets I used.
This video has two deliberate mistakes in it - can you spot them before the speaker corrects them? I spotted one of them, but not the other. This is the script from my stack:
on keydown Whichkey
local yposition, xposition
put top of image "santa" into yposition
put left of image "santa" into xposition
switch Whichkey
case "a"
set the left of image "santa" to xposition-5
break
case "d"
set the left of image "santa" to xposition+5
break
case "w"
set the top of image "santa" to yposition-5
break
case "s"
set the top of image "santa" to yposition+5
break
end switch
end keydown
So far, so good! My Santa is moving about the screen just like in the tutorial! I'm greatly encouraged to take a look at the next video.
After half an hour or so of working through the tutorial I have achieved a present that is always tantalisingly out of reach. Obivously as a game concept this is flawed but I'm sure that will be addressed in the next stages...
A couple of things tripped me up during this video. Firstly, I did not allow for the fact that the dimensions of my stack/background were not quite the same as those demonstrated in the video, so my box went off screen a few times before I corrected the problem, and secondly we had to move a handler from a button to the stack script. I found I had to close the code editor with the error message, and re-open it from the Object menu in order to paste in the handler in the correct place.
The speaker does not explain why that handler needed to be moved. This is because he originally had it in a button script, and then tried to refer to it from a stack script. But the handler was not in the correct place in the message path for this to work. The LiveCode message path sends messages from the top down, so a button will look in its own scripts first, then in the card script, then in the stack script and finally default to the engine if it can't find anything else to handle a message. However the stack script will not look "upward" to a button script, it only looks down towards the engine. So we were able to put the handler in the stack script and delete it from the button script, because the button was able to find it in the stack.
Learn more about the message path here.
I will carry on working through these videos and creating my own Xmas Game in the next edition of the newsletter. Hopefully I will finish my game in time for Christmas.
My thanks are due to the author of this video series, D. Stoble, whoever and wherever he may be. Nice work!
|