var/list/all_skills=list()
world/New()
for(var/type in typesof(/skill))
all_skills += new type()
mob/proc/
AddSkill(id)
var/skill_type = SkillType(id)
var/skill/skill
if(!skill_type)
skill = new /skill()
skill.id = id
skill.name = ""
else
skill = new skill_type()
skills += skill
new /skillcard(src, skill)
return skill
proc
SkillType(id)
for(var/skill/skill in all_skills)
if(skill.id == id)
return skill.type
Is there a better way to handle skillcards? I mean looping through all_skills list every time a skill is added is a real pain, especially if the game has over 500 skills. I'm just trying to figure out how to return a skill type without having to loop through the list in order to find it.
|
Nov 22 2016, 10:00 am
|
|
Use an associative list. Assuming id isn't a number, you can associate the id to the skill with that id (id_to_skill[id] = skill), then get the skill associated to the id (id_to_skill[id]).
|
In response to Kaiochao
|
|
The id is a number. Here are ids converted to text using ters method. How do I create a skill card though, because technically the id is still a number represented by a text. I have no idea how to get information from the list like a skills cooldown/name etc. So when the savefile tries to check a skills name I get errors like "Cannot read "1004".name or 1004.name.
AddSkill(skill/skill) |
In response to Mav472
|
|
var skill/skill = skills[idstr] |
In response to Kaiochao
|
|
That returns as an error Cannot read "1".name
|
In response to Mav472
|
|
That's probably because you're passing the ID value to AddSkill() instead of the actual skill object.
|
In response to Kaiochao
|
|
I'm not sure how to create the skill object based on the associative list. Is there a way to return the parent object using its id value?
|
In the first place, why are you bothering to do this? Why do skills have IDs? Why not identify skills by type?
var list/all_skills |
In response to Kaiochao
|
|
I'm honestly really sorry Kaiochao. I just need an efficient way to handle skills; adding skills to a players list, creating skill cards, saving/loading information from the skills like cooldowns and uses. The skill ids handle skill purchases. I'll use this method but it doesn't seem anymore efficient. I'll still have to loop through long lists to retrieve information.
|
In response to Mav472
|
|
I'll take a step back and start from the code you gave in the original post, because I think I misinterpreted something along the way.
Original: var/list/all_skills=list() Here's what it could look like with an associative list: // this is changed to map ids to types A bonus here is that skill_id_to_type is also effectively a list of all Skill IDs that exist: mob/verb/list_all_skill_ids() |
In response to Kaiochao
|
|
This is great though. Thanks a ton bro |
In response to Kaiochao
|
|
skill_id_to_type[skill.id] = type
getting an index of of bounds here |
In response to Mav472
|
|
I forgot you were using numbers for id... You'll have to convert to text like before. I edited my previous post.
|