ID:142163
 
Code:
Skill
proc
Level(mob/M)
if(M&&exp>=mexp)
for(var/A in unlocked_skills)
var
i = 0
a = 0
params = params2list(unlocked_skills[A])
params2 = params["req"]
newtech = text2path(params["path"])
while(length(params2))
var
skill = copytext(params2,1,findtext(params2,"`"))
numreq = text2num(copytext(params2,length(skill)+2,findtext(params2,"~")))
world<<skill
world<<numreq
for(var/Skill/S in M.contents)
if(skill in M.contents && numreq >= S.level) a ++
params2 = copytext(params2,findtext(params2,"~")+1,length(params2))
world<<params2
i++
if(i == looptimes)break
sleep(1)
world<<"[a] & [i]"
if(a == i && !(newtech in M.othervars[LEARNED]) )
M << "You have learned [params["sname"]]!"
M.othervars[LEARNED] += newtech
M.contents += new newtech

Basic
Starting_Skills
Hand_To_Hand
name="Hand To Hand"skill"
unlocked_skills = list("Adrenaline Rush" = "path= /Skill/Special_Skills/Everyone/Adrenaline&sname=Adrenaline Rush&req=Skill/Basic/Starting_Skills/Hand_To_Hand`10~/Skill/Basic/Starting_Skills/Block`5~/Skill/Basic/Starting_Skills/Evade`5~")


Problem description:

The following Snippet is part of my Skill system for my game.

The problem i'm having is the Level proc when trying to learn something.

I'll explain the problem, and then post the debug.

1: The loop works fine the first 2 times, but doesn't work after that at all(see below)
2: The first skill always begins without "/", even if i use findtext
3: Using the looptimes is bad, but if i don't, it loops infinitly.
4: It doesn't seem to find any of the skills in my contents(even if the requirments are correct), so when the loop is finished, nothing happens.

The Debug.

You feel more experienced with using Hand To Hand.
Skill/Basic/Starting_Skills/Hand_To_Hand
10
/Skill/Basic/Starting_Skills/Block`5~/Skill/Basic/ Starting_Skills/Evade`5
/Skill/Basic/Starting_Skills/Block
5
/Skill/Basic/Starting_Skills/Evade`
/Skill/Basic/Starting_Skills/Evade

/Skill/Basic/Starting_Skills/Evade
0 & 3
It's hard to debug this without more of the program, but for your point 2 (1st skill doesn't start with /), note that you are apparently missing a "/" from the unlocked_skills line containing: req=Skill/Basic/Starting_Skills/Hand_To_Hand.

As for point 4 (won't find skill in contents), are you just adding a string with the name of the skill to the mob contents, or are you actually adding an instance of the skill datum? If the latter (Edit: a further look at your code seems to show this is true), I believe you'll need to use locate(skill) in M.contents to find it.
In response to Hobnob
Hobnob wrote:
It's hard to debug this without more of the program, but for your point 2 (1st skill doesn't start with /), note that you are apparently missing a "/" from the unlocked_skills line containing: req=Skill/Basic/Starting_Skills/Hand_To_Hand.

As for point 4 (won't find skill in contents), are you just adding a string with the name of the skill to the mob contents, or are you actually adding an instance of the skill datum? If the latter (Edit: a further look at your code seems to show this is true), I believe you'll need to use locate(skill) in M.contents to find it.

Well, tommrow if I have time i'll get together a small src showing the basics of the system.

I also fixed Number 2(i can't believe i missed it >_>) as for 4, locate didn't work.
In response to Axerob
I fixed it, oddly enough by messing around.

    proc
Level(mob/M)
if(M&&exp>=mexp)
M<<"You feel more experienced with using [src]."
level++
mexp+=100
exp=1
power+=level + round(100 / ( 2 ** rand(1,10 )))
if( !(unlocked_skills) )return
for(var/A in unlocked_skills)
var
i = 0
a = 0
params = params2list(unlocked_skills[A])
params2 = params["req"]
while(length(params2))
var
skill = copytext(params2,1,findtext(params2,"`"))
numreq = copytext(params2,length(skill)+2,findtext(params2,"~"))
for(var/Skill/S in M.contents)
if(locate(text2path(skill)) in M.contents)
if(S.level >= text2num(numreq))
a ++
break
params2 = copytext(params2,findtext(params2,"~")+1,length(params2)+1)
i++
sleep(1)
var/newtech = text2path(params["path"])
if(a == i && !(locate(newtech) in M.othervars[LEARNED]) )
M << "You have learned [params["sname"]]!"
M.othervars[LEARNED] += new newtech
M.contents += new newtech