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.

[Resolved] variable problem

Status
Not open for further replies.
So I have a money system where I've converted the gold variable into gold[], with each array element being a different currency. I have it displaying in the menu correctly, i have battles giving me gold correctly, shops, everything works fine. The system itself isn't my problem.

I use a global variable called '$goldtype', defined in class Game_system, def initialize, to determine what the currency is for each region in the game is. So when you walk between regions, a scriopt call will do $goldtype=2 to switch gold[$goldtype] from gold[1] to gold[2].

However my problem is, the game doesn't save the value of $goldtype! When I save, quit, and reload the game, $goldtype is back to its initial value every time, despite being set at 1 or 2 or 3 or whatever in game.

how do i fix this? do i need to define the global variable somewhere else? or use a different kind of variable?
 
Just make goldtype an instance of Game_System like that:

Code:
class Game_System

attr_accessor :goldtype

alias old_initialize initialize

  def initialize
    @goldtype = 0
    old_initialize
  end
end

Then just use $game_system.goldtype = integer in a call script command and gold[$game_system.goldtype].
 
Status
Not open for further replies.

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