I'm still somewhat new to GML and could use some help with building a primary system I'd like to have in my game. I would like to have the player be able to quickly swap between 4 playable characters in an action RPG game. Each playable character has it's own moveset, sprites, and stats, such as height (for going under things) and will eventually have their own stamina bar that will refill while another character is being used.
I currently have all my playable characters as separate objects tied to a parent so they can inherit common properties, and my code currently allows me to swap characters by using a player_control object to facilitate swapping. It destroys the old player object instance, and creates a new player object instance where the old one was standing. I was attempting to make the game able to cycle through more playable characters when I ran into an issue with my idea. Creating and destroying instances means that it could be hard to save things like health/stamina, and I also wanted to start out with a small party of 2 playable characters and expand it to 3, then 4 as the game goes on. I would need to have some way to change variables for what characters are currently in the party and currently playable (they may faint), and have them able to be added or subtracted to my character swap code. Destroying/creating instances wipes those variable states clean, so it's hard to keep track of data. I've tried making a data structure storing which characters were playable, but it needs to have a current instance of each player object running, which obviously I do not have when I am creating and destroying them.
Should I go in a different direction, such as keeping all the players in one object?
Here is my current player change code
code I was trying to create when I realized it works on instances of objects, not the objects themselves. variable "playable" is a true/false declared in the create event on each object
I currently have all my playable characters as separate objects tied to a parent so they can inherit common properties, and my code currently allows me to swap characters by using a player_control object to facilitate swapping. It destroys the old player object instance, and creates a new player object instance where the old one was standing. I was attempting to make the game able to cycle through more playable characters when I ran into an issue with my idea. Creating and destroying instances means that it could be hard to save things like health/stamina, and I also wanted to start out with a small party of 2 playable characters and expand it to 3, then 4 as the game goes on. I would need to have some way to change variables for what characters are currently in the party and currently playable (they may faint), and have them able to be added or subtracted to my character swap code. Destroying/creating instances wipes those variable states clean, so it's hard to keep track of data. I've tried making a data structure storing which characters were playable, but it needs to have a current instance of each player object running, which obviously I do not have when I am creating and destroying them.
Should I go in a different direction, such as keeping all the players in one object?
Here is my current player change code
GML:
if (input_c){
instance_destroy(current_player); //destroy the old current player
instance_create_layer(x, y, "objects", obj_rekkie); //create the new current player
current_player = obj_rekkie;
}
GML:
var yy = 0; //local var for looping through the data structure
var pgrid = ds_playable; //local variable to be used with the "with" statement
with(obj_player_template){ //with each of the children of player_template, perform the code: (problem, this only runs currant instances in the game)
pgrid[# 0,yy] = id; //loop through instances and add their ID's
pgrid[# 1,yy] = playable; //loop through and state if they are playable or not
yy++; //incriment y and do it again till there is nothing left
}
Last edited: