ID:139433
 
Code:
obj
Axe
desc = "A sturdy axe."

Sword
desc = "A sharp sword."

Hammer
desc = "A large hammer."




// Under mob, under the login proc

usr.Weapons.Add("Axe","Sword","Hammer")





// and this is the verb under mob I'm having trouble with...

checkweapons()
var obj/W = input("Your weapons") in Weapons
world << W.desc


Problem description:


Everything else works fine except when i hit the checkweapons and select a weapon choice, it says:

runtime error: Cannot read "Axe".desc


I assume it has to do with the part that it is text, and not just an object? I'm not sure, please help, I'm fairly new.
usr.Weapons.Add("Axe","Sword","Hammer")


I would've used src instead of usr in this case, but basically what you are doing here is adding text strings to the list instead of objects. You need to create a new instance of the object classes and add those to the list instead. Something like this:

var/obj/Axe/axeInstance = new()
var/obj/Sword/swordInstance = new()
var/obj/Hammer/hammerInstance = new()
src.Weapons.Add(axeInstance,swordInstance,hammerInstance)
In response to Cody123100
To be honest I always find it funny how people believe knowing whether an axe is sturdy or not is really helping. Sometimes it's good to know details but most items should be interpretable from their name alone.
In response to Kyle_ZX
Kyle_ZX wrote:
To be honest I always find it funny how people believe knowing whether an axe is sturdy or not is really helping. Sometimes it's good to know details but most items should be interpretable from their name alone.

I agree. And really, unless you plan on throwing items in that are destroyable through use like and old axe might only be usable 3 times were as a new axe maybe 10 or a rusted axe maybe 5 times. If all the axes are the same and have the same usability, you really don't need to describe them.
In response to Moussiffer
Moussiffer wrote:
Kyle_ZX wrote:
To be honest I always find it funny how people believe knowing whether an axe is sturdy or not is really helping. Sometimes it's good to know details but most items should be interpretable from their name alone.

I agree. And really, unless you plan on throwing items in that are destroyable through use like and old axe might only be usable 3 times were as a new axe maybe 10 or a rusted axe maybe 5 times. If all the axes are the same and have the same usability, you really don't need to describe them.

But his question had nothing to do with semantics, personal preferences or design philosophy--it was a question as to why his program wasn't working.

But Cody was right. The problem is in using a text string as opposed to an atom. He helpfully provided useful information, so I won't echo him further.

In response to Slipknight
Well you know, i was planning on generating everything's details from double sided axes to rusty old crappy ones, thanks for helping guys, it was mostly a test, haha.
In response to Cody123100
I'm not sure if that's the best way. That way requires a lot of lines of code.

var/list/weapons=list(/obj/Axe,/obj/Sword,/obj/Hammer)

mob/Login()
..()
for(var/T in weapons)
src.Weapons.Add(new/T())


This way, you can add more types to the weapons list without having to add many more lines of code and declare new variables.

In response to Hypnautilus
Hypnautilus wrote:
I'm not sure if that's the best way. That way requires a lot of lines of code.

> var/list/weapons=list(/obj/Axe,/obj/Sword,/obj/Hammer)
>
> mob/Login()
> ..()
> for(var/T in weapons)
> src.Weapons.Add(new/T())
>

This way, you can add more types to the weapons list without having to add many more lines of code and declare new variables.

If you wish to be that way, simplified further...
mob/Login()
..()
src.Weapons.Add(new/obj/Axe(),new/obj/Sword(),new/obj/Hammer())


Not too much difference in any of the methods provided.
In response to Pirion
mob/Login()
..()
for(var/t in typesof(/obj/weapon) - /obj/weapon)
Weapons.Add(new t)


No need to specify a weapons list, as long as they all come off the same root in the tree.
In response to Kyle_ZX
Flavour text. The sentences "you see a brute" and "you see an intimidating, well-built brute" are equivalent (the latter can be inferred from the former), but give off a different feel.