Make a Xmas Game
Make a Xmas Game - Beginners!

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.

 

The Message Path

 

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!

About The Author
Kevin Miller
Heather Laine
Heather is Customer Services Manager for LiveCode.
Read Heather's Blog
Other Articles
Hour of LiveCode
   11.12.2014

Last night we held our "Hour of Code" live online, taking you through the first lesson for the Create it with LiveCode course. We were delighted with the turnout, so many of you participated!

 

For those of you who could not be there, we have recorded the session and you can view it here.

Read more
 
 
Seeking Eureka
   11.12.2014
We've been finding out about some of the people on our Create it with LiveCode course. Our job is to get you all to that moment when you realise, hey, yes, I can do this! I'll be following how well we do together on this journey, and a great place to start is by meeting you, the coders-to-be.
Read more

Build an Xmas Game

   11.12.2014

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,

Read more
What is a Variable?
   11.12.2014
It's basic, it's fundamental, it's something you will use all the time in LiveCode, and it's something that beginners are frequently baffled by. This lesson explains what variables are, the different types you can use, and why you use them.
Read more
 
Thank you for your time.

 

© LiveCode 2014