General Implementation of Variables

Published September 15, 2014
Advertisement
I have no screenshots for this post, because here I'm going on about the ideology of variables and data types. First, a brief comparison with Enterbrain's RPG Maker programs.

Most of you who are also developers likely know all about variable types, but on the off chance that one or two of my readers are traditionally non-programmers or have only passing knowledge of RPG Maker, I'll discuss all this to the basics.

In the RPG Maker game editor, you can specify Boolean conditional states, but they are confusingly called "switches", used in either global visibility or as "self-switches" within Events. (The reason this is confusing to any "proper" programmer, is because the 'switch' keyword is actually listed in most object-oriented programming language (such as Java) as a "reserved keyword" used in conditionally branching through functionality based upon the value of a variable or result of a method. Why Enterbrain chose to go with 'switch' to denote a Boolean state is, you know, beyond me....)

The editor also allows specifying numeric (integer) values (also, quite oddly, simply called "variables") although they are not "typed" like Java variables are (byte, short, int, long, et cetera). At this point in my examination, none of the RGSS or RTP documentation seems to specify exactly how the RPG system handles numeric type-conversions and mathematic operations; it just seems something of a "gutless wonder" in Ruby (of which I'm also quite oblivious).

In terms of the RPG Maker editor, it seems you are only able to access the list of global "switches" and "variables" and per-event "self-switches" via Event page editing; as there is no Database tab to list and modify all those variables.

Variable Types In Java.


To my logical mind, at least, I am quite happy with the variable types. The types native to Java are (primarily) thus:

  • The Boolean Condition. A boolean value is what most RM'ers think of when they use switches and self-switches in RPG Maker events; it merely handles true:false states (also called on:off state), which is technically just flipping the polarity of a single bit.
  • The Numeric Values. A number of numeric variable types exist to use in calculation.

    • A byte value (whose value range is -128 to 127 and only requires 8 bits) could be used for "small" values.
    • A short value (whose value range is -32,768 to 32,767 and requires 16 bits, or 2 bytes) could be used for most normal integer values.
    • An int value (whose value range is -2,147,483,648 to 2,147,483,647 and requires 32 bits, or 4 bytes) could be used for larger values.
    • A long value (whose value range is -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 and requires 64 bits, or 8 bytes) are definitely for incredibly humongous values. One typical use is for tracking the milliseconds' value of the operating system's time. -- For most purposes, I have no idea why an RM game would need this, but I am supporting the type just in case.
    • But for the non-whole-number values we have a 32-bit float and a 64-bit double type, (floats for 7 significant digits, doubles for 15 significant digits).

  • The Character Values. A char and a String are for textual objects; the char type is purely for text of one character in length, and a String object (merely a Java class that wraps around a multi-length array of char objects). For plain-text ASCII, each char takes one byte; but for extended character sets you could double or even quadruple the number of bytes per literal character.

  • And so it goes. The number variable types are signed to be positive or negative; so, you cannot have an unsigned byte for the range of 0 to 255 (as much as I'd like it to).

    All of the above is important to the point that (when this is all completed) we as a game creator can optimize the game classes to make variables use the least amount of memory bytes when running. Such problems used to be the concern of game makers back in the early console system days, when games came on cartridges with limited memory. (Thankfully, we are past the memory-limited days, ... although it never hurts to be concerned about game optimizations, in a general sense.)

    Variable Types In My ARPGM.


    In my own Alternative RPG Maker, and Java development (in which variables are strongly-typed), I am using variable fields arranged according to their specific Java types. In fact, I've written Java classes that wrap each of these types along with some handling methods so that it simplifies mathematical operations and comparisons from elsewhere in the engine; these operations shouldn't be too unfamiliar to someone who has used RPG Maker's Event system "required conditions" and the switch or variable operations to get or set a value, or to compare to another value.

    As far as their representation in my editor interface, I am wanting to show the variable name for each of the aforementioned/defined variable types, in their own tab; both the name and initial value, if so desired, should be modifiable from within the tab page. Of course, for a literal-minded programmer like me who loves strongly-typed variables, this means that I will enforce creating and editing variables according to my wrapper classes. And this means that variables can be a bit more organized.

    Where This Is Useful.


    This is incredibly useful to my design philosophy, for any typed data that can be editable in the editor. It isn't even solely for the global variables, either; actually, the Event instances can have appropriately-typed self-variables such as boolean, integer, and String objects. In RPG Maker, a typical event has access to four self-switches but no numeric values. (Four boolean conditions might be too few for some events, so it is possible to subclass the parent Event class so that different types of events can use more variables.) And a map instance could possibly have its own per-map variables, for values that may only be used on that map - and unloaded and saved when leaving that map.

    And especially for events on a map; I have ideas for games where you have some seed and a plot of land. For the individual crop tile, I should want to track various aspects of its life-cycle; soil fertility, moisture, stage and time of growth, et cetera. And a different event type on a map might be a specialized NPC Event with its own characteristic variables; a dating sim or relationship management sim might have NPC variables for times talked, last time talked, current favor, maximum favor, relationship level, or something.

    Basically, I have been looking into any way possible to streamline the potentially extensive list of switches and integral data that RM creators could end up having. If certain variables may only ever be needed when certain characters are active, or when certain maps are active, or from within certain events are running, and not used when they are not in memory, ... then why not make them a part of that character, or map, or event?

    It's obvious that I'm an incredibly big dreamer; I see what Enterbrain hath wrought, but I see how an rpg maker could have or should have become, and I want to provide it.
    0 likes 0 comments

    Comments

    Nobody has left a comment. You can be the first!
    You must log in to join the conversation.
    Don't have a GameDev.net account? Sign up!
    Advertisement
    Advertisement