Running the code results in runtime error: bad index
Code Snippet (if applicable) to Reproduce Problem:
#define ADD_STAT(ID,VALUE) stats[ID] = new/value_range(VALUE,VALUE)
value_range
var min
var max
New(min,max=min)
src.min = min
src.max = max
proc
operator+=(value=0)
min += value
if(min > max){min = max}
return min
operator-=(value=0)
min -= value
world << "value is now [min]"
if(0 > min){min = 0}
return min
stats
var list/stats = new
proc
operator[](ID)
return stats[ID]
//
player/New()
ADD_STAT("Health", 99)
ADD_STAT("Attack", 99)
ADD_STAT("Strength", 99)
ADD_STAT("Defense", 99)
ADD_STAT("Cooking", 99)
ADD_STAT("Woodcutting", 99)
ADD_STAT("Firemaking", 99)
npc/New()
ADD_STAT("Health", 3)
ADD_STAT("Attack", 1)
ADD_STAT("Strength", 1)
ADD_STAT("Defense", 1)
mob/var/stats/stats = new/stats/player
mob/Login()
var min = stats["Health"].min
var max = stats["Health"].max
world << "Your Health is [min]/[max]"
stats["Health"] -= 10
Expected Results:
No runtime
Actual Results:
Runtime
can be replaced with
And still works O_O