Jump to content

deleting a ref


Recommended Posts

if your quest no longer needs to point to a string,

you use the command

 

sv_destruct myStringVariable

 

when you no longer need a variable

you can....

 

let myVariable := 0

 

and to remove an array you can

let myArray := ar_null

 

SO........

what do you do when you no longer want to keep a ref?

 

scn TestCase

 

ref myRef

 

begin gamemode

 

let myRef := player.GetPlayersLastRiddenHorse

 

do some stuff with myRef

.

.

.

now no longer need to keep up with myRef

and I want it destroyed/removed/zero'd out so its not in the savegame data

causing extra fluff we don't need

 

 

I'm thinking I just need to set it to zero

let myRef := 0

 

but I'm not sure

 

 

Link to comment
Share on other sites

The answer requires some clarifications:


All variable in your script are 4 bytes long.

All are saved in the savegame, whether they contain a meaninfull value, zero or some garbage.


Some, like ints and floats, contains the value (number) itself (e.g. a conter may contain 0,1,2,3...)

Setting them to zero does not reduce savegame size.


A string_var contains a pointer to the actual string stored elsewhere in memory.

sv_destruct tells the engine (OBSE, in this case) that you dont need that string anymore, therefore the engine will free the memory and will not save that string in the savegame.

The 4-byte string_var itself will be saved.


An array_var also contains a pointer to the actual array stored elsewhere in memory, but it has a more elaborated internal engine.

Arrays are designed/optimized to be used by multiple scripts. In other words, multiple scripts my have string_vars pointing to the same array.

It would not be wise for a script to destroy an array, since other scripts may still need it, so there is no ar_destruct.

Instead, OBSE keeps track of how may array_vars are pointing to the array. When the count reaches zero, the array data is automatically 'destructed' (memory freed, no savegame space).

"let myArray := ..." adds to that count. "let myArray := ar_null" reduces the count.


Ref vars contains the FormID of the reference.

Like other vars, this 4-byte var is saved in the savegame, whether it contains a FormID or zero.


As you see, regarding savegame space, you only have to worry about strings and arrays. Zeroing the other types is pretty much a matter of coding style.


(btw, savegame bloating caused by irresponsible use of PlaceAtMe ia a completey different matter).

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...