ID:1723831
 
(See the best response by Mr_Goober.)
RTE:
runtime error: type mismatch: Trained Fighter! (/Jutsus/Perks/Jutsus/T2_Taijutsu) += On-Edge! (/Jutsus/Perks/Jutsus/T1_Reflex)
proc name: Give Perk (/mob/admin/verb/Give_Perk)
source file: Perks.dm,165
usr: Haruka (/mob)
src: Haruka (/mob)
call stack:
Haruka (/mob): Give Perk(Character (/mob))


I'm receiving this runtime error when I use the "Give Perk()" verb. I have no clue why. The significant code is the following:

mob/var/list/UPerks = new()

        verb
Give_Perk(mob/M in world)
set category = "Admin"
var/C = input("Choose the perk you shall give to [M].") as null|anything in Perks
if(C)
M.UPerks+=C
M.Save()
// M.UPerks.Add(C)
M<<"You were given [C] by [src]."
src<<"You gave [C] to [M]."
LogText("-Admin-[src.name]/[src.key] gave [M.name]/[M.key] the '[C]' perk.",0,1)



EDIT: Line 165 is M.UPerks+=C
Best response
UPerks is probably being assigned to a non list object before you try adding the perk to it. This can cause a type mismatch.

Because DM is not type strict, even when the appropriate type has been declared, it is only used for accessing a type's fields. The type itself can be omitted and casted when needed.
In response to Mr_Goober
Uhh...How do I go about preventing and fix this?
If you see the runtime error it says:

Trained Fighter! += On Edge!

The perk Trained Fighter was set to UPerks at a previous time, so check that perk and see if it is being added incorrectly.
In response to Mr_Goober
I don't see anything off with it:
            T1_Reflex
icon='JutsuPerks.dmi'
// icon_state="ReflexT1"
name="On-Edge!"
desc="This person has reflexes that are above average for a normal person. They can react a bit faster than a normal person may when dodging strikes and weaponry; lowering the chances of them getting hit. Though most trained can hit them with little to no trouble. Their reflexes are obviously not anything really impressive."
There are no methods associated with this object? If not, check the parent object for its methods and see if it assigns UPerks instead of adds to it. That is what we are looking for.
In response to Mr_Goober
What do you mean by "assigns UPerks instead of adds to it"?
...I still don't understand what the problem is, nor how to fix it.
In response to Kboy33
Let me try to explain it as simply as possible.

Kboy33 wrote:
...I still don't understand what the problem is, nor how to fix it.
The problem is that UPerks and C are both regular (non-primitive) objects, and the += operator does not work on regular objects (it only works on special objects that the BYOND devs designed it to work on: google "operator overloading" for more on this).

Adding one perk to another perk is probably not what you want to do here.
My guess is that you want to add perks to a list called UPerks.
But UPerks is not a list!

And since BYOND is loosely-typed, it doesn't care about these sorts of (non-sane) operations until the last possible moment, when it trips sanity checks in the engine code: those throw the runtime error you're seeing.

Kboy33 wrote:
What do you mean by "assigns UPerks instead of adds to it"?

Mr_Goober is suggesting that you look through your code for something that says UPerks = thing when it should say UPerks += thing.

UPerks = thing will assign thing to UPerks instead of adding thing to UPerks: that's a mistake and it can cause this error.
In response to Wild Bill Bartok
Thank you for the clarification! I cannot find anything that assigns UPerks except:

mob/var/list/UPerks = new()
Anybody?
Shouldn't you be adding T1_Reflex to the list instead of "On-Edge"?
In response to Kboy33
Kboy33 wrote:
Thank you for the clarification! I cannot find anything that assigns UPerks except:

mob/var/list/UPerks = new()


Is the runtime error still coming up?
If it is, that means keep looking.
Somewhere, UPerks is getting set to this:

/Jutsus/Perks/Jutsus/T2_Taijutsu (name="Trained Fighter!"

And you have to find out where in order to fix that.
In response to Wild Bill Bartok
My idea is that I might have to make it like this:

                var/Jutsus/Perks/Jutsus/C = input("Choose the perk you shall give to [M].") as null|anything in Perks


Therefore C is of the type Jutsus/Perks/Jutsus. Although I don't know if this has any relevance. I genuinely can't find anything which is assigning UPerks to a Perk.

EDIT: I'm not even sure how the first part of the RTE came around:

runtime error: type mismatch: Trained Fighter! (/Jutsus/Perks/Jutsus/T2_Taijutsu) += On-Edge! (/Jutsus/Perks/Jutsus/T1_Reflex)