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.

Quick Syntax Question [Resolved]

Okay, I've been looking around and can't seem to figure this out...

How do you access arrays in a certain class from a different class?

LIke... If Class1 had @array1, how could I access that array from Class2. I've tried using attr_accessor :array1 (for example, not really that), but I don't really even now how the attr_accessor works... I've just been trying to do array = Class1.array and it's not working...

...Am I making any sense?
 
Ah! Okay, it works now! Thanks!

EDIT: Actually... now I have a new problem. I've seen this done before:

Code:
 

def initialize

   @array1 = []

   @array2 = []

   for i in 0..100

      @array1[i] = []

      @array2[i] = []

   end

end

 

This is for a 'multi-demensional array' or table or whatever it's called in Ruby. However... it's not working for me even though I took the method straight from a working class and just used my own names. I'm getting an error that says that '[]=' is an undefined method.

EDIT2: Ach! Nevermind. My blindness caused that one. I fixed it. ^_^
 

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