• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Making a modular Skillbar

P

Pyrosix

Guest
For the turn based game I am designing, I'm trying to come up with a way to make a modular Skillbar since skills are used like consumables. I somewhat understand the concept of making buttons. But it's the modularity that stumps me mostly. I thought about using DS maps but wasn't sure where to begin to implement them since the way skills are gained is through a dynamic method.
 

Kezarus

Endless Game Maker
In my previous game, Endless RPG, I put all Skill Ids on an array. Whenever I had to "print" the Skill bar, I resort to that array and print what's inside.

You can put structs inside the same array and have more things like cooldown, sprite ids, texts, etc. Have fun. =]

If you need something to draw buttons on the GUI, my Framework is right bellow. And it's free.
 
If I understand correctly, you want some kind of equivalent to the "belt" in diablo, where you have, say, 10 slots in which you can put stuff in them (scroll, potions, elixirs, or in your case skills)?
If so, I would just have a "belt_slot" array, in which each entry is a struct, or -1 if empty.

you could then do var _item_clicked = belt_slot[button_index_of_clicked_button]; to access the struct of what's inside this slot.

From then on, it's all smooth sailing to access the data you need to do whatever you want.
var _base_dmg = _item_clicked.base_damage;, and such.

You will also be able to save this data much easier (which I guess you'll want to in a RPG), since you pretty much already have a JSON ready to encode/encrypt/save with the belt_slot[] array.

All in all, don't use DS Maps, use Structs. Basically, they are the same, but better.
 
Last edited:
P

Pyrosix

Guest
So going off the replies above, it seems structs would be my best bet. I'm not familiar with them but that just means I have some researching to Do. For structs does that mean I can store what the skill is supposed to do in them as well? Would they need to be individual scripts?

Thank you for the replies
 

Nidoking

Member
You can store a function in a script. It's actually nicely convenient - as long as all of the functions you'd want to use take the same number and type of arguments, you can store a function in a variable and then call the function using the variable name.
 
So going off the replies above, it seems structs would be my best bet. I'm not familiar with them but that just means I have some researching to Do. For structs does that mean I can store what the skill is supposed to do in them as well? Would they need to be individual scripts?

Thank you for the replies
You will never ever look back, I swear. And yes, you can store everything in them.
Basically, in cour case you could do away with something like this:
GML:
function some_skill(_dmg, _type, _icon_sprite) constructor {            //See the constructor keyword? That's it!
    damage = _dmg;
    elemental_type = _type;
    icon_sprite = _icon_sprite;
}
and then when you want to assign a new skill to the belt, you go
GML:
belt[belt_spot_index] = new some_skill(3, ELEM_FIRE, spr_flame_icon); //Lets say ELEM_FIRE is some macro
And to access the variables you go dot notation
GML:
//Access the data of the belt slot I clicked
var _spell = belt[belt_slot_I_clicked];        //_spell is now holding our struct

hp -= _spell.damage;        //This will remove the damage value of the spell from our hp variable

//To access the sprite_index, you would call:
draw_sprite[_spell.icon_sprite, 0, belt_slot_x_position, belt_slot_y_position]
For example, I can hold all my player stats in a struct named "stats". So then if I want to access, say, the variable "strength" inside it, I would call var _str = stats.strength;.
Looks much nicer.

There are plenty of ways to use them, it's all up to you, really. This example is very raw and basic, it could go much further.
 
Top