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.

Arrays, feeling quite silly

I'm absolutely stumped :|

Ok so $game_netplayer is like so:

Code:
  def initialize

    super

    @map_id = 0

    @name = ""

    @level = -1

    @netid = -1

    @hp = -1

    @sp = -1

    @username = ""

    @move_tom = true

    $game_temp.spriteset_refresh = true

    @x = 0

    @y = 0

  end

Where $game_netplayer = Game_Netplayer.new


I am completely stumped as how to do the following:


For the netplayer that has the name "wyatt" change the hp to be 500.



:| Anyone care to remind an old fool?
 
what i would do :p to easily get players from their name, is a class hash, that is filled when a netplayer is created... then you would just need a small method to get the player you want from his name.

like in this example:
[rgss] 
class MyClass
@@myHash = {}
 
  def initialize
    do_whatever
 
    @@myHash[myidentifier.to_sym] = self
  end
 
  def self.[](id)
    @@myHash[id]
  end
end
 
[/rgss]

:p then you can simply call

get_me = MyClass[me.to_sym]

( i like to use symbols cause they're unique and fast (instead of strings))

Adding this in the netplayer class, with the name as an identifier, would help you i think.
 
well you can but it's basically ending up with a complicated hash..
you'll need to parse the array testing each player for their name... and return the player if his name matches...not really worth it i think...
 

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