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.
pointer_to_variable scripting

0 Members and 1 Guest are viewing this topic.

***
Rep:
Level 83
*edit* I found a script that does all this, but I would appreciate some help learning how to use the script.  The script is DoubleX RMVXA Variable Pointers.  I'm keeping this message intact in case anyone gains anything from it. *edit*

Hi all.

I'm ready to move my game-making out of the stone age of R2K and into VXAce, but there is one thing that VXAce sorely lacks.  Does anybody remember the "pointer_to_variable" feature of R2K and R2K3 (called "variab: Variable No." in my version)?  It allowed you to reference the value within a variable by using a second variable as a pointer, and it went something like this...

var_a SET *pointer_var_b*
-or-
*pointer var_a* SET var_b

I have a limited vocabulary for exactly what this function does and why it is so important, but in short it makes referencing massive quantities of variables very simple. 

EX:

var_3 SET 90
var_2 SET 3
var_1 SET *pointer_var_2*

This event would set "var_1" equal to 90 because "pointer_var_2" is treating the number it is set to (3) as a variable (var_3), and then looking at what value is in that variable (var_3).

Make sense?

Not really?

Why not just set "var_1" = "var_3," you may be asking.  Because this feature lets you reference long lists of variables using only a single, clean loop with minimal programming.  It looks like this:

batch var_3 - var_102 SET 'x'
var_2 SET 3
LABEL_1
var_1 SET *pointer_var_2*
FORK:
   IF var_1 > 0
      "true"
   THEN
      "false"
end
   IF var_2 < 102
      var_2 + 1
      GO_TO: LABEL_1
end


In the above example, I am able to receive a "true" or "false" value from 99 consecutive variables very rapidly and with very little eventing. 
"var_2 + 1" makes it so that "var_1 SET *pointer_var_2*" checks the value of a new variable every loop ("var_3" the first loop, "var_4" the next loop, etc.). 

Anybody interested and willing to script such a feature into VXAce?  In can show plenty of my work if you need proof of my eventing/game-making skills.

Thanks for reading!
« Last Edit: July 06, 2015, 10:14:45 PM by flapbat »

***
Scripter
Rep:
Level 36
Just noticed this topic(even though I should've noticed this a long time ago). This might help:
DoubleX RMVXA Variable Pointers Tutorial
If you get what those symbols means and how to use those rules, using the script shouldn't be too hard  :)

***
Rep:
Level 83
Thank you, DoubleX.  I'll try making sense of the symbols.  And thanks for writing the script!

*
A-pow 2015
Rep:
Level 81
2014 Best RPG Maker User - GraphicsFor frequently finding and reporting spam and spam bots2013 Most Unsung MemberSecret Santa 2013 ParticipantFor taking arms in the name of your breakfast.How can I help you? :Da^2 + b^2 = c^2Secret Santa 2012 ParticipantSilver - GIAW 10Silver - GIAW 9Bronze - GIAW HalloweenGold - Game In A Week VII
Wouldn't it be easier to just use script calls?


One that I've learned about recently is "$game_variables[]". It returns the value of the variable number in the brackets. It doesn't sound too impressive on it's own, as there's already a way to change variables with eventing, but there are some neat things that you can do with it.

For example, in RM2k3, there was an option to use "variable references". Basically, this would take the value inside a variable and return the variable of the number that matches the first variable's value.

To do this, you'd use a script call that looks like this:

$game_variables[$game_variables[111]] = 5

This probably seems a little complicated, so let's simplify it a little. Let's assume that variable 111 is equal to 10.
This script call would then be "$game_variables[10] = 5 ". So now variable 10 is equal to 5. Whatever value is in 111 would be the new variable number.

You can also add (+=), subtract(-=), multiply(*=), divide(/=), and mod(%=) variables. This could be useful if you have a lot of variables you want to modify, but that aren't in consecutive order.

« Last Edit: July 20, 2015, 08:56:55 PM by Acolyte »

***
Scripter
Rep:
Level 36
Wouldn't it be easier to just use script calls?


One that I've learned about recently is "$game_variables[]". It returns the value of the variable number in the brackets. It doesn't sound too impressive on it's own, as there's already a way to change variables with eventing, but there are some neat things that you can do with it.

For example, in RM2k3, there was an option to use "variable references". Basically, this would take the value inside a variable and return the variable of the number that matches the first variable's value.

To do this, you'd use a script call that looks like this:

$game_variables[$game_variables[111]] = 5

This probably seems a little complicated, so let's simplify it a little. Let's assume that variable 111 is equal to 10.
This script call would then be "$game_variables[10] = 5 ". So now variable 10 is equal to 5. Whatever value is in 111 would be the new variable number.

You can also add (+=), subtract(-=), multiply(*=), divide(/=), and mod(%=) variables. This could be useful if you have a lot of variables you want to modify, but that aren't in consecutive order.

It depends on what the op wants.
If he/she doesn't want to play with pointers to pointers to pointers... thing, then script calls will just be easier.
For instance:
Code: [Select]
$game_variables[$game_variables[ptr_id]] # Reads a game variable by dereferencing the pointer with id ptr_id
$game_variables[$game_variables[ptr_id]] = var # Sets a game variable as var by dereferencing the pointer with id ptr_id
$game_variables[ptr_id] # Reads the variable id the pointer points to
$game_variables[ptr_id] = var_id # Sets the variable id the pointer points to as var_id
ptr_id is the pointer id, $game_variables[ptr_id] is the pointer, and $game_variables[$game_variables[ptr_id]] is the variable that pointer points to.
To play with pointers to pointers:
Code: [Select]
$game_variables[pptr_id] # Reads what pointer the pointer to pointer points to
$game_variables[pptr_id] = ptr_id # Sets the pointer to pointer to point to the pointer with id ptr_id
$game_variables[$game_variables[pptr_id]] # Reads what variable id the pointer points to by dereferencing the pointer to pointer
$game_variables[$game_variables[pptr_id]] = var_id # Sets the pointer with id ptr_id to point to variable with id var_id by dereferencing the pointer to pointer
$game_variables[$game_variables[$game_variables[pptr_id]]] # Reads the value of the variable with id var_id by dereferencing the pointer to pointer twice
$game_variables[$game_variables[$game_variables[pptr_id]]] = var # Sets the value of the variable with id var_id as var by dereferencing the pointer to pointer twice
Now by changing $game_variables[pptr_id], what the variable id the pointer with ptr_id points to can be changed easily.
Although pointers to pointers to pointers... are rarely used(although pointers to pointers might still be a bit common), if many levels of chained pointing and dereferencing is what the op wants, then doing so using script calls alone can be really, really painful. In this case the variable pointers script might help :)
« Last Edit: July 21, 2015, 04:10:57 AM by DoubleX »

*
A-pow 2015
Rep:
Level 81
2014 Best RPG Maker User - GraphicsFor frequently finding and reporting spam and spam bots2013 Most Unsung MemberSecret Santa 2013 ParticipantFor taking arms in the name of your breakfast.How can I help you? :Da^2 + b^2 = c^2Secret Santa 2012 ParticipantSilver - GIAW 10Silver - GIAW 9Bronze - GIAW HalloweenGold - Game In A Week VII
You have a good point. I guess I didn't think about using pointers pointing to pointers pointing to pointers. Just thinking about it makes my head hurt. :irock2:

***
Rep:
Level 83

It depends on what the op wants.
If he/she doesn't want to play with pointers to pointers to pointers... thing, then script calls will just be easier.
For instance:
Code: [Select]
$game_variables[$game_variables[ptr_id]] # Reads a game variable by dereferencing the pointer with id ptr_id
$game_variables[$game_variables[ptr_id]] = var # Sets a game variable as var by dereferencing the pointer with id ptr_id
$game_variables[ptr_id] # Reads the variable id the pointer points to
$game_variables[ptr_id] = var_id # Sets the variable id the pointer points to as var_id
ptr_id is the pointer id, $game_variables[ptr_id] is the pointer, and $game_variables[$game_variables[ptr_id]] is the variable that pointer points to.
To play with pointers to pointers:
Code: [Select]
$game_variables[pptr_id] # Reads what pointer the pointer to pointer points to
$game_variables[pptr_id] = ptr_id # Sets the pointer to pointer to point to the pointer with id ptr_id
$game_variables[$game_variables[pptr_id]] # Reads what variable id the pointer points to by dereferencing the pointer to pointer
$game_variables[$game_variables[pptr_id]] = var_id # Sets the pointer with id ptr_id to point to variable with id var_id by dereferencing the pointer to pointer
$game_variables[$game_variables[$game_variables[pptr_id]]] # Reads the value of the variable with id var_id by dereferencing the pointer to pointer twice
$game_variables[$game_variables[$game_variables[pptr_id]]] = var # Sets the value of the variable with id var_id as var by dereferencing the pointer to pointer twice
Now by changing $game_variables[pptr_id], what the variable id the pointer with ptr_id points to can be changed easily.
Although pointers to pointers to pointers... are rarely used(although pointers to pointers might still be a bit common), if many levels of chained pointing and dereferencing is what the op wants, then doing so using script calls alone can be really, really painful. In this case the variable pointers script might help :)

This is all awesome stuff.  Thanks to both of you.  All I am looking to do is check the value of a variable that is pointed to, then modify the variable that is pointed to, and finally increment the pointer variable to point to the next $game_variables.

So let me see if I understand this correctly: 

Code: [Select]
$game_variables[$game_variables[ptr_id[2]]] # Would this read a game variable by dereferencing the pointer with id ptr_id[2]?
$game_variables[$game_variables[ptr_id[2]]] = $game_variables[3] # Would this set $game_variables[3] = the pointer with ptr_id[2]?
$game_variables[$game_variables[ptr_id[2]]] += 1  # Would this increment ptr_id[2] by +1, causing it to point to the next $game_variables?

I'm sure I'm not doing this right, but thanks for your understanding.  How do I define ptr_id and pptr_id?

***
Scripter
Rep:
Level 36

It depends on what the op wants.
If he/she doesn't want to play with pointers to pointers to pointers... thing, then script calls will just be easier.
For instance:
Code: [Select]
$game_variables[$game_variables[ptr_id]] # Reads a game variable by dereferencing the pointer with id ptr_id
$game_variables[$game_variables[ptr_id]] = var # Sets a game variable as var by dereferencing the pointer with id ptr_id
$game_variables[ptr_id] # Reads the variable id the pointer points to
$game_variables[ptr_id] = var_id # Sets the variable id the pointer points to as var_id
ptr_id is the pointer id, $game_variables[ptr_id] is the pointer, and $game_variables[$game_variables[ptr_id]] is the variable that pointer points to.
To play with pointers to pointers:
Code: [Select]
$game_variables[pptr_id] # Reads what pointer the pointer to pointer points to
$game_variables[pptr_id] = ptr_id # Sets the pointer to pointer to point to the pointer with id ptr_id
$game_variables[$game_variables[pptr_id]] # Reads what variable id the pointer points to by dereferencing the pointer to pointer
$game_variables[$game_variables[pptr_id]] = var_id # Sets the pointer with id ptr_id to point to variable with id var_id by dereferencing the pointer to pointer
$game_variables[$game_variables[$game_variables[pptr_id]]] # Reads the value of the variable with id var_id by dereferencing the pointer to pointer twice
$game_variables[$game_variables[$game_variables[pptr_id]]] = var # Sets the value of the variable with id var_id as var by dereferencing the pointer to pointer twice
Now by changing $game_variables[pptr_id], what the variable id the pointer with ptr_id points to can be changed easily.
Although pointers to pointers to pointers... are rarely used(although pointers to pointers might still be a bit common), if many levels of chained pointing and dereferencing is what the op wants, then doing so using script calls alone can be really, really painful. In this case the variable pointers script might help :)

This is all awesome stuff.  Thanks to both of you.  All I am looking to do is check the value of a variable that is pointed to, then modify the variable that is pointed to, and finally increment the pointer variable to point to the next $game_variables.

So let me see if I understand this correctly: 

Code: [Select]
$game_variables[$game_variables[ptr_id[2]]] # Would this read a game variable by dereferencing the pointer with id ptr_id[2]?
$game_variables[$game_variables[ptr_id[2]]] = $game_variables[3] # Would this set $game_variables[3] = the pointer with ptr_id[2]?
$game_variables[$game_variables[ptr_id[2]]] += 1  # Would this increment ptr_id[2] by +1, causing it to point to the next $game_variables?

I'm sure I'm not doing this right, but thanks for your understanding.  How do I define ptr_id and pptr_id?
Code: [Select]
$game_variables[$game_variables[ptr_id[2]]] # Yes, it reads the value of the variable pointed by the variable with id ptr_id[2]
$game_variables[$game_variables[ptr_id[2]]] = $game_variables[3] # No, this sets the value of what $game_variables[ptr_id[2]] points to as that of $game_variables[3]
$game_variables[$game_variables[ptr_id[2]]] += 1 # No, this adds the value of the variable pointed by the variable with id ptr_id[2] by 1

A pointer is just a special type of variable. In terms of $game_variables, a pointer is a variable that stores the id of other variables, and that pointer itself has an id that can be stored by another pointer, which is a pointer by pointer. Likewise, a pointer to pointer to pointer to pointer stores the id of other pointers to pointers, and so on.
A variable is said to be referenced by a pointer if that pointer stores the id of that variable; A variable is said to be dereferenced by a pointer if the value of that variable is read via that pointer.

To check the value of a variable that is pointed by a pointer:
Code: [Select]
$game_variables[$game_variables[ptr_id]] # $game_variables[ptr_id] is the pointer of the variable whose value's checked, and ptr_id is the id of that pointer
To modify the variable that's pointed by a pointer:
Code: [Select]
$game_variables[$game_variables[ptr_id]] = var # $game_variables[ptr_id] is the pointer of the variable whose value's modified, and ptr_id is the id of that pointer
To change what variable id a pointer points to:
Code: [Select]
$game_variables[ptr_id] = var_id # $game_variables[ptr_id] now points to the variable with var_id

Example:
Say you organized variables by batches. Each batch serves different purpose, and is managed by tracking the smallest variable id and the number of variables. Now you can use pointers to do the job:
Code: [Select]
groups = {
  :group_1_name => [group_1_smallest_var_id, group_1_var_num],
  :group_2_name => [group_2_smallest_var_id, group_2_var_num],
  :group_3_name => [group_3_smallest_var_id, group_3_var_num],
  :group_n_name => [group_n_smallest_var_id, group_n_var_num]
}
$game_variables[ptr_id] = groups[:group_i_name][0]
while conditions($game_variables[$game_variables[ptr_id]])
  actions($game_variables[$game_variables[ptr_id]])
  $game_variables[ptr_id] += offsets
end
« Last Edit: July 22, 2015, 04:06:58 PM by DoubleX »

***
Rep:
Level 83
Grrr.....

Totally necroposting, but I wanted to say thank you for trying to help.  I have tried many times and simply cannot figure out what to do to make this basic thing work.  So, looks like I'll stick to eventing within what the maker is capable of.  But again, thanks.