RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
How do I stick a variable in the script brackets?

0 Members and 1 Guest are viewing this topic.

***
Rep:
Level 82
We learn by living...
Take the following script for example:

Code: [Select]
$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_code
define 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]


*****
Rep:
Level 84
This text is way too personal.
Bronze - GIAW 11 (Hard)Silver - GIAW Halloween
Both Variable_A and Variable_B need to return something before they mean anything.
« Last Edit: June 12, 2010, 03:16:24 AM by cozziekuns »

********
Hungry
Rep:
Level 96
Mawbeast
2013 Best ArtistParticipant - GIAW 11Secret Santa 2013 ParticipantFor the great victory in the Breakfast War.2012 Best Game Creator (Non-RM Programs)~Bronze - GIAW 9Project of the Month winner for December 2009Project of the Month winner for August 20082011 Best Game Creator (Non RM)Gold - GIAW Halloween
if you want to use methods that way, they'd have to look something like

Code: [Select]
def var_A
return $game_variables[#]
end

alternatively, you could just

Code: [Select]
$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

***
Rep:
Level 82
We learn by living...
I get an error fixnum cant pass variable

Code: [Select]
@>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]


*****
Rep:
Level 84
This text is way too personal.
Bronze - GIAW 11 (Hard)Silver - GIAW Halloween
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:

Code: [Select]
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]

***
Rep:
Level 82
We learn by living...
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.

********
Hungry
Rep:
Level 96
Mawbeast
2013 Best ArtistParticipant - GIAW 11Secret Santa 2013 ParticipantFor the great victory in the Breakfast War.2012 Best Game Creator (Non-RM Programs)~Bronze - GIAW 9Project of the Month winner for December 2009Project of the Month winner for August 20082011 Best Game Creator (Non RM)Gold - GIAW Halloween
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

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best RPG Maker User (Scripting)2011 Best Use of Avatar and Signature Space2010 Most Mature Member2010 Favourite Staff Member
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:

Code: [Select]
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.

***
Rep:
Level 82
We learn by living...
M.A.
Code: [Select]
a = $game_variables[2]
b = $data_enemies[1]
$game_variables[11] =
b.element_ranks[a]

:)