Saving variables on mobs/rooms/objs

Login to reply  Page: « < 1 of 1 > »
19 Feb 2010 - 13:312365
Saving variables on mobs/rooms/objs
How difficult would it be to allow certain mobs to save the variables that are given to them via dg_scripts? Players save variables currently and if a mob is given a new flag MOB_VAR_SAVE it too should be able to save them. I would find this very helpful for player run shops, certain quests and tons of other little things. Has anyone done this?


19 Feb 2010 - 17:362366
Mobs can already save variables to themselves with global. If you want them to save to the mob over reboot there's currently no way to do that, but I can't think of anything that would be possible that way that isn't currently possible.


__________________

Dedicated DG Forum
19 Feb 2010 - 20:212368
yes, im speaking of saving them over reboots.


19 Feb 2010 - 20:432369
what are you trying to do exactly? chances are anything you want saved to the mob would probably have a reasonable workaround via saving to the player


__________________
The Augmented Dimension
( A fantasy hack/slash Circle 3.1 derivative )
frostmud.com 8228

Last edited by Kyle (19 Feb 2010 - 20:45)
20 Feb 2010 - 18:002371
have you ever seen a trigger that saves a variable to the mob that is executing it? For example... I have a mob that checks you when you walk by to see if you have the high score for a trigger based "ski-ball" game on the mud. If you have the high score it lets you know and then saves your ski-ball high score and your name to variables on the mob.

so much like players.... mobs can save information to themselves as variables. But they arent saved in a file like players variables are.

I think if this were possible it would be a huge upgrade for dg scripts... honestly would open tons of doors.


20 Feb 2010 - 19:272372
There are some design issues to consider, though:
We don't really want to store all variables for all instances of all mobs - most of them are not relevant to store. Also, it could be somewhat difficult to set them back up again after a reboot, since IDs for non-players are subject to changes over reboots.

We are really talking about a new scope for variables: "prototype-scope" (as opposed to "local" in a trigger and "global" on a mob/room/object).

To make this, two things need to be written: A setter and a getter.

How about a command like "save_var <varname>" and a corresponding "%self.saved_vars(<varname>)%" getter?

I imagine the setter to simply add to/alter a (sorted tree? hashmap?-)structure in memory, which if changed will be written to disk once per game loop (or each 10 game loops? performance might be an issue here), and the getter just looking up by vnum and varname in the in-memory structure.


__________________
You know who I am.
20 Feb 2010 - 19:302373
Quote welcor:
How about a command like "save_var <varname>" and a corresponding "%self.saved_vars(<varname>)%" getter?

Come to think of it, "persist" and "persisted()" sound better.


__________________
You know who I am.
21 Feb 2010 - 02:562374
I whipped something up. Check the front page : http://www.tbamud.com/content/saving-variables-mobsroomsobjs


__________________
You know who I am.
13 Mar 2010 - 20:062417
Persisted var trouble
here is a little script that reads 3 persisted variables. name, level and class. In line one he is supposed to spit out the name and the level. 2nd line is the class and 3rd is the level.


Puff says, 'saved name var is: Bosstone and lvl var is .' (here, not outputting 2 persisted vars in one sentence)
Puff says, 'vartree saved as Mercenary.'
Puff says, 'vardeuce is: 23'


in the first sentence puff is not outputting the variable vardeuce. he will output it on line 3 but for some reason he wont spit our 2 persisted vars in one sentence.... any ideas?




say saved name var is: %self.persisted(last-player-to-trigger-me)% and lvl var is %self.persisted(vardeuce)%.
say vartree saved as %self.persisted(vartree)%.
say vardeuce is: %self.persisted(vardeuce)%



Last edited by rudeboyrave (13 Mar 2010 - 20:17)
14 Mar 2010 - 01:102419
Apparently the tree (which I regret to say I didn't write myself, so I can't debug it) doesn't like calling TREE_FIND twice in rapid succession. This is one of the things it's reasonably easy to work around though:

eval type1 %self.persisted(type1)%
eval type2 %self.persisted(type2)%
say types are %type1% and %type2%


__________________
You know who I am.
14 Mar 2010 - 02:202420
right on. thanks for this, it is very handy!


14 Mar 2010 - 03:112421
also seems that rooms saved vars cant be recalled... insta crash


14 Mar 2010 - 09:472422
hmm.. that'll probably need a gdb backtrace to debug


__________________
You know who I am.
Login to reply  Page: « < 1 of 1 > »