ID:2482494
 
(See the best response by Kaiochao.)
In this instance i have done something like this.
obj/verb/Equip()
usr.equippedweapon = src

i want to later be able to call back to that weapon in a code like this.
usr.damage = usr.equippedweapon.damage

obviously that doesnt work but you can get what i really want to do here.
In this specific instance i want it so that when you equip an object it makes the older usr.equippedweapon.equipped = 0.
Weapon
var
Name
Damage
obj/equipped = /obj/

New(n, d)
if(n)
Name = ""
if(d)
Damage = d
mob
var
list/Weapons = list()
Weapon
MainWeapon = new("Main Hand", 10)
SideWeapon = new("Side Arm", 5)
New()
if(!Weapons.len)
Weapons.Add(MainWeapon,
SideWeapon)
..()

I'm terrible at explaining things but I tried to make it as self explanitory as possible

You'd then be able to use src.MainWeapon.Damage or add in more vars etc.


You can also use this method for stats like src.Strength.Level + src.Strength.Bonus etc.
Yeah sorry but i do not get that at all. Doesn't weapon need to be defined as an object for example?
In response to Klonoalunar
Klonoalunar wrote:
Yeah sorry but i do not get that at all. Doesn't weapon need to be defined as an object for example?

okay so equipped would be used like if you've defined your weapon say a katana you'd add this into your equip coding
var/obj/weapon/katana/K = new()
src.MainWeapon.equipped = K
src.MainWeapon.Damage = K.damage

ofc this creates a new katana tho lol you'd have to do it from whatever weapon path you've got in the players inv
that'll register the equipped weapon as the katana and change your damage variable to the base damage of the katana see? then when you run damage you can just use src.MainWeapon.Damage
ah right but in this specific instance for example, if i equip another item i want to do something like this
mob/verb/Equip()
if(src.equipped == 1)
usr<<"You are already using this"
else
usr.weaponequipped.equipped = 0
src.equipped = 1
you don't have to put == 1, you can just put (src.equipped) and if it's 0 you can put (!src.equipped) but I'm a little confused as to what you're asking lmao
The code needs to change the old equipped items equipped variable to 0
obviously that doesnt work but you can get what i really want to do here.
It would have worked if you had defined equippedweapon as a weapon type.
If I may, what do you mean by this?
In response to Klonoalunar
Best response
Variables declared as a certain type allow the members of that type (vars/procs) to be accessed through them.

In other words, whenever you do A.B or A.B(), A must be declared as a type that has B. Otherwise, the compiler points out (in the form of a compilation error) that B is undefined for A.

Naturally this extends to A.B.C, A.B.C.D, and so on, since each . operation is its own separate operation. A.B is the B of A, A.B.C is the C of that, A.B.C.D is the D of that, etc.

For instance, mobs have a client var declared as a /client, and clients have a mob var declared as a /mob. This lets you do things like client.mob.client.mob... forever, because it's a circular reference.

So in your case, if a weapon's damage variable is defined under the type /obj/weapon, then equippedweapon should be declared as a weapon like so:
obj/weapon
var
damage

mob
var
obj/weapon/equipped_weapon

Then, you can access equipped_weapon.damage (from a src that has equipped_weapon).