mob
trainer
var
action
battle
want
ready
id
Click(src in orange(1))
if(src==/mob/trainer)
if(usr.id==0)
usr<<"Only trainers may battle."
if(src.battle!=0)
usr<<"Wait for them to finish their battle."
if(usr.battle!=0)
usr<<"You're still battling!"
if(src.ready==0)
usr<<"Give them a minute, they just battled."
if(src.want==0)
usr<<"They don't want to battle."
else
usr.battle=1
src.battle=1
walk_to(src.x-0,src.y-1)
src.dir=SOUTH
src.battle=usr.id
usr.battle=usr.id
ID:273941
![]() Sep 10 2011, 4:13 am
|
|
Every single var is said to be "Undefined". But I've defined them all right here! What is going on and how do I fix it?
|
![]() Sep 10 2011, 5:12 am
|
|
usr refers to /mob not /mob/trainer. Define variables under /mob or use :
|
Or don't use :, like, ever. Proper type casting is your friend. Just use var/mob/trainer/T = usr, then reference T instead of usr.
|
Zaoshi wrote:
usr refers to /mob not /mob/trainer. Define variables under /mob or use : Echoing Robertbanks2's sentiment, never ever advise someone to use the : operator. There is a time and place for it, but that time never comes for beginners. Defining the vars under /mob is a good option; type-casting works too. However in any case the code won't operate because he used if(src==/mob/trainer) which is always false--since src is a mob and not a type path--whereas he should have used if(istype(src,/mob/trainer)) instead. |
okay, i removed /mob/trainer and just used mob, but after compiling, the src. variables are STILL undefined.
I obviously defined them, does anyone know what's wrong? |
The aforementioned typecasting is still necessary in the case of src because src could be any type of atom, not just /mob. The compiler doesn't take the fact that it can't possibly NOT be a mob due to the conditions of getting there into account, so you still have to specifically tell it what src is.
|
Robertbanks2 wrote:
The aforementioned typecasting is still necessary in the case of src because src could be any type of atom, not just /mob. The compiler doesn't take the fact that it can't possibly NOT be a mob due to the conditions of getting there into account, so you still have to specifically tell it what src is. Actually, src will always be type-casted to the same type as the source object. I'm not sure what the OP did, but I'm guessing he just changed if(src==/mob/trainer) to if(src==/mob)... @OP: If you change your code, and your problem isn't solved, it's helpful to show us the updated code so we can see what you tried. Also, your arguments for walk_to() are incorrect. It's not a mob process, it's a global one, so you need to pass it the atom/movable you actually want to move. See the linked-to reference entry for the arguments. |