So, I'm using a view range script for my game, and I was wondering how to do the following:
The script calls a method like so:
$view_range_enemies_view(a, b, c, d, e)
Where:
a = event_id (the monster's ID)
b = the view range in tiles
c = switch thrown when player is within view range
d = self switch thrown when player is within view range
e = whether impassable tiles are taken into account (block enemy view)
Here's an example:
$view_range_enemies_view(4, 5, nil, 'A', true)
However, I use a lot of these script calls in the enemy event and I'm going to make a lot of enemy events. Instead of having to go through each page for each event and type in the enemy's event ID for each script call, I'd like to be able to set some sort of variable that will do that for me.
I tried PK8's Self Variables script to do that. That does the following:
self_variable(variable_id, value, operation(i.e set, add, etc.))
And to call the variable, you use: self_variable(variable_id) in a call script.
So I tried this:
self_variable('monster', 4, 0) #set variable to monster's ID which is 4
$view_range_enemies_view(self_variable('monster'), 5, nil, 'A', true)
And I get an error telling me:
Script 'Self Variables' line 127: NoMethodError occurred
undefined method for '[]=' for nil:NilClass
That points to the following line in the script:
class Interpreter
def self_variable(id, value = nil, oper = nil)
if @event_id > 0
key = [@map_id, @event_id, id]
if value != nil
case oper
when nil, 0, 'equal', 'set', '=' # Setting
$game_self_variables[key] = value <------------------THIS LINE
when 1, 'add', '+' # Adding
$game_self_variables[key] += value
when 2, 'sub', 'subtract', '-' # Subtracting
$game_self_variables[key] -= value
when 3, 'mul', 'multiply', 'x', '*' # Multiplying
$game_self_variables[key] *= value
when 4, 'div', 'divide', '/' # Dividing
$game_self_variables[key] /= value if value != 0
when 5, 'mod', 'modular', '%' # Modulating
$game_self_variables[key] %= value if value != 0
end
else
return $game_self_variables[key]
end
if value != nil
$game_map.need_refresh = true
return true
end
end
end
end
I have a feeling it's just the syntax I'm messing up on. Any ideas?