Take the following script for example:
$game_variables[11] =
$data_enemies[1].element_ranks[1] - 3
p $game_variables[11]what do I have to do to have something like the following meta code working?
Quote from: fake_codedefine variable_A
n = $game_variables[2]
end
define variable_B
n = $game_variables[3]
end
$game_variables[11] = $data_enemies[variable_A].element_ranks[variable_B] - 3
p $game_variables[11]
Both Variable_A and Variable_B need to return something before they mean anything.
if you want to use methods that way, they'd have to look something like
def var_A
return $game_variables[#]
end
alternatively, you could just
$game_variables[11] = $data_enemies[$game_variables[A]].element_ranks[$game_variables[B]] - 3
I get an error fixnum cant pass variable
@>Control Variables: [0002:Choice] = 2
@>Script: def var_A
: :return $game_variables[2]
: :end
: :
: :$game_variables[11] =
: :$data_enemies[1].element_ranks
: :[$game_variables[var_A]] - 3
: :
: :p $game_variables[11]
The script box wasn't big enough to fit $data_enemies[1].element_ranks[$game_variables[var_A]] - 3 on one line. Go figure.
Try this:
def a
var = $game_variables[2]
return var
end
b = $data_enemies[1]
$game_variables[11] =
b.element_ranks[$game_variables[a]]
p $game_variables[11]
that worked perfectly. i wish there was a way of knowing when it's a space problem and an actual coding problem. Seems like something you just have to pick up over time.
Quote from: shintashi on June 12, 2010, 05:31:09 AM
that worked perfectly. i wish there was a way of knowing when it's a space problem and an actual coding problem. Seems like something you just have to pick up over time.
yeah that's weird I've never run across that before.
I really don't know why you are defining a method to retrieve a variable in the same script command that you are using it.
Why not just:
a = $game_variables[2]
b = $data_enemies[1]
$game_variables[11] =
b.element_ranks[$game_variables[a]]
In any case, space problems are annoying in the event command box. It would make so much more sense for them to give you unlimited horizontal room. Generally, though, try to fit whatever you would normally put on one line on one line through the use of local variables and you'll be fine. That's the best way to avoid those problems.
M.A.
a = $game_variables[2]
b = $data_enemies[1]
$game_variables[11] =
b.element_ranks[a]
:)