ID:264379
 
Code:
mob/var
S11
S22

list
S1
S2
S3


mob
verb
Learn_Punch()
src.S1 += /mob/S1/verb/Punch
src.S2 += /mob/S2/verb/Kick
if(src.S22)
src.verbs += new/mob/S2/verb/Kick()
if(src.S11)
src.verbs += new/mob/S1/verb/Punch()

S1/verb
Punch()
viewers(usr)<<"[usr] punched!"
S2/verb
Kick()
viewers(usr)<<"[usr] kicked!"
verb
Switch_Stance()
if(S22)
for(var/V in typesof(/mob/S2/verb))
usr.verbs -= V
for(var/X in usr.S1)
usr.verbs += X


Problem description: I'm not sure what I've done wrong, but up at src.S1 += /mob/S1/verb/Punch I get the following runtime error:

runtime error: type mismatch: /mob/S1/verb/Punch (/mob/S1/verb/Punch) += /mob/S1/verb/Punch (/mob/S1/verb/Punch)
proc name: Learn Punch (/mob/verb/Learn_Punch)

I think I can see what I've done wrong, but I'm not sure how to fix it. Can someone please give me some guidance?

Demon_F0rce wrote:
Code:
> mob/var
> S11
> S22
>
> list
> S1
> S2
> S3
>
>
> mob
> verb
> Learn_Punch()
> src.S1 += mob/S1/verb/Punch
> src.S2 += mob/S2/verb/Kick
> if(src.S22)
> src.verbs += new/mob/S2/verb/Kick()
> if(src.S11)
> src.verbs += new/mob/S1/verb/Punch()
>
> S1/verb
> Punch()
> view(usr)<<"<b><font size = 1>[usr] punched [M]!"
> S2/verb
> Kick()
> view(usr)<<"<b><font size = 1>[usr] kicked [M]!"
> verb
> Switch_Stance()
> if(S22)
> for(var/V in typesof(/mob/S2/verb))
> usr.verbs -= V
> for(var/X in usr.S1)
> usr.verbs += X

Problem description: I'm not sure what I've done wrong, but up at src.S1 += /mob/S1/verb/Punch I get the following runtime error:

runtime error: type mismatch: /mob/S1/verb/Punch (/mob/S1/verb/Punch) += /mob/S1/verb/Punch (/mob/S1/verb/Punch)
proc name: Learn Punch (/mob/verb/Learn_Punch)

I think I can see what I've done wrong, but I'm not sure how to fix it. Can someone please give me some guidance?

I tried fixing it, compile that and se what u get
You may have defined the vars to be of /list type, but you've never actually given them a value of a list. Normally defined type doesn't mean anything and the var won't actually contain a list (or [insert X here]) unless you initialize it to one:
var/list/L
//is the same as
var/list/L = null
//ways of initializing an empty list:
var/list/L = new
var/list/L = new() //parentheses optional if no args
var/list/L = new /list()
var/list/L = list()
var/L[0] //this also implicitly defines the var as /list type
In response to Kaioken
I tried all of the ways to write the list var that you mentioned, I kept getting the same runtime error as before, so it seems that I'm not getting the problem from there.
In response to Demon_F0rce
If you're sure you've initialized all of the lists and their vars still get set into a type path*, that means you must be accidentally setting them to it somewhere (ie with the = operator), so fix that. But what's up with this funky design anyway...? Why have all those lists on the mob and not just use verbs directly? I think whatever you're trying to do, there's a cleaner way to do it.

*ie, S1 got set to /mob/S1/verb/Punch. This would be normally caused by not initializing the list and using += (in effect null += /mob/S1/verb/Punch), but if you've truly fixed that, it seems it can only be the above, or that you're deleting the list somewhere.
In response to Kaioken
What I'm trying to do is discussed here: [link]

And here's another copy of the post:

"Another question, how could I make it so that by clicking some verbs, I can add and remove verbs. For example, lets say P is a martial artist and can use three stances. S1 allows P to use punch and chop, S2 allows P to use kick and jump and S3 allows P to run on walls. However, listed under S1 in verbs also includes block. So, if P were to switch from S2 to S1, I can't simply remove the verbs from S2 and add the ones from S1.

I thought from that, that the best way to change verbs through the stances was to get DM to figure out what stance P is in, get rid of all verbs from that branch, then add in the verbs that P knows from the other stance via one of P's list vars. However, I got stuck on how to add the verbs from the list to P. Could someone please help me here?"
In response to Demon_F0rce
Yes, but I don't see what use those extra lists are. Also, you don't need new() when adding verbs, and you can add the list typesof() returns directly.
I'd just group all the verbs of a given stance under a given path node (like you have), and then use typesof() to add or remove a whole branch, using a var to keep track of the player's current stance (and remove the verbs of it when he switches from it). Something like this looks like a good way to do it:
stance //just a verb-container datum - you can use anything\
to put the verbs under

S1/verb
Punch()
Jump()
S2/verb
Kick()
Crouch()
//...

/*unfortunately text2path doesn't work for type paths
ending in "/verb", so we can't just use it to quickly
grab the right master path. so we'll make a proc for it*/

proc/stance2path(n)
//takes in stance id, returns the master verb type path of that stance's verbs
switch(n)
if(0) //no stance
//signify this is a recognized 'stance id' by returning true
return 1
if(1) //Stance 1 / S1
return /stance/S1/verb
if(2) return /stance/S2/verb
//...
mob/fighter
var/stance = 0//stance ID; number, you may use a different value type. could also use #defines to name the numbers
verb/Switch_Stance(newstance as null|num)
/*you could also have the player choose from a list
of predefined values instead, even text ones, but for
demonstration I'll take the shorter path and use a number*/

if(newstance == null) //if he pressed cancel
return
var/P_current = stance2path(src.stance)
var/P_new = stance2path(newstance)
if(!P_new)
//proc returned default value of null;\
this stance id doesn't exist.

return
if(P_current != 1) //if the player isn't in 'no stance'
//remove the verbs of the style he's in
src.verbs -= typesof(P_current)
if(P_new != 1) //if the player isn't switching into 'no stance'
src.verbs += typesof(P_new)
src.stance = newstance

I didn't include extras you'll probably want like more stances or notifications to the player that he entered a nonexistent stance (but that won't be possible anyway if you make him choose from a list of stances), etc.
In response to Kaioken
This is helpful, but then I end up back at the original problem which was that what if player didn't know how to use punch, and I want them to learn it before it becomes accessible as a verb? Therefore, I thought it would be a good idea that each player has a list of the verbs they know of each stance, and then add the verbs from that list. If I were to implement this, I'd end up right at the problem we were discussing before. The bad thing here is though, I have no idea where to put what and how to call what.
In response to Demon_F0rce
You can have just one list of all the verbs the player 'knows'. Then when the player switches stance, instead of directly adding all the verbs in that stance, instead loop through the verbs in that stance, and only add them to verbs if they exist in the player's 'know' list.
In response to Kaioken
Okay then, I'm sure I can work off of this. Thanks for your help.