GML How to Programm Tree of Skills

Petrik33

Member
Hello everybody, I will be quick AF, just need a tip from experienced GameMakers:
What is the most efficient way to make skill tree for a hero, like in RPG, where you have different ways of your hero development different branches, which sometimes lead to same skill for example, the "Leaves/branches" of the tree will be sometimes active sometimes passive skills and sometimes they will change already existing skills. When the player levels up he gets a choice of any skill he has a path to, so he can either choose something from the bottom or the top of the tree, the skill only has to be reached in the tree, The future branches of the tree won't be visible in case if its neccesary to know. The skills are planed to be made by . JSONs??????
I tried to find example of such trees in other games, but have only recalled the tech tree in Civilization, the difference is that in Civilization, to open branch you have to reach it by all the paths(if two different techs lead to one tech, you have to explore both teachs to reach the new one) and also in Civilization the whole tree is visible, but it doesn't matter I guess.
 

curato

Member
json is just a way to hold data. Personally, I would use a ds_map. The real structure to this isn't the data structure you save the data in, but the logic behind that if you store at 5 in the fire tree variable for example that it know you can get a skill or have access to a branch tree. Any implementation I can think off would be store the important data then make use of conditional statements like if or switch to determine what is appropriate based on what point values you have stored. You just need to break the task down in small pieces. Once you have the data structure you can have a nice image of a skill tree with instance of objects on it that you could click to add points to can would check the variables to see if that is allowed or not and could grant skills depending on how many points are there.
 

Petrik33

Member
json is just a way to hold data. Personally, I would use a ds_map. The real structure to this isn't the data structure you save the data in, but the logic behind that if you store at 5 in the fire tree variable for example that it know you can get a skill or have access to a branch tree. Any implementation I can think off would be store the important data then make use of conditional statements like if or switch to determine what is appropriate based on what point values you have stored. You just need to break the task down in small pieces. Once you have the data structure you can have a nice image of a skill tree with instance of objects on it that you could click to add points to can would check the variables to see if that is allowed or not and could grant skills depending on how many points are there.
Thanks a lot, so just to be sure, you mean I should add a key to the map, that will hold the skill that is needed to unlock this one, and other key to store next skill you gonna unlock, am I right?
 
Have you already decided how the tree will be structured? What skills will be on it, how many, etc.? Some of these are design questions and you can make changes later if you want to rebalance things, but it's important to make some decisions now.

Basically I'd imagine each skill as its own variable, either Boolean ("true" meaning you have the skill, "false" meaning you don't) or Real if you can take a skill multiple times to improve its effects. Not sure where the best place to store these would be. (You need to be able to keep changes from room to room and make sure that these changes get saved in whatever your save game routine is.)

Once you've gotten them all set as variables, then a skill tree's interface can be programmed to check if certain skills are already flagged as true or > 0, and these can be conditions for making the player able to select skills further along that path. Then it's just a question of how you want the player to interface with it. You'll want some kind of graphical display which can change based on what's selected, objects the player can interact with, etc.
 

curato

Member
yeah ds_maps are good for that kind of data and they are good for storing stuff you want to save for a save game or something as there are already built in functions for saving them to a file. Just for example, I have a ds_map in my main project which stores the completion status for all the level and how many stars and such you earned and the basic sound and video settings. This is save to a file when ever a change is made that way when the game starts I can load it back into memory and it remembers your progress from last time. But I had to look at the game and decide what I needed to keep track of and what point I would make changes and save it like when you complete a level then it updates the level's completion and the stars earned. In your case you would want to look at it when you level up save the level and how many points you gain then if you need to assign them some where and what skills you gain that way when you return to the game you have all of that to check your players status. ds_map is nice but it is just a fancy was to save variables. My advise is design what you want to do first then go about figuring out how to implement your vision.
 
Top