Cuppycake's Metaplace Journey - Part 2
At this point in time, Ponyplace was nothing more than a flamboyantly colored background of grass and rivers (made completely of tiles that were available for free on the web) with a gaudy orange and pink pony plopped down in the middle. Not much of a game yet, but I could clearly see the vision of where I wanted Ponyplace to be. The question was, how do I get there?
The first thing that I knew I needed was movement, crucial in making Ponyplace a game rather than a slide show. This was where I was about to start my intimate romance with scripts. *cue dramatic music* At this point I wasn’t familiar at all with templates, but knowing about them now makes this a lot easier to explain – so I’ll attempt to do so.
A template is really a pretty simple concept that took me a little bit of time to comprehend, so I’ll try to define one in terms that will make everyone understand. Basically, every object in your world has a template. It isn’t necessarily its own unique template (for example, every gnoll in your RPG can be from a gnoll template) but every object needs one. What this means is that if I make a gnoll template, and make it so that gnoll has 40 hitpoints, and give it pink hair – every gnoll that I place down in my game using that template will have 40 hitpoints and pink hair. If I want an ogre instead of gnoll, then I make a new template called “Ogre.” Templates are the cookie cutter for all the different cookies I’ll want to put in my game.


Now that I’ve given a little primer, I’ll explain how I made my pony move. Right off the bat I thought to myself, “How the heck will I come up with the code to make my pony move!!??one11” but it proved to be quite simple. We have this awesome resource called the Metaplace Wiki that has an entire section dedicated to code snippets. These are little pieces of rad functionality that I can completely rip off (read: steal) by coping and pasting it into my world. There happened to be one named “Simple click-to-move” and since I like simplicity – I stole it.
-- Inputs and commands
Define Commands()
(1) MakeInput('Click on terrain to move to destination.',
'mouse-terrain', 'click', 'none', 'slide_terrain')
(2) MakeCommand('slide_terrain', 'Slide to destination on terrain.',
'x:float', 'y:float', 'z:float')
end
-- Commands
Command slide_terrain(x,y,z)
(a) distance = math.abs(x - self.x) + math.abs(y-self.y)
(b) slideTime = 350 + distance * 75
(c) SlideObject(self, x, y, z, slideTime, 1)
end
There’s the code. Daunting, isn’t it? It’s really not that scary – but I remember being TERRIFIED by this. Let’s break it down a bit.
Let’s start with the second section which is the Commands section. This is the real meat of the script; the part that actually makes the avatar walk around. The first line (labeled with an “a”) just calculates the distance between where you’re currently standing and where you click to move. The “b” line calculates the time you should take to move in, or the speed. The third line, “c”, actually moves the object. SlideObject is a built in function that my world will already understand as long as I give it the right parameters. You’ll notice there are 6 parameters (self, x, y, z, slideTime, 1) and I could explain each one – but this is already a lot more technical then I wanted it to be.
The first section is the Inputs and Commands section. Line 2 just makes a command named “slide_terrain” and line 1 makes it so that command is executed whenever you click the mouse. Easy! Less than 15 lines of code and now every single person who plays Ponyplace will be able to move.

So I opened up my player script and plunked this chunk of code right down inside it. I saved the script (which checks for any script errors – luckily I didn’t have any errors or I’d blame someone else for them). My player script comes automatically attached to the player template, but I double checked it just to be sure. I tried to click around in my world and nothing happened.
Oh! Silly me, I forgot to change my world to “play” mode. Worlds have two different modes when you’re in the tools – “Build Mode” and “Play Mode”. A simple button click toggles the two modes, but while you’re in build mode it makes it so that your scripts don’t function so that things aren’t moving around while you’re working on your world. I changed to “Play Mode” and clicked around. Nothing happened. I swore.
After swearing a lot, I decided to just restart my world to see if that would fix it. It did! (Turns out I could have just reloaded my user instead of restarting the whole world, but I hadn’t learned that yet). My pony could now glide gently around the pasture by clicking the mouse. It was incredible! I have never felt so triumphant in my life. After prancing around the office and proudly proclaiming that I am the best programmer who has ever worked on Metaplace – I came down to earth and realized that I hadn’t REALLY done anything other than copy/paste a script. It still felt amazing and made me want to do more and more. After learning how to make my pony walk, it was only minutes of work to learn how to make the pony rear up on its hind legs when you hit space bar. Hitting “E” for eat, made my pony put its head down to the ground. I imported a galloping sound for when the pony ran, and a munching sound for when the pony eats. It was simple and awesome.
I quickly announced to everyone in the office that I have created a masterpiece and that they should come check it out by pasting them a URL right to my game. I had 5 or 6 people in Ponyplace at once, everyone an exact orange and pink clone of my pony (those thiefs!). Everyone could click around and move because they were all “players” and the player template had a player script that contained my movement code. All little objects running around my world, instantly multiplayer with all the same abilities. Watching everyone run around galloping, eating, and rearing up on their hind legs was an exhilarating feeling. It wasn’t much, but I had made my first epic game within Metaplace.
Tami "Cuppycake" Baribeau
Community Manager


