[RM2K] USING POINTER VARIABLES
Posts
Pages:
1
I was reading some tutorials abous pointer variable on rm2k/3 and understood how works, but no one of these tutorials was clearly to me. Somebody can teach me some situations to use this kind of function?
It makes code easier to write, especially if you use custom systems, like customized item slots. It becomes much more useful the more custom systems that you're using.
Instead of using Variable Operations for every possibility of an outcome, making a huge amount of Conditionals and Variable Operations changes, you can just point to the variable that you want to change, using another variable. (But, you had to have planned to set that variable up first.)
Let's say that you have a lot of playable characters, but you don't know who is in the player's party. You can make it so that when the player chooses characters to be in the party, a certain variable is set... like, 011:Party Char 1 = 10 ("Bertrand")... 012:Party Char 2 = 4("Molly")... 013:Party Char 3 = 23("Fido")... OK.
Now, let's say that you're using a custom battle system, and you've organized your player's stats into certain variables. You've planned it so that the character ID, when multiplied by 100, matches the variable in which you're storing that character's HP.
So, character 10 (A guy named Bertrand), when you multiply 10 by 100, you get 1000. This means that Bertrand's HP is stored in variable 1000. Molly's would be stored in variable 400. Fido's HP would be stored in variable 2300.
Something bad happens to the party and you need to damage the HP of the characters.
You would construct a little loop to damage their HP, by 50 HP.
Temporary Variable A = 11
Loop
>Temporary Variable B =[[Temporary Variable A]]
>Temporary Variable B * 100
>[Temporary Variable B] - 50
>Temporary Variable A + 1
>If Temporary Variable A > 13
> Break Loop
>End
End Loop
In the above loop, Temporary Variable A points to the Party Char group of variables, which you've arranged to be variable #11, #12, and #13. It becomes a pointer for whatever values are in these variables.
Temporary Variable B then grabs the value in Temporary Variable A. In #11, it would be 10, Bertrand. Then it multiplies that number by 100 to find the variable in which you're storing Bertrand's HP. Then, it subtracts 50 from that variable. Then, it increases Temporary Variable A by 1, moving to the next Party Char variable. If the number is over 13, then that's it, there are no more Party Characters. Exit loop.
A lot of using pointers relies on how you set up the architecture of your own game. If you're using a custom system, it becomes totally up to you.
Instead of using Variable Operations for every possibility of an outcome, making a huge amount of Conditionals and Variable Operations changes, you can just point to the variable that you want to change, using another variable. (But, you had to have planned to set that variable up first.)
Let's say that you have a lot of playable characters, but you don't know who is in the player's party. You can make it so that when the player chooses characters to be in the party, a certain variable is set... like, 011:Party Char 1 = 10 ("Bertrand")... 012:Party Char 2 = 4("Molly")... 013:Party Char 3 = 23("Fido")... OK.
Now, let's say that you're using a custom battle system, and you've organized your player's stats into certain variables. You've planned it so that the character ID, when multiplied by 100, matches the variable in which you're storing that character's HP.
So, character 10 (A guy named Bertrand), when you multiply 10 by 100, you get 1000. This means that Bertrand's HP is stored in variable 1000. Molly's would be stored in variable 400. Fido's HP would be stored in variable 2300.
Something bad happens to the party and you need to damage the HP of the characters.
You would construct a little loop to damage their HP, by 50 HP.
Temporary Variable A = 11
Loop
>Temporary Variable B =[[Temporary Variable A]]
>Temporary Variable B * 100
>[Temporary Variable B] - 50
>Temporary Variable A + 1
>If Temporary Variable A > 13
> Break Loop
>End
End Loop
In the above loop, Temporary Variable A points to the Party Char group of variables, which you've arranged to be variable #11, #12, and #13. It becomes a pointer for whatever values are in these variables.
Temporary Variable B then grabs the value in Temporary Variable A. In #11, it would be 10, Bertrand. Then it multiplies that number by 100 to find the variable in which you're storing Bertrand's HP. Then, it subtracts 50 from that variable. Then, it increases Temporary Variable A by 1, moving to the next Party Char variable. If the number is over 13, then that's it, there are no more Party Characters. Exit loop.
A lot of using pointers relies on how you set up the architecture of your own game. If you're using a custom system, it becomes totally up to you.
Pages:
1