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.

Creating a Game_*

OS

Sponsor

Hello. I am writing two scripts for my Interact Pack, Game_NPC, and Game_OBJ. Both should work similarly to Game_Actor. But I need to know a few things:

First of all, what do you think is easier for the developer of a game;
1. Creating a file for each NPC and OBJ in thier own folders in GameFolder/Data, and loading these files like Game_Actors loads the in-editor Database Actors Data.
or
2. Creating the information for the objects and npcs in a seperate script (like Game_NPCs and Game_OBJs #note the added s's). Each NPC and OBJ would be created in an array like this:
npc1 = [name, age, gender]
npc2 = [name, age, gender]
npc3 = [name, age, gender]
npc = [npc1, npc2, npc3]
Same for the OBJects. These 2 arrays (npc and obj) would be loaded into Game_NPC and Game_OBJ.

These are the only two methods of doing this that I can think of. Which one do you prefer, so I know which is more popular.

If 1. is chosen, I will need to know how to load and read text files (one line at a time).

And I need to know how to assign variables to each individual obj and npc so that I can do this:

$game_npc[npc_id].name = "NewNameString"
name = $game_npc[npc_id].getName #returns NPC[npc_id]'s name

I am kind of confused (learning too many languages at once). At least help with the last bit about assigning variables. Thanks for any help, and Peace Out!

~Broken
 
Code:
class Foo

attr_accessor :name

	def initialize(name)
	@name = name
	end
end

#then you create a object.
obj = Foo.new("Lobosque")

and you can do the name thing now.
Sorry if it is not what you want, but its what i undestood.
 
Here is an example on how to make array classes.
Code:
class Game_Examples
  def initialize
    @data = []
  end
  def [](index)
    return @data[index]
  end
  def []=(index, object)
    @data[index] = object
  end
end
It's up to you to put what is in @data.
 

OS

Sponsor

Thanks. I need to know if this would work, then?
Code:
class Game_NPCs < NPC_Database
  NPC_COUNT = 2
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    @data = []
  end
  #--------------------------------------------------------------------------
  # * Get NPC
  #     npc_id : npc ID
  #--------------------------------------------------------------------------
  def [](npc_id)
    if npc_id > NPC_COUNT or @npcs[npc_id] == nil
      return nil
    end
    if @data[npc_id] == nil
      @data[npc_id] = Game_NPC.new(npc_id)
    end
    return @data[npc_id]
  end
end
Code:
class Game_NPC < NPC_Database
  attr_accessor :id
  attr_accessor :surname
  attr_accessor :middle
  attr_accessor :name
  attr_accessor :age #Used in same-sex marriages (Checked for oldest)
  attr_accessor :sex #gender
  attr_accessor :marriage
  attr_accessor :disp #Explained later
  attr_accessor :bounty #Explained later
  attr_accessor :lvl #used in same-sex marriages and battles (Checked for highest)
  attr_accessor :hp #used in battle
  attr_accessor :items #an array that holds up to 5 items.
  attr_accessor :clothes #an array that holds Body, Head, Hand, Feet, and Shield Equiped armour.
  attr_accessor :weapon #a variable that holds 1 weapon
 #attr_accessor :skills #an array holding any (5) skills/spells the NPC knows
 #attr_accessor :mp
 #MARRIAGE_MIN = 18 #The youngest age an NPC can be to get married
 def initialize(npc_id)
   super()
   setup(npc_id)
 end
 
 def setup(npc_id)
  @npc_id = npc_id
  @surname = @npc[i][0]
  @middle = @npc[i][1]
  @name = @npc[i][2]
  @age = @npc[i][3]
  @sex = @npc[i][4]
  @disp = @npc[i][5]
  @bounty = @npc[i][6]
  @lvl = @npc[i][7]
  @hp = 100 #Percentages only
  @items = @npc[i][8]
  @clothes = @npc[i][9]
  @weapon = @npc[i][10]
 end
 
 def id
   return @npc_id
 end
end

I'm getting a NoMethodError, undifined method `[]' for Nil:nilClass on line 3 for this little test:
Code:
class Scene_NPCTest
  def initialize
    @e = $game_npc[1].id
  end
  
  def main
    print @e
    print $game_npc[0].id
    $scene = Scene_Map.new
  end
end

If you or somebody else can help me figure out why it won't work, please do.
Thankee.
Peace Out!
~Broken
 

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