Gw Temp

Menu

Tutorial - 'Variable No. Explained' by voxvam

An item about RPGMaker 2000 posted on

Blurb

Delving into the more tougher parts of RPGmaker 2000, Variables Numbers.

Body

-----Basic Information About This Tutorial-----
Knowledge Requirements: Change Variable
Pros: You learn more of the functionality that rm2k has to offer, a more professional rm2k guru-like way to code some things. Can also help clean up code making it appear more neat and tidy.
Cons: Many have a VERY hard time understanding the concept, sometimes it's easier to do it the normal way. It is a hard concept to understand, and hard to explain, please bare with me if you want to continue.

Ever wondered what that "Variable No." thing in the Change Variable dialog box is for, you will find out here.

-----What Am I Going To Use This For-----
Well basicly this is just a little used feature that rm2k has to offer involving variables. Many high level computer languages (like c++) have something quite similar to this (pointers). This concept can be used to make many called events look more tidy, however knowledge of the theory behind this can benifit any person wanting to become a programmer. But no, you don't really need to know this at all to make a cbs, cms, etc. It's an extra.

-----Why Not Use The Easy Way-----
That is a good question. Basicly you do things this way to make you're code look cooler, and if you do it right it can make you're code easier to understand as well. The other way is not as "cool", but it is easy. It's your choice.

Opinion: If you don't understand the concept after re-reading the tutorial about 3 times, don't waste you're time unless you really really want to and have nothing better to do.

-----I Want To Give It A Shot-----
Good, at least you're willing to try, nothing wrong with that.
Well I'll try and give you some definitions then.

Pointer - In general, a pointer is like a piece of paper that tells you where to find what you are looking for.

Passing by reference - You are passing a piece of paper (pointer) that gives you directions where to find what you want, not what you want itself.

Passing by value - This means you are passing something that you want, not a piece of paper (no pointer).

-----Simple Examples-----
Change Variable, One: #23, set to 5. --> Passing by value.
Change Variable, Variable No: #3, set to 5 --> Passing by reference.

If variable #3 holds the value of 23, then variable #23 will hold the value of 5.

So variable #3 is a pointer, the value it holds (what is written on the piece of paper) is the number of the variable you are looking for.

So for rm2k, when you use a "Variable No" field, the value of that variable (the pointer) is the number of the variable you will be using. So if the pointer holds the value of 10 (if 10 is written on the piece of paper), you will be using variable number 10.


Change Variable "testPointer", set to 1
Start Cycle

Call SetVariableTo5
Change Variable "testPointer", add by 1

Fork "testPointer" = 10 Then
Break Cycle
End Fork

End Cycle

So with this example, if the called event "SetVariableTo5" changes the value of the variable that the pointer "testPointer" points to and sets it to 5, then what will happen is variable numbers 1 to 10 will all have the value 5.

Something like this would be good if you want to read the values of a bunch of variables all in a row.
Say you want to count how many items you have for a custom item menu. You could do something like this, read all the values of all the variables that are used in the custom item menu and sum the values in about 10 lines of code, rather than 1 line for each item.

-----In Review-----
Whenever you see "Variable No." something X, the value of variable X is the variable number that you will actually be using. I don't think I can state it any easier.

PS. Another good use for this would be in custom item menus specificly, especially the dynamic kind.

That's all folks.

If you have a comment/question/suggestion, please feel free to email me at voxvam@shaw.ca or catch me on aim (signon-name: voxvam).

Good luck and have fun now :)