ID:264402
 

Problem description:Okay I have a life system in my game but I can't figure out how to make it so you can recover them by using an object.


Here is my code

mob/player
var/lives = 3

obj/HP_Recover
verb/Recover_Lives()
if(lives < 3)
lives = 3
usr << "Your lives have been recovered!"
else
usr << "You alredy have all of your lives."


I keep getting the error: "lives undefined var"

Please help!!!

You didn't specify WHO's life. As you have /obj/ has parent, it'll default "src.life", which means "the object's life".

usr.life
In response to Mysame
Since lives is defined under mob/player using usr will also error since usr is just /mob.

You can typecast it by doing
mob/player/user=usr


Or just define lives under /mob

In response to T3h P3ngu1n
Oh, well spotted, missed that.
In response to T3h P3ngu1n
okay i changed the code to:

obj/HP_Recover/verb/Recover_Lives(mob/player/user=usr)
set src in view (1)
if(user.lives < 3)
user.lives = 3
usr << "Your lives have been recovered!"
else
usr << "You alredy have all of your lives."


I don't get any errors, but now it comes up with a window that asks who you want the lives to be recovered for. I don't want that. I just want the user who is using the "HP_Recover"'s lives to be recovered.

Please help
In response to Shadow Zeta
obj/HP_Recover/verb/Recover_Lives()
set src in view (1)
var/mob/player/user=usr
if(user.lives < 3)
user.lives = 3
usr << "Your lives have been recovered!"
else
usr << "You already have all of your lives."


If you put it as a parameter, then yes it will ask for a parameter.
In response to T3h P3ngu1n
Thanks, now it works.