ID:148537
 
This is my Give_attack verb, incase of some odd happenning. I as a moderator can give someone their attacks back if needed. But, here's an error I recieve when testing it...

runtime error: Cannot read /obj/slidingdoor (/obj/slidingdoor).tech
proc name: give_attack (/mob/Admin/verb/give_attack)
source file: Police.dm,763
usr: Son Gozelko (/mob/characters/saiyajin)
src: Son Gozelko (/mob/characters/saiyajin)
call stack:
Son Gozelko (/mob/characters/saiyajin): give_attack(Son Gozelko (/mob/characters/saiyajin))


Now, here's my code
    verb
give_attack(mob/characters/M in world)
set category = "Admin"
var/list/techs=list()
for(var/O as null|anything in typesof(/obj))
if(O:tech==1)
techs+=new O
techs+="Cancel"
var/choice=input("What attack do you wish to give [M]?","Skills","") in techs
if(choice=="Cancel")
else
M.contents+=new choice
M<<"<b>[usr] gave you [choice]."
for(var/mob/P in world)
if(P.ishost==1)
P<<"<b><font color=red>[usr] gave [choice] to [M] at approx : [ReportDate(world.realtime)]"
Goku72 wrote:
This is my Give_attack verb, incase of some odd happenning. I as a moderator can give someone their attacks back if needed. But, here's an error I recieve when testing it...
runtime error: Cannot read /obj/slidingdoor (/obj/slidingdoor).tech
proc name: give_attack (/mob/Admin/verb/give_attack)
source file: Police.dm,763
usr: Son Gozelko (/mob/characters/saiyajin)
src: Son Gozelko (/mob/characters/saiyajin)
call stack:
Son Gozelko (/mob/characters/saiyajin): give_attack(Son Gozelko (/mob/characters/saiyajin))

The problem is right there: You're trying to access a var of a type path, not an actual obj. And here's where it's happening:
for(var/O as null|anything in typesof(/obj))
if(O:tech==1)

First off, the "as null|anything" is useless to you in a for() loop, so you may as well get rid of it.
What's triggering your bug, though, is that because you're looping through types, not objs that are actually in existence (that is, created, also called "instantiated"). It's like looping through names instead of mobs; names don't have vars, but mobs do.

There are various ways to do this. Perhaps it'd be most convenient if initial() could simply provide the var you need, via initial(tech,O), but sadly such functionality doesn't exist yet. You'll actually have to create an obj of this type in order to read its var.

It looks to me like this problem is entirely bypassable by defining all these special attacks as subtypes of /obj/tech, though, and looping through those.
var/choice=input("What attack do you wish to give [M]?","Skills","")\
as null|anything in typesof(/obj/tech)-/obj/tech

Lummox JR