Part I - Loading and Moving Slices
Hello, and welcome to this short little tutorial. In this tutorial, we'll cover the bare-bones basics of slices and how to use them in a game. We'll cover loading slices up, moving them around, destroying them, and a few other nifty things.
This won't cover absolutely everything though, as there are simply far too many things that you can do with slices for all of them to be covered here. Instead, this should serve as a solid starting point from which a newcomer to slices will be able to build upon before moving on to some of the more advanced (and fun!) aspects of slices. Specifically, we'll cover what slices are, manipulating slices, parent-child slices, moving slices around, and removing them. We'll touch on slice collections, sorting slices, and special slices, but we won't go too in-depth with them. It will also be divided into different parts, to keep things short and easily "digestible".
This tutorial assumes that you already have an average grasp of plotscripting, so we won't be going too much into how to script. We will, of course, go over how to use the specific commands and their proper syntax, but we won't be discussing how to compile your slice-movement script or how to go about writing a script.
Anyways, that's enough for the introduction, so without further ado, let's get started!
I - What is a Slice?
First off, what exactly is this "slice" thing everyone's ranting and raving about? In a nutshell, a slice is pretty much anything that's drawn to the screen like sprites, layers, etc... This means that all graphics, the sprite attached to your hero, the layer he/she's walking around in, etc... are all slices. That's certainly a bit overwhelming though, so we'll talk about those special slices later on.
It would be easier, perhaps, to think of a slice as anything you load up and slap onto the screen to get some sort of effect or functionality. If you've worked with the OHRRPGCE for any amount of time, you've probably grown accustomed to thinking of things on the screen in terms of tiles. It's easy to move the hero to (3, 12) or have a fireplace at (4,1) animating nicely. Slices, on the other hand, do not operate by tiles. They operate fairly independently from tiles, and instead of such, they are pretty much always worked on by addressing the actual pixel coordinates.
Think of them then as free-floating images that you load and place on top of the main gameplay. Take the following image, for example:
In that image, the four sprites in the center are all standard NPCs that can be moved about using simple commands like walk npc. The other elements though, the health/magic/stamina bars, the portrait, and the weapon info, are all slices which have been placed on top of the basic gameplay, as illustrated below:
With this, the slices are all placed on top of the main action. This means that they operate independently of everything moving below them. A walk hero command will not interfere with any of the slices used here. They all exist unattached to any of the standard gameplay elements right now. Moving slices about and manipulating them thus allows you to do all sorts of fantabulous things with slices. A few examples would be a mouse cursor, a combat engine (shown in the pictures), a HUD similar to SNES Legend of Zelda games, and a whole bunch of other things.
With that done, let's go on to how to actually create a slice.
II - Loading Slices
The first thing that must be understood when working with slices is just how they behave and how they're manipulated. If, for example, I wanted to move my barbarian hero (the long-haired dude in a loincloth in the picture above) it would be extremely simple:
Code:
script, move belor west, begin
walk hero(hero:Belor, west, 6)
end
script, move belor west, begin
walk hero(hero:Belor, west, 6)
end
What you'll notice is that it's trivially easy to grab the hero and move him around by referring to him as hero:Belor. One of the most confusing things when starting out with slices then, is just how are you supposed to refer to them? How are you supposed to tell your script which slice to move left, which one to move in circles, and which one to get rid of? The answer is simple, you have to use slice handles.
All slices have a handle. This is the specific identifier that is used to... well, identify that slice and single it out from all of the other slices that you may be using. Just about every single command for slices will take a slice handle as an argument, so it's important to keep track of these.
That does not, however, mean that when a slice is created, you'll automagically get a number which you have to write down. Instead, slice handles can be stored in variables, the same way as any other value. All slice functions that load a slice up will return a slice handle. Now, you don't absolutely have to store this value if you're just going to load it once and never touch it again. That, however, is rather unlikely, so you'd create a variable the way you'd normally create variables, and then store the returned number in that variable.
Code:
script, my first slice thingy, begin
variable(sl)
sl := load portrait sprite(4)
end
script, my first slice thingy, begin
variable(sl)
sl := load portrait sprite(4)
end
Take note, in this example, we've used sl as the name for the slice handle. A lot of the examples in the plotscripting dictionary and the wiki also use sl, but this is by no means something that you have to do. sl is not some magical variable that has to be used with slices. If you have your own naming conventions (you really should have some sort of naming convention, if only to keep organized) then by all means, rename your variable to whatever you want. The above example works just as well as this one (though I can hardly see anyone actually using that as a variable name):
Code:
script, my second slice thingy, begin
variable(oogyboogyslicehandle)
oogyboogyslicehandle := load portrait sprite(4)
end
script, my second slice thingy, begin
variable(oogyboogyslicehandle)
oogyboogyslicehandle := load portrait sprite(4)
end
What this particular little script does is loads portrait 4 (as defined by you in Custom) and stores the handle of that particular slice in variable sl. This is important, because that handle refers only to that specific instance of portrait #4. If I were to load portrait #4 again for some reason, it would have a different handle and would have to be stored in another variable.
Code:
script, my first slice thingy, begin
variable(sl1, sl2)
sl1 := load portrait sprite(4)
sl2 := load portrait sprite(4)
end
script, my first slice thingy, begin
variable(sl1, sl2)
sl1 := load portrait sprite(4)
sl2 := load portrait sprite(4)
end
In that example, we would have two slices loaded to the screen which happen to be identical in appearance. They would, despite being the same portrait, have different slice handles. This means that they can be (and indeed, should be) manipulated as separate, distinct, entities.
There are a whole bunch of different commands to load a slice up. They are all in the plotscripting dictionary and all typically take the form load X sprite(num, palette). Now, you may be wondering why even portraits, borders, etc... are all called "sprites" when all your experience with Custom has told you that sprites only refer to walkabouts and battle graphics. While this may be true normally, when working with slices, pretty much all of these graphics, portraits, enemy sprites, weapons, borders, etc... are all referred to as sprites. This will come into play later on, but for now, suffice to say that they are all "sprites" when it comes to slices.
So, now that we know how to load a slice and what a handle is, let's get on to moving slices around.
III - Moving Slices Around
Let's go back to the example of moving the barbarian hero around:
Code:
script, move belor west, begin
walk hero(hero:Belor, west, 6)
end
script, move belor west, begin
walk hero(hero:Belor, west, 6)
end
In that example, we know that the hero is referred to as hero:Belor. We also know, that to refer to a slice in the same way, we would have to first store the slice's handle before we can do anything to it. Once you've got the handle stored in a variable, it's easy to refer to it and move it anywhere and anyway you want.
There are a whole bunch of different ways to move slices; far too many to cover each in detail. Here, however, are a few of the more common ones:
- put slice(handle, x, y)
- set slice x(handle, x)
- set slice y(handle, y)
Perhaps the one that you'll be using the most often, is put slice. What that does, is it moves the slice you're referring to, to a specific (x, y) coordinates. Now remember, when working with slices, you're going to be using pixel coordinates, not tile coordinates.
Code:
script, my thid slice thingy, begin
variable(sl)
sl := load portrait sprite(4)
put slice(sl, 10, 10)
end
script, my thid slice thingy, begin
variable(sl)
sl := load portrait sprite(4)
put slice(sl, 10, 10)
end
What this little bit of code does is it loads up portrait #4, stores the handle of that slice in variable sl, and then puts that slice at pixel coordinates (10, 10). The set slice x and set slice y commands are similar, but instead of specifying a certain (x, y) coordinates, you can instead change only the x or the y coordinates.
There are a whole bunch of other methods to move slices around, and they're all documented in the plotscripting dictionary, so feel free to experiment.
Closing
And that's all for this part for now. Next time, tune in for Text Slices, Containers, and Parent-Child slices!
BMR out!
Being from the third world, I reserve the right to speak in the third person.
Using Editor version wip 20170527 gfx_sdl+fb music_sdl



