This topic aims to aid users understand how to fully utilize this script. It assumes you've basic pointer, script call and game variable knowledge, and little scripting proficiency, but you still might gain something if you don't meet the above assumptions.

Symbols

1. <|-|>
- Reads from/writes to(binary, left to right)
2. |>-|>
- Points to without chaining(binary, left to right)
3. |>=|>
- Points to with chaining(binary, left to right)
4. =|>
- Effectively means(binary, left to right)
5. <|=|>
- Is effectively the same as(binary, left to right)


Rules

1. a |>=|> a <|=|> a |>-|> a
2. a |>=|> b <|-|> b <|=|> a |>-|> b =|> a <|-|> b
3. a |>=|> b |>-|> c =|> a |>-|> c && b |>-|> c
4. (c must be different from a) a |>=|> b |>=|> c =|> a |>=|> c && b |>=|> c
5. a |>=|> b |>=|> a =|> a |>=|> a && b |>=|> b


Theorems

1. a |>=|> b |>=|> c |>=|> b =|> a <|-|> b && b <|-|> b && c <|-|> c
Proof:
a |>=|> b |>=|> c |>=|> b =|> a |>=|> b && b |>=|> c |>=|> b (Rule 4)
=|> a |>=|> b && b |>=|> b && c |>=|> c (Rule 5)
=|> a |>=|> b && b |>-|> b && c |>-|> c (Rule 1)
=|> a |>-|> b && b |>-|> b && c |>-|> c (Rule 3)
=|> a <|-|> b && b <|-|> b && c <|-|> c (Rule 2)


Applications

1. Doubly circular linked list
From Theorem 1:
- a1 |>=|> a2 |>=|> a3 |>=|> ... |>=|> an |>=|> ai =|> a1 <|-|> ai
What a1 reads from/writes to can be controlled by controlling what an points to without changing any other pointer record, making implementing doubly circular linked lists feasible.
To be more effective, efficient and simple, always keep track of the ids of the variable being the 1st, last and currently pointed elements respectively(currently pointed means being actually read from/written to).
In the below setup, head_var_id, cur_var_id and tail_var_id keeps track of the ids of the variable being the 1st, last and currently pointed elements respectively.
a) Setting up the list
- Use this script call:

cur_var_id = head_var_id
(list_length - 1).times { |index|
  $game_variables.var_pointers[cur_var_id] = [var_id_list[index], true]
  cur_var_id = $game_variables.var_pointers[cur_var_id][0]
}
tail_var_id = cur_var_id
$game_variables.var_pointers[tail_var_id] = [head_var_id, true]
b) Accessing the currently pointed element
- Use this script call:
$game_variables[head_var_id] # Using $game_variables[cur_var_id] also works
c) Pointing to the next i element
- Use this script call:
$game_variables.var_pointers[tail_var_id][0] = head_var_id
i.times { cur_var_id = $game_variables.var_pointers[cur_var_id][0] }
$game_variables.var_pointers[tail_var_id][0] = cur_var_id
d) Pointing to the previous i element
- Use this script call:
$game_variables.var_pointers[tail_var_id][0] = head_var_id
i.times { cur_var_id = $game_variables.var_pointers.index([cur_var_id, true]) }
$game_variables.var_pointers[tail_var_id][0] = cur_var_id
e) Adding a new element as the next element of the currently pointed element
- Use this script call:
next_var_id = $game_variables.var_pointers[cur_var_id][0]
$game_variables.var_pointers[cur_var_id][0] = new_var_id
$game_variables.var_pointers[new_var_id] = [next_var_id, true]
f) Removing the next element of the currently pointed element
- Use this script call:
old_var_id = $game_variables.var_pointers[cur_var_id][0]
next_var_id = $game_variables.var_pointers[old_var_id][0]
$game_variables.var_pointers[cur_var_id][0] = next_var_id
$game_variables.var_pointers[old_var_id][0] = 0
g) Adding an element as the new 1st element of the list
- Use this script call:
$game_variables.var_pointers[new_var_id] = [head_var_id, true]
head_var_id = new_var_id
$game_variables.var_pointers[tail_var_id][0] = head_var_id
h) Adding an element as the new last element of the list
- Use this script call:
$game_variables.var_pointers[tail_var_id] = [new_var_id, true]
tail_var_id = new_var_id
$game_variables.var_pointers[tail_var_id][0] = head_var_id
i) Removing the 1st element of the list
- Use this script call:
new_head_var_id = $game_variables.var_pointers[head_var_id][0]
$game_variables.var_pointers[head_var_id][0] = 0
head_var_id = new_head_var_id
$game_variables.var_pointers[tail_var_id][0] = head_var_id
j) Removing the last element of the list
- Use this script call:
new_tail_var_id = $game_variables.var_pointers.index([tail_var_id, true])
$game_variables.var_pointers[tail_var_id][0] = 0
tail_var_id = new_tail_var_id
$game_variables.var_pointers[tail_var_id][0] = head_var_id
k) Shifting the 1st and last element of the list to their next i elements:
- Use this script call:
$game_variables.var_pointers[tail_var_id][0] = head_var_id
i.times { tail_var_id = $game_variables.var_pointers[tail_var_id][0] }
head_var_id = $game_variables.var_pointers[tail_var_id][0]
l) Shifting the 1st and last element of the list to their previous i elements:
- Use this script call:
$game_variables.var_pointers[tail_var_id][0] = head_var_id
i.times { tail_var_id = $game_variables.var_pointers.index([tail_var_id, true]) }
head_var_id = $game_variables.var_pointers[tail_var_id][0]

Share


About the Author

No Comments

Quick Reply

Guest

Enter a username

Security check: What is 8 plus 2?