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.

My script is getting to complicated then it should be.

Dko

Member

Hiyas again. Currently my brain is dieing on me and I need some help. Ive been working on a script to give my game character one extra stat(like str) and be able to edit it in game. So far though I have the extra stat added with your guys help and im now trying to make the system in debug to edit it. So far though what has complicated matters is I now basically have two copies of the data base. The one that rpgmaker xp's editor uses and my personal one that has my extra stat. Which leaves me to have to figure out how to have it so when the first one is edited I can save the changes to the second file and still have any changes I made to my extra stat untouched. This having two data base files to deal with is the pits. I really wish I could just work with the original to do all this. Ive looked at Sephs virtual Database script but it just doesn't seam to work the way I would hope. Does anyone have any ideas for me?
 

OS

Sponsor

I believe you should right down any changes that need to be made to your database after changing your in-game version. It takes more time, but you still have the benefit of seeing changes to the database while you play. Sorry that this isn't what you wanted to hear, but it's the only way I can think of...

Peace!

~Broken
 

Dko

Member

currently what ive done so far is this Spehiroth. Though as you probably can tell it doesn't save any changes ive made to the new 8th parameter of every character.
Code:
class Scene_Title
  #--------------------------------------------------------------------------
  # * Main Database
  #--------------------------------------------------------------------------
  alias dkos_main_database main_database
  def main_database
    dkos_main_database
    $data_actors.each {|actor| actor.setup_stats if actor != nil}
  end
end

module RPG
  class Actor
    def setup_stats
      # Setup New Table
      parameters = Table.new(7, 100)
      # Run Through and Copy From Parameters
      @parameters.ysize.times do |y|
        @parameters.xsize.times do |x|
          parameters[x, y] = @parameters[x, y]
        end
      end
      # Setup new parameters
      @parameters = parameters
    end
  end
end
I just wish I had the money to get a book on Ruby. I have a hard time absorbing information off a computer screen for some reason.
 
Ouch. You are doing that the hard way, causing way too much work on your part. Trust me.

I strongly suggest you read the tutorial. It goes through this pretty well I think.

Code:
class Game_Actor < Game_Battler
  New_Stat = {}
  def stat_name
    if New_Stat.has_key?(@id)
      return New_Stat[@id]
    else
      return default
    end
  end
end

Something as basic as that is much more efficient and compatable then adding attributes to the @parameters table. What if someone else wants to add attributes to the table? Then something isn't going to work, which is why both should do it. :p
 

Dko

Member

I guess I have too. I just wanted something consistent with what they already had. The thing is though I doubt anyone else will be working on this but me. BTW what does has_key? do?
 
The has_key? is a method in the Hash class. A Hash is Array with different indexing system.

Array uses a counting system for indexes, 0, 1, 2, 3, ... x
Hash uses objects for index. key/index => value

Like so:
Code:
array = [obj_1, obj_2, obj_3, ..., obj_x]
hash = { 0 => obj_1, 1 => obj_2, 2 => obj_3, ... x => obj_x + 1 }

hash = { key/index => value, ... }

Remember, any object can be the key or value and hashes have no order though.
 

Dko

Member

Ok im trying to do it this way. But I don't want a constant as I want to be able to change what the variable holds in game with the debug menu Im working on. But im having problems with this.
Code:
class Game_Actor < Game_Battler
  
  @stam = {}
    
  def stam
    if @stam.has_key?(@id)
      return @stam[@id]
    else
      return default
    end
  end
  
  def stam=(new)
    @stam = new
  end
  
end
I get an error saying no method error for stam. What could be wrong?
 
Data Actors doesn't hold the stam variable. If you want, you can put your method in the RPG::Actor class, then have a method in Game_Actor that reads the variables from Data Actors, but this isn't needed.

Use $game_actors[actor_id].stam
 

Dko

Member

Im just about ready to give up. I made changes like you all suggested but now my debug menu doesn't work right. Nothing shows up on the right side (where the stam variable is saposta display) Every time I seam to have an answer I get 20 more wuestions. I just freaking want to give any character in the data base a new stat score just like Hp or Str that I can set for every level in debug mode. I wish this was C++ then I might be able to figure out what im doing wrong. Ive heard things about compatibility and frankly I don't care about that. I just need something that works. At least with the old code I had I was displaying the variables and changing them and just had to figure out a way to save and load them. >.<
 
Stop your whining and stick it out. :p


Ok. Here's an example that you could use:

Code:
class Game_Actor < Game_Battler
  Stamina_Base_Values = {
  }
  Stamina_Increase_Values = {
  }
  def base_stamina
    if Stamina_Base_Values.has_key?(@actor_id)
      return Stamina_Base_Values[@actor_id]
    end
    return 0
  end
  def increase_stamina
    if Stamina_Increase_Values.has_key?(@actor_id)
      return Stamina_Increase_Values[@actor_id]
    end
    return 0
  end
  def stamina
    b, i = base_stamina, increase_stamina
    return b + i * self.level
  end
end

That will let you basically set a point-slope formula for a stat stamina. The formula is basic : base_vale + increase_value * level.

You set them up with actor_id => value in the hash.
 

Dko

Member

I don't need a formula. I need to be able to save the values I set in game. This is because Im not the only person making this game. Im just doing the battle system. I have to make it so someone can change the stam values to what ever they wish for each character with out coding experience. Im sorry if I was getting pissy. Just the amount of time ive spent on this and not the actual battle system is nerve wracking.
Also ive change my code back to the old way I had it. I know it works for the most part. But like I said I need a way to save what changes they make.

Ok im actually trying it your way again as I thought of something. But im not sure what I need to do. Weather I don't get the jist of how this is saposta work or Something else ive done wrong.
Ive changed it like this
Code:
class Game_Actor < Game_Battler
  
  @stam = {}
  @stam.default = 1
    
  def stam
    if @stam != nil
      if @stam.has_key?(@id)
        return @stam[@id]
      else
        return default
      end
    end
    
  end
  
  def stam=(new)
    @stam = new
  end
  
end
and im calling it like this.
status = $game_actors[i+1].stam[@char_lvl].to.s
But I seam to get the error Undefined method [] for nil class.
 
Your coding is just plain wrong, on quite a few levels. I am not trying to be mean, but it seems like you are missing the basic OO elements.

Code:
  @stam = {}
  @stam.default = 1

You are initializing your @stam variable as a hash, then you are trying to access some instance of your @stam variable, which is just all wrong. Maybe @stam_default, but .default is trying to access a method within the class Hash which will result in an error.

Code:
  def stam
    if @stam != nil
      if @stam.has_key?(@id)
        return @stam[@id]
      else
        return default
      end
    end
    
  end

@stam should never be nil. This is why you don't want to allow access to this variable (see below). If you are intending to use your @stam_default variable, replace default with @stam_default.

Code:
  def stam=(new)
    @stam = new
  end

This is not what you are wanting. For one, a method like this could be an attr_accessor :stam and you could leave it at that.



Here, just forgot all of that. Try this:
Code:
class Game_Actor
  Starting_Stam = {}
  attr_accessor :stam
  alias_method :settingstam_setup, :setup
  def setup(id)
    settingstam_setup(id)
    if Starting_Stam.has_key?(id)
      @stam = Starting_Stam[id]
    else
      @stam = 0
    end
  end
end

Now you can change your instance stam with <game_actor>.stam = n

It will not set for all levels though. You have to auto-set everything.



Lets break this code down :

$game_actors[i+1].stam[@char_lvl].to.s

$game_actors[i+1] will return an actor. so this part is fine.

.stam returns an interger by the way you are doing this.

So $game_actors[i+1].stam returns a number, but from there, you are trying to access some index for an integer. Just isn't going to happen.

I really don't know what to say. It seems like you are trying to do things 2 different ways without understanding how to accomplish either way, so you are ending up doing something mixed up.
 

Dko

Member

Well half of it is because I have a horrible time undersanding anyone else's code. Even if its very basic. I need to have my code work like this.
$game_actors[i+1].stam[@char_lvl].to.s not
Other wise I will have to re write a whole bunch of other code. I need to be able to have either an array or hash which holds a characters Stamina for every level. Much like @parameters in $data_actors works. Except its only the one stat.
I can NOT have the stats generated by the code. A human being needs to input them using hopefully the interface I put into the debug menu. Please understand this Seph as ive tried saying it many times.
 
Whatever. I am done here. If you can't handel yourself in a fashion decent for someone willing to help you, then don't bother asking. You need to stop throwing a fit and possibly change your code. I have given you dozens of suggestions, and you snub each of them because you don't want to change your code. I have nothing more to say.
 

Dko

Member

I wasn't having a fit in the last post. I was just saying I have certain constraints that I have to live with. I do thank you for trying to help me Seph. sorry.
EDIT: ok ive finnaly worked thru things now im not tired and grumpy. My debug menu now saves and loads my extra stats properly for the most part. Again thanks for the help and sorry.
 

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