Main Menu
  • Welcome to The RPG Maker Resource Kit.

How do I stick a variable in the script brackets?

Started by shintashi, June 12, 2010, 02:58:56 AM

0 Members and 1 Guest are viewing this topic.

shintashi

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]


cozziekuns

#1
Both Variable_A and Variable_B need to return something before they mean anything.

tSwitch

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


FCF3a A+ C- D H- M P+ R T W- Z- Sf RLCT a cmn+++ d++ e++ f h+++ iw+++ j+ p sf+
Follow my project: MBlok | Find me on: Bandcamp | Twitter | Patreon

shintashi

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]


cozziekuns

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]

shintashi

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.

tSwitch

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.


FCF3a A+ C- D H- M P+ R T W- Z- Sf RLCT a cmn+++ d++ e++ f h+++ iw+++ j+ p sf+
Follow my project: MBlok | Find me on: Bandcamp | Twitter | Patreon

modern algebra

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.

shintashi

M.A.

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


:)