ID:245506
 
Keywords: panel, stat
(See the best response by DarkCampainger.)
Code:
mob
Stat()
statpanel ("Animals")
stat ("Water: [thirst]")
mob

var
thirst = 100

animals
Chicken
icon = 'icon/animals.dmi'
icon_state = "chicken"
layer = 100
New()
..()
while(src)
sleep(10)
if(src)
if(thirst <= 0)
world << "[src] gets sick!"
continue
else
thirst -= 10
world << "[src] gets thirstier!"


Problem description:
hello...I have only been DM coding for a short time, a few months..right now I am so freaking frustrated at this code i just want to throw my computer at the wall. I have tried everything i could possibly think of for someone that has been coding for 5months... for some reason it is not displaying the animals water on the statpanel. This seems so basic i'm embarrassed of coming here..

Heres what it my code does..
1. when a new chicken is created
2. start a loop that subtracts from the animals thirst
3. i have it set to sleep for 1 second for testing purposes.
4. if the chicken has less than or equal to zero thirst
5. it gets sick (then it will continue to subtract from the chickens health until it gets deleted but i haven't coded that in yet)

This all works. except one freaking thing!!! The Animal stat panel doesn't show the animals thirst subtracting! It just shows Water: 100 and remains 100 while the chicken runs its loop...

What could i possibly be doing wrong! this is so frustrating ive tried so many ways! If its something super simple im going to leap off a bridge and im taking this computer with me!
Best response
Unless the player IS the chicken, you're displaying the wrong object's thirst variable. When you just use the variable name without specifying what object you're accessing, it defaults to src (which is the player in the case of your mob/Stat() process).

You need to get a reference to the chicken to display its specific thirst value. Unless your player has a list of owned animals, you'll probably want to loop through the world or view() and get each animal.

mob
Stat()
statpanel("Animals")
for(var/mob/animals/A in view(5,src)) // Loop through all of the /mob/animals types within a view of 5 tiles from the player
stat(A) // Display the animal
stat("Water:[A.thirst]") // Display its thirst
Oh, i see! thank you :D