Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

array call function? [RESOLVED]

1) is there a way i can call a different array based on a variable?

for instance: I have 4 arrays:

Aluxes = [1,2,3,4]
Basil = [5,6,7,8]
Cyris = [9,10,11,12]
Dorothy = [13,14,15,16]

how can tell the game to call a different array based on the character in question? (i.e. @actor_name[2] or sumthin)

2) if this is possible, can i have it call it more like this?:

Aluxes_stats = [1,2,3,4]
Basil_stats = [5,6,7,8]
Cyris_stats = [9,10,11,12]
Dorothy_stats = [13,14,15,16]

and tell the game to call a different array based on the character in question with _stats added? (i.e. @actor_name+"_stats"[4])???
 

OS

Sponsor

I am not exactly sure what you mean, but I think it would be easier to do this:
Code:
actor_stats = [actor]
if actor == $game_actors[2]
   actor_stats.push(1)
   actor_stats.push(2)
   actor_stats.push(3)
   actor_stats.push(4)
elsif #etc.

That way you can check for the actor in question, while giving them their stats. I'm sorry if this is not what you meant.

Also, in the bottom of your post you say:
@actor_name+"_stats"[4]

That doesn't appear to make sense, but I would like to point out most of all that you put [4] when your arrays all end at 3. Didn't know if you noticed.

As I said before, sorry if this is not what you meant exactly. I wrote this under the assumption that you wanted to create a variable to be used throughout a script. This method will shorten your code considerably (instead of checking for which variable you are using, you just use the actor variable loaded into index 0). Peace!
 
o boy...this is rly hard 2 explain

ok heres wat im trying to accomplish: im creating a whole bunch of values, flags, etc. based on an actor's class from scratch. Since there are so many, (15!) I want to use arrays instead of an
ENORMOUS system of 'if' 'else' functions (too many classes, too) and 16 lines of renewed variables. So i.e. a fighter and a mage have different stat caps. Rather than coding

Code:
if @actor_class_id == 1
  str_cap = 10
  dex_cap = 15
  agi_cap = 22
  .........
else
  if @actor_class_id == 2
    str_cap = 30
so on and so forth

i want it to look for an array of stat cap variables based on class.
so more along the lines of:

Code:
fighter_caps = [30,20,etc]
mage_caps = [10,15,etc]

str_cap = #the classes str cap in index 0 at the classes caps array
 
To answer your first question, you may want to use this:
Code:
stats = {
  'Aluxes' => [1,2,3,4],
  'Basil' => [5,6,7,8],
  'Cyris' => [9,10,11,12],
  'Dorothy' => [13,14,15,16] 
}

So you call it this way:
Code:
stats['Cyris'][3] # 12


About second question.. can you elaborate a bit more?
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top