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.

manipulating data question

say you had:
[rgss]class someclass < anotherclass
  attr_reader :data
  def initialize(data)
   super()
    @data = data
  end
end
[/rgss]
what would be the proper way to change the value of data?
 
Within the class, you use:
Code:
@data = 'new_value'
Outside of the class, you can't right now modify the variable, as it's only readable, not writeable. To write it, either choose attr_writer (write-only) or attr_accessor (read/write). If you do that, you change it like this:
Code:
character = Someclass.new('your_value')

p character.data #=> 'your_value'

character.data = 'new_value'

p character.data #=> 'new_value'
 
see i knew it was something simple like that i just couldnt remember, btw on our conversation earlier, i got it to make rxdata files fine, just having some issues reading them properly, i think ill have it soon, and if i dont ill ask for help. nothing like learning :)
 

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