MPUZ: A Simple Object

From Mario Fan Games Galaxy Wiki
This information is subject to change.
MPUZ
Mpuz logo.png
Development Main Page
Basics
Intermediate
Advanced
  • none
Reference
[Edit]


Getting Started

Assuming you're absolutely serious about creating a new object (why wouldn't you be?), just open up the object editor. I promise this won't be too hard to follow... at least I hope it won't be.

You'll also need an image of something: keep it small, around 16 x 16 pixels or so. We need an image or obviously we can't see the object (well, technically MPUZ will spit an error in your face if you don't have an image, so).

The Code

CREATE

Press the Create button to access the creation code area. We're going to need to define a couple of variables, because Lua doesn't like it if you call variables without defining them first; because this code runs only once when the object is created (and is the first to be called), it's a good idea to put variable defines and object setup code here.

me.cust.yoffset = 0 -- See NOTE 1
me.cust.yoriginal = me.y
me:talk("HELLO WORLD") -- See NOTE 2

-- NOTE 1: 'me' is a keyword that refers to the current object; 'cust' is just an organizer... you don't have to use 'cust' or another word for that matter, but it's a bad idea to just dump your variables into the main 'me space', unless you want to risk breaking something. You break, you buy
-- NOTE 2: 'talk()' is a function that displays a message bubble near the talking object; if you have NPCs or something, they'll probably use this (but they'll more likely use 'say()' instead, which will be covered later). 'HELLO WORLD' is used here because it's apparently a law to use that in your first program, and you don't break any laws, right?

MAIN BODY

Click on the Main button next; this is the code which is run each time the object is accessed. Obviously, this means a good chunk of your code will usually go here.

me.y = me.cust.yoriginal + sin(me.cust.yoffset) * 32 -- See NOTE 3
me.cust.yoffset = me.cust.yoffset + 1

-- NOTE 3: 'me.y' of course, is the object's Y position; you'll probably be modifying this a lot. MPUZ's trig functions take degrees if you were wondering. And, FYI, Lua (by default) does not support '+=' and the like; you'll live

Images

You should still have that image I mentioned earlier. Click the Images button, then the Add button. Select that image from the file selection box. You'll notice its outlined; this means it's selected (though that doesn't matter now). What does matter, however, is the fact that it's considered to be the object's default image, meaning it's the first to be displayed when the object is created. If you had more images, you could select one of those as the default; but you don't, so you can't. But anyway, just exit this screen once you've loaded the image.

IT'S ALIVE!!!1

Well, not really. Yet. First we have to export it. File -> Export. Done. You might want to save it too, which is a little different than just exporting it. You could reload it in either case, however (unless you precompiled the script(s), in which case you better hope you have more than just the exported object), but just get into the habit of saving.

The Result

You'll now have an object that nicely floats up and down, and annoyingly says "HELLO WORLD" every time you test the level... what level? Oh yes, the level you have to make in order to test the object! That's covered in the Simple Level tutorial, because this tutorial just covered making an object; don't you just love this.