ID:2222674
 
(See the best response by Nadrew.)
Code:
statx
var
value=1
max_value=0
mob
var/statx/health

Stat()
statpanel("Stats")
stat("Health:[health.value]")



Im trying to get the jist of how to use this datum stuff yet when i run the game i just returns a error that says null value. Am i not allowed to put the health.value in the stat thing?
You need to actually create a new statx. It's returning null because statx isn't actually associated with anything.

statx
var
value=1
max_value=0
mob
var/statx/health

New()
..()
if(!health) health = new /statx
Stat()
statpanel("Stats")
stat("Health:[health.value]")


You don't even need the "/statx" part when you initialize it. Since the variable is cast to that type it'll be initialized to that type.

health = new()


Would accomplish the same thing without the overhead of a type lookup.
Would accomplish the same thing without the overhead of a type lookup.

Good to know.
would i be able to skip the whole health=new() thing if i added a new() to the statx datum instead or would i have to code every stat as health=new() mana=new() etc
Best response
You need to initialize them one way or another.

var/statx
health = new()
mana = new()
strength = new()


Simply defining a variable with no value means nothing.
if(statpanel("name"))

Not related completely but this will help with performance.
In response to Kozuma3
Kozuma3 wrote:
if(statpanel("name"))

Not related completely but this will help with performance.

This is a bad idea though if you're not doing complex stuff in other statpanels, and it caused enough problems for the webclient that the webclient will always make statpanel(name) return true.

Basically if Stat() is doing a lot of work, you should always consider finding ways to make it do less, like pre-caching most of the data it's going to show. Of course, even better is moving away from Stat() in favor of a HUD.