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.

What is the best way to code this?

I am having trouble deciding on which direction I should take my coding, currently I am making a CBS and with it I have a class that holds all stats and attributes of a character, aptly named "Character". I am having a hard time implementing a system which allows me to easily create instances of character types. Currently I have hard coded all data of a character type directly into my scripts, the only way I could think of doing this is simply make a child class of the class "Character" for every single different enemy and character type, which is a lot. In otherwords,if I wanted to create a type of enemy called "Slime", instead of simply using the "Character" class, I make a completely different child class out of character called "Slime." Why? Because I cant use the default database of RMXP because my CBS differs too much.

So here are my questions:

1) is there an easier way to build a database of enemy/character types other than directly hardcoding them into the system, especially as child classes.

2) Is creating a different child class for every different character type a little too extreme or unprofessional? It seems like I am trying to kill a fly with a shotgun.

I guess I am looking more for criticism than help, while my current system works, it feels sloppy.
 
Object-oriented programming isn't the best way to do database work... because a different character isn't a different class : it is just the same class, but with different parameters.
You could follow the rmxp way : Fill a Table class with the data you need, and dump it to a .rxdata. That way, you'll be able to load the table using $data_my_enemies = load_data(...), and work with it exactly the same way you would work with the standard database.

You could even create a mini editor in rgss to speed up the tedious process of filling the database.
 
Well, think of it from an object oriented programmer's point of view.

You have an object. Your "Character" class. You want to make a slime enemy, so make a class "Enemy" that extends "Character."

Code:
class Enemy < Character

the Character class holds everything any kind of generic character (actor and enemy alike) would need, such as Name, HP, MP, Speed, and all that. The Enemy class would hold data that only enemies would need.

So now you want to make a slime, your first enemy. Create the $data_enemies array.

Code:
$data_enemies = []

Now, make a variable of type Enemy which will be your slime.

Code:
enemy = Enemy.new()
enemy.name = "Slime"
enemy.hp = 500
enemy.mp = 300
enemy.speed = 50

Now add that new enemy to the $data_enemies array.

Code:
$data_enemies.push(enemy)

Repeat for every enemy you plan on making. Once everything is set up, the $data_enemies array is handled exactly how the default system handles their enemy array.

This is how I would do it, anyway. Hope it helps!
 
Ok, thanks. That is pretty much what I figured. It's been a couple of months since I worked on my game so when I went back and saw this mess I was a little confused. I just wanted to get some help from the experts.

But now that something was said about it, how do you encode and decode data from .rxdata? I've never been able to do it properly. Everytime I try and save any non-built in classes it gives me an error that it is undefined.
 
save_data() and load_data()

The methods are described in the help file.

BTW Rataime, I don't believe much of the RMXP data is done in Tables, but as instances of the appropriate class within the module RPG that are saved by the editor into an .rxdata file and read by the game as indexed arrays.
 
Sorry, but I've searched but I can't find those methods anywhere. What object houses them? I thought that anything like that would be found in the File or IO class.

Edit: Oh sorry, after some searching I found it. I have read the help file several times, I can't believe I missed this. I guess i need to go over it again.

Alright, this topic is resolved. Thank you all for your help, I am going to go play around with my new knowledge. :)
 
The object that has the methods save_data and load_data is the Kernel module (this means you can call these anywhere since Kernel is included in all objects/classes), but save_data and load_data are hidden and you can not see the contents of these methods

The table class is good only for large amount of numbers there is a limit on what you can store in a table -32,768 to 32,767. (which is silly imo) Tables are used for the actor's stats, the map data, the tileset info, and a few other things

Why not just use the RMXP default classes to hold the attributes

Game_Battler holds attributes for all battlers and is the parent of Game_Actor and Game_Enemy

Game_Actor holds actor information (for the players)
Game_Enemy holds enemy information (for enemies)

why not read up on those classes

but I really couldn't follow your first post care to explain in more detail for me
 
It's kind of dumb now that I look back. I was trying to instance classes by creating child classes and then instancing those. It was old code so it confused me. I tried hardcoding all of the different types of enemies and characters and it just seemed like there would be a better way of doing it. My new system is better and while I still would have to code everything, it is much easier.

Also, the reason I dont use the built in character classes is because my stats, battle algorithms, skills, spells, and overall battle setup are so significantly different from the default battle system that I would be better off creating the classes from scratch.
 

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