ID:2507548
 
(See the best response by Marekssj3.)
Code:
mob/Magic/verb
Fireball()
LightingStrike()
mob/Illusion/verb
DoubleVision()
Reflection()
mob/verb/CountSpells()
var/amount=count()
usr<<"You have [amount] Spells"
mob/proc/count()//this is what I have problems with
var/ammount=0
for(var/mob/Magic/verb in src.verbs)
ammount+=1//for every Magic verb you have, +1 to the ammount
for(var/mob/Illusion/verb in src.verbs)
ammount+=1//same for every Illusion spell
return ammount
//This is the whole code, it doesn't give any errors or anithing, but it just doesn't work, it always returns 0


Problem description: I want to count certain types of verbs a user has

mob/Magic/verb
Fireball()
Lighting()
mob/verb/Countverb()
var/list/verb_types = typesof(/mob/Magic/verb)
return verb_types.len

That would be another way to do the things. I tried to test for checking every verb in the mob verbs but it's only possible if you don't define the path type of the var like:
for(var/Z in verbs)
It will return all verbs
In response to Czoaf
That's an interesting code, but I think that will always return 2 right? Example: If the user only has the Fireball spell and not the lightning spell, will that return 1? or will it return 2? I'm asking because I don't see any reference to the user's verbs. I want to count the Magic verbs the user has, not how many spells there are.
Best response
I'm not sure this is the best way to do it, but here is my formula:

mob
Login()
..()
src.verbs+=/mob/Magic/verb/Fireball
// src.verbs+=/mob/Magic/verb/LightingStrike

mob/Magic/verb
Fireball()
LightingStrike()
mob/Illusion/verb
DoubleVision()
Reflection()

mob/proc/countVerbs(var/path="/mob/Magic")
var/counter=0
for(var/v in src.verbs)
if(findtext("[v]",path))
counter++
return counter


mob/verb/Test()
world<<countVerbs()
In response to Marekssj3
Yes, this worked perfectly, thank you~