The OHR Beginner's Scripting Guide Part I — Introduction

Talk about things that are not making games here. But you should also make games!

Moderators: Bob the Hamster, marionline, SDHawk

Post Reply
User avatar
BMR
Metal King Slime
Posts: 3310
Joined: Mon Feb 27, 2012 2:46 pm
Location: The Philippines
Contact:

The OHR Beginner's Scripting Guide Part I — Introduction

Post by BMR »

The OHR Beginner's Scripting Guide Part I — Introduction

Like my color guide, this guide is not meant to show or teach any specific techniques. Rather, it's aimed at complete beginners who are only just starting up with scripting. It'll introduce basic concepts, common terms, and various theories that are important (or at least useful) when reading and when writing scripts. That aside, let's get started.


I. Basic Concepts

Before anything else, what exactly is a script? In a nutshell, a script is a set of instructions written using a specific syntax that tells the engine how to do things that are beyond the scope of the default capabilities of the program. Specifically, a script is a series of instructions written outside of the engine, compiled, and then imported into the engine. As it is right now, the OHRRPGCE is rather capable by itself. You'll be able to do a great deal without ever touching scripting. Once you start wanting to implement things beyond the default capabilities of the engine though, you're going to need to do some scripting.

Because scripts are simple text files without any sort of interface, a lot of people may be scared off by the idea of mucking about with a bunch of meaningless symbols, words, and code. While it's certainly true that scripting can get very complicated, it's nowhere near as difficult as it initially seems. Some tasks are hard to do, others are easy to do, and as you gain more experience you'll get a better idea of what's possible, what's difficult, and everything in between.

The list below should give you an idea as to what sort of things you can accomplish:

  • ⬆Easier⬆
  • Tracking the number of battles fought
    .
  • Moving characters around a map
    .
  • Animating a custscene to tell the story
    .
  • Changing a map's scenery depending on in-game vents
    .
  • Getting guards to patrol a specific area
    .
  • A day/night cycle or weather effects
    .
  • Getting guards to patrol an area and attack on sight
    .
  • Making a randomly generated map
    .
  • A dynamic lighting system affected by walls
    .
  • Creating a custom combat engine
    .
  • Card Games
    .
  • Making a platformer
    ⬇Harder⬇


As you can see, there are many things you can do with scripting. It'll certainly take time and effort, but all sorts of things can be done with scripting. However, when starting scripting, it's a good idea to start small before moving onto bigger and grander things. It doesn't take long to master the basics, but even so it's still important to get a firm grasp on them first.

Now that you've gotten an idea as to what scripts are, let's move on to some basic concepts in scripting.



II. Commands

If you've done any sort of coding or scripting before, you'll know that the scripts are not written in plain English. Instead, they're written using a specific set of instructions and structured in a specific way. The language used by the OHRRPGCE is called HamsterSpeak. Everything in a script is written using HamsterSpeak and is then compiled upon importing into Custom. When writing anything in HamsterSpeak, you'll need to use a specific set of commands or functions. All the different functions are listed in the <a href="http://hamsterrepublic.com/ohrrpgce/doc ... tscripting Dictionary</a> along with how they're used, their proper syntax, and examples of their usage.

These functions govern what can be done and how things are written in HamsterSpeak. An important thing to note about HamsterSpeak is that everything is case insensitive and whitespace insensitive as well. This means that the following are all identical:

Code: Select all

walk hero &#40;me, north, 5&#41;
WALK HERO &#40;me, north, 5&#41;
walkhero&#40;me,north,5&#41;
Walk Hero &#40;Me, North, 5&#41;
Whenever you write a command, it is typically written on a line by itself. It is, however, possible to have multiple commands written on a single line and separated by commas. Either style works, but keep in mind that when using the latter, lines can get really long, really quickly.

These commands, no matter how you write them, will govern the flow of your script and how it acts. It is important then, to know what you want to do, and what the corresponding command is. Over the course of this guide, we'll be covering some of the more basic and more common commands and how to use them. We will also cover some of the more complicated or advanced ones, but not until the basics are covered.

However, commands by themselves are fairly useless. You'll need something to work with, and those are variables.

III. Variables

What exactly are variables then? In a nutshell, a variable is pretty much like a little box where you can store stuff in (programmers please pardon my description). This little box has a name, and you can use that to put things inside. You can use these variables to store many different things, a few of which are listed below:
  • Values to be used in computation
  • Specific NPC references
  • Hero stats
  • Coordinates of party members
  • Tag values for plot events
  • The number of items in inventory
As you can see, what you can store in variables is rather varied. You'll use command in conjunction with these variables to do pretty much everything. To use a variable, it first has to be declared. When declaring a variable, essentially what you're doing is telling the script interpreter, "This is the name of the variable I want to create. Keep this name in mind so that I can use it later." You an choose any name you want for the variable, and just like with commands, they are case insensitive and whitespace insensitive. The following declarations then, are all legal:

Code: Select all

variable&#40;
  currentx
  Current Y
  CoUnTeR
&#41;
That said, when naming your variables, it's a good idea to stick to choose a single naming and capitalizing convention and stick to it. While HamsterSpeak will not enforce any of these conventions on you, it's still helpful (especially when you've got hundreds of lines of script) to be able to easily look at your script and see everything in an organized, well-structured manner.

In other chapters, we'll talk more about how to manipulate variables, assign values to them, and get them to do some actual work. For now, it's enough to cover what they are. There are also different types of variables, but we will cover those in greater detail later on.


And that's all for this segment, in the next article, we'll compile our first script and import it into Custom.
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
User avatar
msw188
Metal Slime
Posts: 783
Joined: Tue Oct 16, 2007 1:43 am
Location: Los Angeles, CA

Post by msw188 »

Changing a map's scenery depending on in-game vents
This is the best way to decide what a map's scenery should look like.

I'm always a bit curious about guides like this. What counts as obvious, and what doesn't? I notice that BMR says that variables are a box that we can put things in. That's fine, but I'd think that it is VERY important to clarify that variables are only allowed to hold single numbers at a time. We need a whole separate thing to store "words" in, and if we need two numbers for something (like x,y coordinates of a hero on the map), we need two variables.

I'm also curious (although it doesn't matter at all) about how the various scripting ideas were assigned to be easy vs hard. I scripted a full 1-player poker game in Tales 1, and I'd say that was much easier than getting guards to patrol and attack on sight (which I also attempted, but was only vaguely successful with).

It might be worthwhile to say that the more ways a player can interact with a script, the harder it gets to write the script (generally). Thus cutscenes (where the player's control is suspended) are usually much easier than, say, scripting a light source that can be blocked by the player.
I am Srime
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

Nice! I'm looking forward to how this progresses. I'd say I can currently code within the middle to hard range with help and feedback from threads. I'd sure like to see more in depth explanations of the harder stuff you mentioned. I especially get confused when it comes to slices, or making an enemy have a triangular shaped field of vision, or how to make a field of vision obstructed by walls.

Anyways, I'm sure it'll be awhile before you get to the harder stuff but I'll keep checking in to see if I can learn something new.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
Post Reply