ID:157502
 
Is it possible to restore all of the variables of a mob?
like:
mob/techniques
var/specialmagic = 30
var/coolmagic = 20

Now, lets say I used specialmagic 5 times, and coolmagic 3 times, which now would be 25,17.
Is it possible to make a proc or verb which will restore these vars to it's orginal numbers? I haven't gotten any idea of how to make it possible.
When I mean it like this, I don't want to have to do something like

mob/verb
specialmagic = 30
coolmagic = 20

Repeating all of the variables just to restore lots of variables would make the code pretty big...
Or is that the only way?

Thanks...
Enic wrote:
Is it possible to restore all of the variables of a mob?
like:
mob/techniques
> var/specialmagic = 30
> var/coolmagic = 20

Now, lets say I used specialmagic 5 times, and coolmagic 3 times, which now would be 25,17.
Is it possible to make a proc or verb which will restore these vars to it's orginal numbers? I haven't gotten any idea of how to make it possible.
When I mean it like this, I don't want to have to do something like

> mob/verb
> var/specialmagic = 30
> var/coolmagic = 20

Repeating all of the variables just to restore lots of variables would make the code pretty big...

Thanks...

If they're always going to be 30 and 20

var/coolmagic = 20
var/specialmagic = 30

mob/verb/restore()
coolmagic = 20
specialmagic = 30

and if you have more just add them to the list.
Look up initial()in the DM reference.
In response to Blafblabla
You have little-to-no experience. Please don't try and provide advice.
In response to Popisfizzy
Good point. I won't.
In response to Stephen001
Blafblabla wrote:
If they're always going to be 30 and 20

var/coolmagic = 20
> var/specialmagic = 30
>
> mob/verb/restore()
> coolmagic = 20
> specialmagic = 30

and if you have more just add them to the list.
That was what I didn't want to do...

Stephen001 wrote:
Look up initial()in the DM reference.
Thanks, I'll do once I'm back home.
In response to Enic
So I'd use it like this?
mob/verb/restore()
specialmagic=initial(specialmagic)
coolmagic=initial(coolmagic)


Well... It wouldn't make more difference than just putting numbers in... Isn't it possible to make all vars in a group to its default? Instead of having thoose two lines, wouldn't it be possible to make it in one line and that one line would restore both?
In response to Enic
mob/player/proc/restore_all()
for(var/v in src.vars)
src.vars[v] = initial(src.vars[v])


But as someone pointed out this would reset vars that you don't want to reset. Wasn't really thinking about it. So, forget I said anything, and go with Garthor or Stephen. =)
In response to Ulterior Motives
Ooh... I see, thanks.
Edit: Actually... Now when I'm trying that, it doesn't work...
In response to Enic
It won't work, mostly because v is the variable name as text, and not the variable itself. There is a big problem with that approach in general though, mobs have a lot of variables which you won't want to call initial() on. For example, initial() on the following if permitted would give you obvious problems:
  • mob.client - Will restore to compile-time null value
  • mob.loc - Will restore to (probably) compile-time 0,0,0 location
  • mob.key - Will restore to compile-time null value

The location is perhaps the big issue for what I believe you are using the mobs for.

Essentially it is safer and more pragmatic to write a restore() proc that calls initial() on the variables you actually want to return to their compile-time values. This still has the benefit over literally assigning the values in that if you decide to change the starting values, you only need to change them in one place.
In response to Stephen001
Yeah... Well, isn't it possible to make a group of variables, and then use initial() to restore thoose who are in this group? However, I don't know how to make variable groups... If it's even possible..
In response to Enic
A datum works, a la:

condition
var
amount = 30
area = 2

mob/effect
var
condition/someGroup = new()

proc
restoreGroup()
someGroup = new()

addAmount(var/X)
someGroup.amount += X


A datum is pretty much anything you want it to be, programmatically. Basically it has no position on the map, no icon etc etc.
In response to Enic
You can create a subset of the vars list and reset it in the same way. So, for example:

mob
var/health
var/mana
var/list/reset_vars = list("health", "mana")
proc/reset()
for(var/v in reset_vars)
vars[v] = initial(vars[v])
In response to Garthor
I see, thanks. That worked fine :)

My resting proc jumped from 51 lines to 26 lines. And it'll alot easier to put new vars to reset
In response to Garthor
That list (and var) shouldn't generally be on every mob, as only one instance of it should be needed. So it should be declared either globally or local to the proc.