"Talent Tree" global yes/false var and int?

Hi, i have been working on a “simple” exp/skills/lvling script. So far everything is working okay.
But right now i want to make a seperate script for a talent tree. But this one is a bit harder, because i do not know how to set it up. I thought of some simple variables.
Like:

var talentPoints : int = 0;
var talentAvailable : boolean = false;

But even when i started with these i thought it wouldn’t work because if you have multiple talents and one is enabled(talentAvailable). Then all would be enabled.

I also had the idea of the possibility spending more points(for example 3) on one talent.
Again, thinking that it would not work. Because of the same issue like the enabling i mentioned earlier.

Then there is the method of creating a variable for every talent.(i hope there is an easier method)
In that case, for each talent. I would have to set it up like:

"name"TalentPoint : int = 0;
"name"TalentAvailable : boolean = false;
"name"MaxLevel : int = 3;

And that probably x 100.

Maybe you guys know a solution for this? Or what these methods are being called so i can search for examples.
(i already searched on google for tutorials this but could not find anything)

I hope someone can help me out with this.

Cheers, Darryl

You could create a Talent class with properties for required talents, required talent points, current level, max level, etc. Something like this:

public class Talent {
    public string name { get; set;}
    public bool isUnlocked { get; set;}
    public Talent requiredTalent { get; set;}
    public int talentPoints { get; set;}
}

And then you’d initialize all of your talents one by one:

void Start() {
	Talent shieldBash = new Talent();
	shieldBash.name = "Shield Bash";
	shieldBash.isUnlocked = false;
	shieldBash.requiredTalent = someOtherTalent;
	shieldBash.talentPoints = 50;	
}

You could then save these talents in an array or something similar for display in your GUI.

I know, that this is not an answer, but i couldn’t post it as a comment cause there were to many characters.

Anyway, here is what i came up with thanks to you.
It is still very basic, but thats mainly because i haven’t decided how i wanted it to work.

But with this layout i can probably make some decent talent trees.

var talentPoints : int = 0;						//How many talentPoints the player has
var maxTalentPoints : int = 50;					//The maximum talentPoints
var hasPoint : boolean = false;					//If the player has a talent point
var talentPointsSpend : int = 0;				//How many talentPoints the player has spend

var playerSkills : PlayerAttributes;

var talentDatabase : TalentInfo[];				//Containing the talent database

private var talentWindow : boolean = false;		//Check if the talentWindow is open

public class TalentInfo
{
	public var talentName : String;				//Name of the talent
	public var talentIcon : Texture2D;			//Icon of the talent
	public var isUnlocked : boolean = false;	//If the talent is unlocked or not
	public var talentMax : boolean = false;		//If the max level of the talent is reached or not
	public var talentLevel : int = 0;			//the current level of the talent
	public var maxTalentPoints : int = 3;		//the max level of the talent
	public var requiredTalent : String;			//If the talent needs a required talent
	public var talentDescription : String;		//The description of what the talent does
	public var talentPosition = Vector2;	//The position where the talent would be on the screen
}


function Start()
{
	playerSkills = gameObject.GetComponent("PlayerSkillSystem");
}


function Update()
{
	//If the player has at least 1 point, than the var hasPoint is set to true else to false
	if(talentPoints >= 1)
	{
		hasPoint = true;
	}
	else
	{
		hasPoint = false;
	}
	
	//Just for test now, if talent 0 is 
	if(talentDatabase[0].talentLevel >= talentDatabase[0].maxTalentPoints)
	{
		talentDatabase[0].talentMax = true;
	}
	if(talentDatabase[1].talentLevel >= talentDatabase[1].maxTalentPoints)
	{
		talentDatabase[1].talentMax = true;
	}
	
	//When the player presses the T key, the "talent window" pops up, or closes
	if(Input.GetKeyDown("t") && talentWindow == false)
	{
		talentWindow = true;
	}
	else if(Input.GetKeyDown("t") && talentWindow == true)
	{
		talentWindow = false;
	}
}


function OnGUI()
{
	//if talentWindow is true, a GUI.BeginGroup is set containing a window with the "talent tree"
	if(talentWindow)
	{
		GUI.BeginGroup(new Rect(Screen.width /2 -400,Screen.height /2 -300,800,600));
		
		GUI.Box(new Rect(0,0,800,600), " ")
		
		if(GUI.Button(Rect(15,15,20,20),talentDatabase[0].talentName))
		{
			if(hasPoint == true)
			{
				if(talentDatabase[0].talentMax == false)
				{
					talentPointsSpend ++;
					talentPoints --;
					talentDatabase[0].isUnlocked = true;
					talentDatabase[0].talentLevel ++;
				}
			}                             
		}
		if(GUI.Button(Rect(15,50,20,20), talentDatabase[1].talentName))
		{
			if(hasPoint == true && talentDatabase[0].talentMax == true)
			{
				if(talentDatabase[1].talentMax == false)
				{
					talentPointsSpend ++;
					talentPoints --;
					talentDatabase[1].isUnlocked = true;
					talentDatabase[1].talentLevel ++;
				}
			}
		}
		
		GUI.EndGroup();
	}
}

Anyway thanks again!

Cheers, Darryl

I wrote one a bit early today for an RPG game I’m working on. It depended on boolean statements for whether or not the skill was unlocked or if they had enough skill points.

var level : int;
var exp : int;
var pointsToSpend : int;
if(exp >= level * 4){
level = level + 1;
exp = 0;
};
var hasS1 : boolean = false;
var hasS2 : boolean = false;
var hasS3 : boolean = false;
var hasA1 : boolean = false;
var hasA2 : boolean = false;
var hasA3 : boolean = false;
var hasT1 : boolean = false;
var hasT2 : boolean = false;
var hasT3 : boolean = false;
var hasB1 : boolean = false;
var hasB2 : boolean = false;
var hasB3 : boolean = false;
var hasM1 : boolean = false;
var hasM2 : boolean = false;
var hasM3 : boolean = false;
var addS1 = function(){
if(pointsToSpend >= 1){
if(hasS1 === false){
hasS1 = true;
pointsToSpend = pointsToSpend - 1;
}
}
};
var addS2 = function(){
if(pointsToSpend >= 1){
if(hasS1){
if(hasS2 === false){
hasS2 = true;
pointsToSpend = pointsToSpend - 1;
}
}
}
};
var addS3 = function(){
if(pointsToSpend >= 1){
if(hasS2){
if(hasS3 === false){
hasS3 = true;
pointsToSpend = pointsToSpend - 1;
}
}
}
};
var addA1 = function(){
if(pointsToSpend >= 1){
if(hasA1 === false){
hasA1 = true;
pointsToSpend = pointsToSpend - 1;
}
}
};
var addA2 = function(){
if(pointsToSpend >= 1){
if(hasA1){
if(hasA2 === false){
hasA2 = true;
pointsToSpend = pointsToSpend - 1;
}
}
}
};
var addA3 = function(){
if(pointsToSpend >= 1){
if(hasA2){
if(hasA3 === false){
hasA3 = true;
pointsToSpend = pointsToSpend - 1;
}
}
}
};
var addT1 = function(){
if(pointsToSpend >= 1){
if(hasT1 === false){
hasT1 = true;
pointsToSpend = pointsToSpend - 1;
}
}
};
var addT2 = function(){
if(pointsToSpend >= 1){
if(hasT1){
if(hasT2 === false){
hasT2 = true;
pointsToSpend = pointsToSpend - 1;
}
}
}
};
var addT3 = function(){
if(pointsToSpend >= 1){
if(hasT2){
if(hasT3 === false){
hasT3 = true;
pointsToSpend = pointsToSpend - 1;
}
}
}
};
var addB1 = function(){
if(pointsToSpend >= 1){
if(hasB1 === false){
hasB1 = true;
pointsToSpend = pointsToSpend - 1;
}
}
};
var addB2 = function(){
if(pointsToSpend >= 1){
if(hasB1){
if(hasB2 === false){
hasB2 = true;
pointsToSpend = pointsToSpend - 1;
}
}
}
};
var addB3 = function(){
if(pointsToSpend >= 1){
if(hasB2){
if(hasB3 === false){
hasB3 = true;
pointsToSpend = pointsToSpend - 1;
}
}
}
};
var addM1 = function(){
if(pointsToSpend >= 1){
if(hasM1 === false){
hasM1 = true;
pointsToSpend = pointsToSpend - 1;
}
}
};
var addM2 = function(){
if(pointsToSpend >= 1){
if(hasM1){
if(hasM1 === false){
hasM2 = true;
pointsToSpend = pointsToSpend - 1;
}
}
}
};
var addM3 = function(){
if(pointsToSpend >= 1){
if(hasM2){
if(hasM3 === false){
hasM3 = true;
pointsToSpend = pointsToSpend - 1;
}
}
}
};
function OnGUI () {
    if (GUI.Button (Rect (100,100,200,20), "Swords Do 20% More Damage")) {
        addS1();
    }
	if (GUI.Button (Rect (100,125,200,20), "Swords Do 30% More Damage")) {
	addS2();
	}
	if (GUI.Button (Rect (100,150,200,20), "Swords Do 40% More Damage")) {
	addS3();
	}
	if (GUI.Button (Rect (310,100,200,20), "Bows Do 20% More Damage")) {
	addA1();
	}
	if (GUI.Button (Rect (310,125,200,20), "Bows Do 30% More Damage")) {
	addA2();
	}
	if (GUI.Button (Rect (310,150,200,20), "Bows Do 40% More Damage")) {
	addA3();
	}
	if (GUI.Button (Rect (520,100,300,20), "20% Harder To Detect While Sneaking")) {
	addT1();
	}
	if (GUI.Button (Rect (520,125,300,20), "30% Harder To Detect While Sneaking")) {
	addT2();
	}
	if (GUI.Button (Rect (520,150,300,20), "40% Harder To Detect While Sneaking")) {
	addT3();
	}
	if (GUI.Button (Rect (830,100,200,20), "Blocking is 20% More Effective")) {
	addB1();
	}
	if (GUI.Button (Rect (830,125,200,20), "Blocking is 30% More Effective")) {
	addB2();
	}
	if (GUI.Button (Rect (830,150,200,20), "Blocking is 20% More Effective")) {
	addB3();
	}
	};