Need help storing a global variable into the savegame

xQd
Scavenger
Posts: 20
Joined: 11 Jul 2017, 14:56

Need help storing a global variable into the savegame

Postby xQd » 20 Jul 2017, 18:32

I am trying to make the value of a variable persistent across saves but I always end up crashing when saving and then loading that save.

Here is how I try to save the value of the variable: utils.save_var(db.actor,"warfare_escort_task_smart",sname) where sname is a name of a smart terrain.

Here is how I try to access the "warfare_escort_task_smart" variable in other script files: utils.load_var(db.actor,"warfare_escort_task_smart").

I start a new game and everything seems fine, the "warfare_escort_task_smart" has the correct value when called with load_var method, but if I save the game and then load it, it always crashes with this error:

Code: Select all

! [LUA] SCRIPT RUNTIME ERROR
! [LUA] ...on\stalker call of pripyat\gamedata\scripts\utils.script:796: attempt to index local 'obj' (a nil value)
! [SCRIPT ERROR]: ...on\stalker call of pripyat\gamedata\scripts\utils.script:796: attempt to index local 'obj' (a nil value)
 
FATAL ERROR
 
[error]Expression    : <no expression>
[error]Function      : CScriptEngine::lua_error
[error]File          : ..\xrServerEntities\script_engine.cpp
[error]Line          : 189
[error]Description   : fatal error
[error]Arguments     : LUA error: ...on\stalker call of pripyat\gamedata\scripts\utils.script:796: attempt to index local 'obj' (a nil value)


The "obj" seems to be the first parameter of the load_var method. It cannot be nil since I used db.actor, which is always online.

User avatar
Alundaio
S.T.A.L.K.E.R.
Posts: 1371
Joined: 26 May 2012, 22:26

Re: Need help storing a global variable into the savegame

Postby Alundaio » 21 Jul 2017, 02:47

When and where are you calling load_var? If db.actor is nil then it's being used before actor net spawn (aka on_game_load) is called.
"I have a dream that one day this community will rise up and live out the true meaning of its creed: "We hold these truths to be self-evident; that all mods are created equal."

xQd
Scavenger
Posts: 20
Joined: 11 Jul 2017, 14:56

Re: Need help storing a global variable into the savegame

Postby xQd » 21 Jul 2017, 03:58

load_var is called inside dialogs_darkvalley.script, dialogs_jupiter.script, dialogs_marsh.script and task_functor.script.

EDIT: Weird, I replaced all the instances of

Code: Select all

utils.load_var(db.actor,"warfare_escort_task_smart")

with

Code: Select all

db.actor and utils.load_var(db.actor,"warfare_escort_task_smart")


It works now, I can save the game and reload without any problems and the value of the variable is loaded correctly.


Return to “General Discussion”

Who is online

Users browsing this forum: Bing [Bot] and 1 guest