Skip to content

Scripting Question re: Local Variables

After doing a bunch of reading online and plumbing the depths of my imperfect memory, I am feeling confused about local variable storage on inventory items and how persistent I can count on that being on server vault characters between persistent world server resets.

I want this to be true:
For server vault characters, any local variables set on a undroppable, unsellable inventory object can be counted on to remain between server resets. There is no reason to think that the data so-stored could ever be lost accidentally.

Is it true? I will probably implement a database system for things that involve a lot of data, but for simple character-specific things that would be frequently called, I think this is a more efficient way to store data, as long as it will work.

Comments

  • TheAmethystDragonTheAmethystDragon Member Posts: 86
    Yes, it's true. Local variables stored on an item in inventory are saved when the character is saved, and can be read by the game while the character is online, even after a server reset.

    I have used this for my PW for years without a single problem.
  • OmnipsiOmnipsi Member Posts: 31
    Indeed, that is the conventional way of attaining character-specific persistency from my understanding. Some implementations do so using a special skin item, so that it's relatively invisible and inaccessible to the PC, when a visible/usable in-inventory widget isn't necessary.
  • GlassmelterGlassmelter Member Posts: 38
    Thank you, @TheAmethystDragon and @Omnipsi ! :)
  • TheAmethystDragonTheAmethystDragon Member Posts: 86
    Omnipsi said:

    Indeed, that is the conventional way of attaining character-specific persistency from my understanding. Some implementations do so using a special skin item, so that it's relatively invisible and inaccessible to the PC, when a visible/usable in-inventory widget isn't necessary.

    My PW creates/destroys PC "skin" items on a regular basis, so I went with a tiny inventory item (set as plot, stolen, undroppable, and can't be destroyed by players) for each PC. Each builder can go with their own method...but it definitely works. :)

    I use it for 99% or more of character-specific variables. A multitude of in-game options, appearance variables (for returning from shapeshifting), choices and data for certain spells, etc. If I can store it as an INT, STRING, or FLOAT, it can go on that item. Come to think of it, I can't recall more than a handful of scripts I use that set variables on PCs themselves.
  • GlassmelterGlassmelter Member Posts: 38
    Are there known limits re: how many variables can be set on an object? I'm in the planning phase of development and don't want to select this as the method for doing a thing and then have to change it down the road because it's not robust enough.
  • SherincallSherincall Member Posts: 387
    No hard limit, but as you add more, the setlocal/getlocal functions become slower (in CS terms, thry are O(n) operations). I think FunkySwerve hit a noticeable perf drop around 5000 variables.

    In these cases, you can split it across multiple items.
  • FinalStandFinalStand Member Posts: 87
    Can you save local variables directly onto character or does it have to be an item?
  • GlassmelterGlassmelter Member Posts: 38
    You can save them onto a character, but my imperfect understanding is that for some reason, variables on the player object aren't persistent across server resets but that variables on an inventory object are persistent across server resets for server vault characters. I don't know why that is the case, but I read it here:

    http://nwn.wikia.com/wiki/Local_variable
  • highv_priesthighv_priest Member Posts: 50

    You can save them onto a character, but my imperfect understanding is that for some reason, variables on the player object aren't persistent across server resets but that variables on an inventory object are persistent across server resets for server vault characters. I don't know why that is the case, but I read it here:

    http://nwn.wikia.com/wiki/Local_variable

    The biggest reason is that variables on creatures are used consistently by scripts, both new and old(good example is Dirge). So making local variables permanent by creatures would require CONSIDERABLE tracking by PWs to prevent issues of things sticking later on. Whereas with items the only time variables apply is when something would be meant to be permanent anyway.
  • FinalStandFinalStand Member Posts: 87
    How do you test (with local local vault) if your vars are getting stripped on save?
  • FreshLemonBunFreshLemonBun Member Posts: 909
    There is a trello card on the input trello about persistence of character variables.
  • GlassmelterGlassmelter Member Posts: 38

    How do you test (with local local vault) if your vars are getting stripped on save?

    Instead of testing in a single player game, load your module using the nwserver application and log into it over your network as though it were a multiplayer game, connecting via your local IP address. Once you've connected once, it will show up in your history in the multiplayer game index no matter what module you have loaded.
Sign In or Register to comment.