ID:149891
 
Is it possible to add new stats to a mob? I was thinking of many different ways, but none would work. Could someone tell me if this is even possible? If not, i think it should really be added as a proc or something.

-Rcet
no, you need to have all variables that your program will use before hand, as when its loaded, all the variables are stored into memory and stuff.

You cannot add variables at run time, at least it doesnt seem possible in programming at all to me.

When you compile, you are compiling every possibility in the game that can happen, no matter what. There is no way to add things to the game's source at run time, and adding variables would do just that.

FIREking
Rcet wrote:
Is it possible to add new stats to a mob?

Sort of. You can, but you'd have to predict all new stats in the code... for example, you could have an event in the game that triggers yourself to become a vampire, and you want to have a "Hunger" stat added to your statistics panel. You could do an if statement such as if(vampire), then do the new stats in there. Here's an example.
mob
var
vampire = 0
hp = 30
mp = 30
Stat()
statpanel("Statistics")
stat("HP: [hp] || MP: [mp]")
if(vampire)
stat("Hunger: [hunger]")
statpanel("Inventory",contents)
verb
become_vampire()
vampire = 1

That should work good.

I hope this answers your question.
Rcet wrote:
Is it possible to add new stats to a mob?

Yes. Use an associative list.

mob
var
list/MyStats = list()

proc
// These procs aren't needed to access MyStats, but they demonstrate the idea well.

SetStat(StatName as text, value)
MyStats[StatName] = value

CheckStat(StatName as text)
if(StatName in MyStats)
return MyStats[StatName]
else // no stat of that name
return null

RemoveStat(StatName as text)
MyStats -= StatName

Stat()
..()
if(statpanel("My Stats"))
for(var/stat in MyStats)
stat("[stat]:",MyStats[stat])

In response to Shadowdarke
// These procs aren't needed to access MyStats

OOP would disagree! ;-)