RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Variable Tutorial Beta

0 Members and 1 Guest are viewing this topic.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Okay, I am working on an event commands tutorial which covers every command in detail. I just finished the Control Variable part of it, but after reading it I feel it might be too long, boring and incomprehensible for the average person. So, I decided to post this portion of my tutorial to get some feedback on what I can cut out and what stuff in it isn't clear, etc... Anyway, I have it attached and be sure to criticize harshly.

EDIT:

I'll put it in a spoiler so there is no unneccesary downloading going on. You won't get the pretty colours though  :( I want to hear from n00bs especially! Tell me what you don't understand so that I can make this better!

Spoiler for:
CONTROL VARIABLE

This is another thing that a lot of people don’t know how to use. They justify this by saying it’s primary use is as a condition, and since they know how to use switches and conditional branches, they say that it is only minimally useful at best. I say, WRONG! Superman is not coming to save you, and worse still you don’t have a mini Superman to shove pianos at people! Variables are a lot more useful than switches; variables are more efficient than switches in almost every situation and they can even be used in a lot of situations where switches fail. This is one of the most important event commands and even complicated actions can be evented easily through the use of variables. I will try my best to explain them in detail for this reason, and so this is going to be a long chapter.

Without any further ado, I present to you the Control Variables Interface. Get to know it well, for without it your eventing can only be, at best, mediocre:


 
Okay, as you can see, this has the same interaction as do switches. You can either operate on a single variable or you can operate on a group of variables within a range (with the limitation that you want to apply the same operation to group of variables which are all bunched together. The difference is the amount of operations you can apply to variables. Before we get to that, let me try to explain what a variable is.

A variable stores any value from -9999999 to 9999999. Each one of these numbers is kind of like a position. So, where a switch has 2 positions (ON and OFF), a variable has 19999999 positions. That’s exactly 9,999,999.5 times more positions than a switch. A typical example of the use of variables is as a tool for counting progress in a quest. Let’s go back to the old lady example. Say that the old man doesn’t want you to kill just one old lady, say he wants you to kill three old ladies. Using switches: one switch so that he doesn’t repeatedly give you the quest, ie. Once you accept the quest, he does not continue asking you to do the quest. Then you’d need an additional switch to turn on for each old lady you kill. 3 old ladies = 3 switches. So a total of 4 switches for this quest. With variables, you only need to use one variable and merely use a Control Variables[Old Lady Murder Spree] +1 for each instance where you would normally use a switch.


See, already you should be getting the feeling that variables are awesome. Well Addition is only one of the operations you can use on variables.


The Control Variables Event Command can be split into three distinct parts: Variable, Operations, and Operand. The variable part is where you choose which variable (or variables) you are going to change with this command. The operations part is where you choose which operation to perform (the operations are all listed in the Operations section below). And the operand part is what you are performing the operation with. Essentially this is the number which you are using to effect changes in your variable (example: if you are using the operation add, this is the number that you add to the variable). You can make the operand a number of different things, which I will explain in the Operand section.

Operations

I am going to go over the operations now, and to make things easier, let’s say we are working with a variable called [Test]. Note, however, that this is an arbitrary name. All operations work the same on any variable.

Set: This basically means “gets the value:” and then in the operand section you choose what value it gets. [<variable>]  = [<operand>]So if you choose the constant “3” as your operand, then the variable [Test] = 3. By default, before any operations are applied to a variable it is set to 0.

Addition: This adds the operand to the value currently stored in the variable. [<variable>] = [<current value stored in variable>] + [<operand>]. The current value in [Test] is 3, so if we use the addition operation with constant 2, then [Test] = [Test] + 2, so [Test] = [3] + 2 so [Test] = 5

Subtraction: This subtracts the operand from the value currently stored in the variable. [<variable>] = [<current value stored in variable>] - [<operand>]. The current value in [Test] is 5, so if we use the subtraction operation on [Test] with the operand being a constant 3, then [Test] = [5] – [3] = 2. So [Test] is now storing the value [2].

Multiplication: This operation multiplies the value currently stored in the variable by the operand. [<variable>] = [<current value stored in variable>]x[<operand>]. Let’s say our operand is 4, then using this operation on [Test] = [2]x[4] = 8. [Test] is now storing the value [8]. Now, I will state this in a slightly more complicated way in the hopes that it will help you better understand the next operation, mod. One thing to note about this operation (about all operations really), is that if the result of the operation is greater than 9999999, then the value stored in the variable defaults to 9999999. So if you were to try to multiply [Test] by 2000000, then [Test] = [8]x[2000000] = 16000000, but the variable [Test] receives the value [9999999].

Division: This operation divides the value currently stored in the variable by the operand, and then rounds down to the nearest integer. [<variable>] = [<current value stored in variable>] / [<operand>]. So, with our variable [Test]. It’s current value is 8, and say we take operand 4, then [Test] = [8] / [4] = 2. Keep in mind that it will round down, so if we took the operand 5, [Test] = [8] / [5] = 1.75 = 1.

Mod: I suspect that most of you have no idea what this last one is, so I will take my time explaining it. Mod calculates the remainder after division. Division        (a / b) can be written in this form: a = bq + r, where a is the number you are trying to divide, b is the number that is dividing it, q is an integer such that bq is less than or equal to a and that b(q+1) is greater than a, and r is the remainder. You’ll probably benefit more from an example. Let’s say we are trying to divide 8 by 5. [8] = [5]x[1] + [3]. The number mod is concerned with is the remainder, so you can say 8 mod 5 = 3. Another example: what is 7 mod 3? [7] = [3]x[2] + 1, so 7 mod 3 = 1. Hopefully you understand this, but in any case I can’t spend any more time on it so I will just give one last example in terms of RMXP variables. The value currently stored in [Test] is 8. SO, if we apply the operand 6, then              [8] % [6] => [8] = [6]x[1] + [2], so [8]%[6] = 2. The value currently stored in [Test] is now 2. Notice also that q (in this case 1) is the value you get when you divide 8 by 6 in variable operations.

Operand

Constant: This is just an integer from -9999999 to 9999999. Pretty simple.

Variable: This allows you to select another variable (or the same variable) as the operand. In other words, if we have two variables, Test 1 and Test 2, and Test 1 = 4; Test 2 = 5, then we could use [Test 1] as the variable we are changing and  [Test 2] as the operand. As far as usage goes, [Test 1] = [current Test 1] + [Test 2] and so [Test 1] = 4 + 5 = 9. Note that it is still only the variable you are specifying that is changed, [Test 2] (the operand) is still only equal to 5.
Random: This takes a single number from a range that you specify and uses it as the operand. Each number from within the range is equally likely to be chosen. So, if you specify a range from 1 to 3, then there is approximately a 33.3 % chance 1 will be chosen, a 33.3% chance 2 will be chosen, and a 33.3% 3 will be chosen. This is useful for anything that has no set outcome. For example, you could use it for dice or anything that requires some randomness.

Item: This works by specifying an item in your inventory. Then, the operand takes the value of the number of that item you have in your inventory. For example, if you specify potions, and your party has 2 potions in their inventory, then the operand will take the value of 2. If the party has 3 potions, then the operand will take the value of 3. etc…

Actor: For this, you have to specify both the player character(people you can have in party) and the parameter. You can choose any character and then from that you can choose any of the following parameters which correspond to that character: Level, Exp, current HP, current MP, max HP, max MP, Strength, Dexterity, Agility, Intelligence, Attack, Physical Defence, Magical Defence, and Evasion. The operand takes the value of the number corresponding to the parameter. For instance, if Aluxes’ Strength is 435, then the operand takes the value 435. Note, max HP means max HP for level, and current HP means max HP – the damage he has received.

Enemy: This is a command meant exclusively for combat. When you are not in combat, it takes the value 0. When you are in combat, it has all the same parameters as actor has, but they correspond to the enemy you specify.

Character: This can apply to any event on the map and the player, just specify it in the first slot. Then, you can specify any of six parameters: Map X, Map Y,
Direction, Screen X, Screen Y, and Terrain Tag. Map X is the x-position of the specified event. X goes from left to right, from zero to (map width – 1). Y goes from top to bottom, from zero to (map length – 1) That’s probably hard to understand so I’ll post a screenshot: Format: x coordinate, y coordinate. Map width = 4, map length = 4
 


Screen X and Screen Y are similar to Map X and Map Y but are determined in pixels, not squares. Each square is 32 pixels x 32 pixels, so basically Screen X = 32x(Map X) and Screen Y = 32x (Map Y). Direction assigns a number to the direction the event is facing. As I stated earlier, Down = 2, Up = 8, Left = 4, and Right = 6. So if the event is facing down, the operand takes the value 2, etc…
Terrain Tag refers to the Database. If you look in the database under tilesets, you can set tiles on a map to have tags from 0 to 7. This command takes the tag from the tile the event is standing on and uses it as the operand.
Other: These are all pretty self explanatory. Map ID: operand takes the value of the Map ID #. Party Members: operand gets the number of characters in your party. Gold: operand gets amount of gold party is currently holding. Steps: operand gets amount of steps party has taken. Play Time: operand gets number of seconds the game has been played for. Timer: operand gets number of seconds left on timer. Save Count: Operand gets # of saves.

Some of you may still have doubts. You are looking at this long, boring, mostly incomprehensible section and thinking to yourself, “sure, it was sort of useful for that quest example, but I still think switches can do everything that variables can… WRONG!!! To show you some of the uses for variables, I will build upon my previous example. In reality, if you were an old man who wanted a few old ladies murdered, would you really ask some random stranger who walked into your house? Probably not. For this reason, maybe you want an alignment system like in Fable. Maybe you only want the old man to ask you if you are sufficiently evil that he believes you will do it. This can easily be accomplished through the use of a single variable. All you have to do is make it so that whenever you do a good action, your alignment variable increases and whenever you do an evil action, your alignment variable decreases. To demonstrate how this would work: Let’s say we base the system on a scale from -5000, …, 5000. 5000 is the maximum good and -5000 is the maximum evil. Killing an old lady is fairly evil, so let’s say that subtracts -250 each time you do it. You can easily make it so that you are only granted the quest if your alignment variable is less than -1000 by putting it into the conditions. Maybe also, you don’t want the old man to say the exact same thing every time you talk to him (you use random for this). So now, our events look like this:

OLD MAN (for all: Trigger: Action Key; Graphic: OLD MAN)

Page 1:
Conditions: None

Event Commands:
Text: This day is filthy; rotten! I have a hankering to murder some old women! You with me?
Show Choices: Yes, No
When Yes
     Text: There be a three old hags in this city that need akilling me hearties. I am a
             pirate! Go now and find them. They do be in shacks near the ocean I say! I give
             ye a share of the plunder matey!
     Control Variable [1. Pointless Killing!] + 1
When No
     Text: Useless Landlubber
Branch End

Page 2:
Conditions: Variable [2. Alignment] is -999 or more

Event Commands:
Control Variable [3: random talking]: Random (1,…,3)
Conditional Branch: [Variable [3: random talking] = 1
    Text: Ah, the fluttering of the butterflies puts this old, weary heart at rest.
Branch End
Conditional Branch: [Variable [3: random talking] = 2
    Text: We are blessed with fine weather this day.
Branch End
Conditional Branch: [Variable [3: random talking] = 3
    Text: AH! Were only my wife alive to feel this Spring air.
Branch End
 
Page 3:
Conditions: Variable [1. Pointless Killing] is 1 or more

Event Commands:
Text: What are ye layin’ aboot here fer. Go kill them ladies by the wharf?

Page 4:
Conditions: Variable [1. Pointless Killing] is 4 or more

Event Commands:
Text: Aye, ye done well fer a useless layabout landlubber!
Change Gold: + 1000
Text: You got a 1000 gold!
Control Variable: [1. Pointless Killing] +1
Page 5:
Conditions: Variable [1. Pointless Killing] is 5 or more
Text: Ye done well laddie. I’ll make use of yea agin some day I reckon.

Each OLD HAG (for all: Trigger: Action Key; Graphic: OLD LADY)

Page 1:
Conditions: None

Event Commands:
Control Variable [3: random talking]: Random (1,…,3)
Conditional Branch: [Variable [3: random talking] = 1
    Text: You seem to be a fine young gentleman
Branch End
Conditional Branch: [Variable [3: random talking] = 2
    Text: I hear there is a nice old man in central who loves the Spring
Branch End
Conditional Branch: [Variable [3: random talking] = 3
    Text: I was once the Queen of Scotland
Branch End

Page 2:
Conditions: Variable [1. Pointless Killing] is 1 or more

Text: Ay, why is your sword drawn?
Battle Processing: Helpless Old Lady
Control Variable [1. Pointless Killing] + 1
Control Variable [2. Alignment] - 250
Control Self Switch: [A] ON

Page 3:
Conditions: Self Switch A is ON
NO GRAPHIC
NO EVENT COMMANDS

See how useful they are! I did not even use 1/100 of variables’ potential in that example.
« Last Edit: March 20, 2007, 07:44:02 PM by modern algebra »

*
I love Firerain
Rep:
Level 97
=D
So far so good M.A
Arlen is hot.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
I put it in a spoiler so you guys don't have to dl.

**
Rep:
Level 87
Your tutorial better explains the interface of Variable Operation than mine.  Haha I assume way too much. Very nice tut, it isn't too drawn out. Only thing I might suggest is break up the sentences, like

Constant: ....

Variable: .....

Random: ....

It would make it longer on the page, but less cluttered and easier to read.

Nice tutorial *thumbs up*
Refrain from calculating your juvenile poultry prior to the incubation process's execution.

pokeball :)OfflineMale
********
Cheese
Rep:
Level 95
?
Very nice. =D
Watch out for: HaloOfTheSun

*
? ? ? ? ? ? ? ? ? The nice kind of alien~
Rep:
Level 92
Martian - Occasionally kind

*
A blessing
Rep:
Level 91
<3 Back.
AT LAST!

*Kneels down before 'modern algebra'*

Thank you so much! My request has finally been answered! :D

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
AT LAST!

*Kneels down before 'modern algebra'*

Thank you so much! My request has finally been answered! :D

lol

No problem, it was a great idea. You may rise.

And here is part I. Part II has no deadline yet, but I have some work to do this week and next, so maybe sometime soon after that.

http://rmrk.net/index.php/topic,14229.0.html