Assigning Multiple Skills Via Class Choice
So I am just going to post some additional information on this topic.
This will make more sense for those who have seen the video.
I mentioned in the video how you would go about adding multiple skills (or items) to a player depending on the class they choose.
Here is a more detailed explanation of how to do that.
First of all, the JSON itself will look more like this:
[
{
"class": "Fighter",
"health": 30,
"attack": 30,
"defense": 25,
"wit": 5,
"intelligence": 5,
"charisma": 6,
"skills": []
},
{
"class": "Mage",
"health": 10,
"attack": 10,
"defense": 20,
"wit": 15,
"intelligence": 20,
"charisma": 17,
"skills": ["SKILL_0001", "SKILL_0002", "SKILL_0003"]
},
{
"class": "Bard",
"health": 5,
"attack": 3,
"defense": 2,
"wit": 19,
"intelligence": 15,
"charisma": 20,
"skills": []
}
]
Notice how I have changed "skill" to "skills" (due to the plural nature of the implementation) but also "None" has been replaced with an empty array instead.
You cannot compare a string to an array so the previous check from the video:
if $class_data["skill"] != "None" then
would give a error now at runtime when choosing a class, since the data in the JSON is now an array.
Instead, the startup script now looks like this:
$class = display_choices("Pick A Class", array["Fighter", "Mage", "Bard"]);
$class_data = data["classes.json"][$class];
show_widget("class_info");
show_widget("skill_bar");
player.property["class"] = $class_data["class"];
player.stat["max_hp"] = $class_data["health"];
player.stat["hp"] = $class_data["health"];
player.stat["attack"] = $class_data["attack"];
player.stat["defense"] = $class_data["defense"];
player.stat["wit"] = $class_data["wit"];
player.stat["intelligence"] = $class_data["intelligence"];
player.stat["charisma"] = $class_data["charisma"];
if $class_data["skills"] != array[] then
print("SKILLS FOUND");
for $skill in $class_data["skills"] do
give_skill($skill);
end;
end;
if the array is not empty, then for loop through the skills array and give each skill to the player.
So in the case of the Mage (See JSON), the player will get three skills.
This can also be done with class specific items. You would just use ITEM ID's in the JSON array, and give_item in the script for loop.