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:
$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:
$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:
$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?
$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:
$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:
$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:
$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:
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