The RPG Maker Resource Kit

RMRK RPG Maker Creation => Requests => Script Request => Topic started by: shintashi on June 12, 2010, 02:58:56 AM

Title: How do I stick a variable in the script brackets?
Post by: shintashi on June 12, 2010, 02:58:56 AM
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]

Title: Re: How do I stick a variable in the script brackets?
Post by: cozziekuns on June 12, 2010, 03:08:16 AM
Both Variable_A and Variable_B need to return something before they mean anything.
Title: Re: How do I stick a variable in the script brackets?
Post by: tSwitch on June 12, 2010, 03:22:58 AM
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
Title: Re: How do I stick a variable in the script brackets?
Post by: shintashi on June 12, 2010, 04:15:17 AM
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]

Title: Re: How do I stick a variable in the script brackets?
Post by: cozziekuns on June 12, 2010, 04:31:07 AM
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]
Title: Re: How do I stick a variable in the script brackets?
Post by: 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.
Title: Re: How do I stick a variable in the script brackets?
Post by: tSwitch on June 12, 2010, 05:36:05 AM
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.
Title: Re: How do I stick a variable in the script brackets?
Post by: modern algebra on June 12, 2010, 12:03:27 PM
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.
Title: Re: How do I stick a variable in the script brackets?
Post by: shintashi on June 12, 2010, 04:32:01 PM
M.A.

a = $game_variables[2]
b = $data_enemies[1]
$game_variables[11] =
b.element_ranks[a]


:)