Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

Kuloslav

Overwrite or update the HandleDeathCleanup function from the gamelogic.lua

Recommended Posts

Kuloslav    21

As in the title, I want to overwrite or update the HandleDeathCleanup function from the gamelogic.lua file without changing the entire file.

The first way to replace (

local require = GLOBAL.require

require "gamelogic"

GLOBAL.HandleDeathCleanup  = function(wilson, data, ...)

    -- Do stuff

end

results in a error when i try activate mod:

scripts/modindex.lua(398,1) Could not load mod_config_data/modconfiguration_test    
scripts/mods.lua(179,1) Loading mod: test (testowy)    
scripts/mods.lua(206,1) Mod: test (testowy)    Loading modworldgenmain.lua    
scripts/mods.lua(214,1) Mod: test (testowy)      Mod had no modworldgenmain.lua. Skipping.    
scripts/mods.lua(206,1) Mod: test (testowy)    Loading modmain.lua    
attempt to call a nil value
LUA ERROR stack traceback:
        =[C] in function 'AddUITransform'
        D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/widgets/widget.lua(11,1) in function '_ctor'
        D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/widgets/broadcastingwidget.lua(6,1) in function '_ctor'
        D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/class.lua(98,1) in function 'BroadcastingWidget'
        D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/gamelogic.lua(20,1) in main chunk
        =[C] in function 'require'
        D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/../mods/test/modmain.lua(3,1) in main chunk
        =[C] in function 'xpcall'
        D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/util.lua(496,1) in function 'RunInEnvironment'
        D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/mods.lua(217,1) in function 'InitializeModMain'
        D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/mods.lua(198,1) in function 'LoadMods'
    ...
        =[C] in function 'SetPersistentString'
        D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/mainfunctions.lua(18,1) in function 'SavePersistentString'
        D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/modindex.lua(76,1)
        =[C] in function 'GetPersistentString'
        D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/modindex.lua(63,1) in function 'BeginStartupSequence'
        scripts/main.lua(277,1) in function 'callback'
        D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/modindex.lua(332,1)
        =[C] in function 'GetPersistentString'
        D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/modindex.lua(312,1) in function 'Load'
        scripts/main.lua(276,1) in main chunk
scripts/mainfunctions.lua(851,1) Error error! We tried displaying an error but TheFrontEnd isn't ready yet...    
scripts/mods.lua(220,1) Mod: test (testowy)      Error loading mod!
...s/common/dont_starve/data/scripts/widgets/widget.lua:345: attempt to index global 'TheFrontEnd' (a nil value)
LUA ERROR stack traceback:
        D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/widgets/widget.lua(345,1) in function 'StartUpdating'
        D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/widgets/broadcastingwidget.lua(11,1) in function '_ctor'
        D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/class.lua(98,1) in function 'BroadcastingWidget'
        D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/gamelogic.lua(20,1) in main chunk
        =[C] in function 'require'
        D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/../mods/test/modmain.lua(3,1) in main chunk
        =[C] in function 'xpcall'
        D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/util.lua(496,1) in function 'RunInEnvironment'
        D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/mods.lua(217,1) in function 'InitializeModMain'
        D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/mods.lua(198,1) in function 'LoadMods'
        scripts/main.lua(233,1) in function 'ModSafeStartup'
        scripts/main.lua(278,1)
        =[C] in function 'SetPersistentString'
        D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/mainfunctions.lua(18,1) in function 'SavePersistentString'
        D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/modindex.lua(76,1)
        =[C] in function 'GetPersistentString'
        D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/modindex.lua(63,1) in function 'BeginStartupSequence'
        scripts/main.lua(277,1) in function 'callback'
        D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/modindex.lua(332,1)
        =[C] in function 'GetPersistentString'
        D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/modindex.lua(312,1) in function 'Load'
        scripts/main.lua(276,1) in main chunk

I also find a different solution for OnPlayerDeath function:
 

GLOBAL.require "playerprofile"
GLOBAL.require "playerdeaths"
GLOBAL.require "saveindex"
GLOBAL.require "screens/mainscreen"
GLOBAL.require "screens/deathscreen"
GLOBAL.require "screens/popupdialog"
GLOBAL.require "screens/bigpopupdialog"
GLOBAL.require "screens/endgamedialog"
GLOBAL.package.loaded.gamelogic = true

 
function GenerateFakeGameLogic()

local f = GLOBAL.io.open("scripts" .. GLOBAL.package.config:sub(1,1) .. "gamelogic.lua", "r") -- Opens gamelogic.lud file into a variable.

GLOBAL.assert(f, "Unable to open gamelogic.lua for reading!")


local fake_game_logic, err = GLOBAL.load(function()
local l = f:read()

    if l then
        return l:gsub('local function OnPlayerDeath', 'function OnPlayerDeath', 1) .. "\n" -- Searches for the "OnPlayerDeath" function. Also pleaces it in a local variable.
    end
end)

f:close()--Closes the file.


if not fake_game_logic then return GLOBAL.error(err) end

GLOBAL.package.loaded.gamelogic = fake_game_logic() or true
GLOBAL.assert( GLOBAL.OnPlayerDeath, "OnPlayerDeath is not global!" )

 --The following code overwrites the OnPlayerDeath function.

GLOBAL.OnPlayerDeath = (function(wilson, data)

    -- Do stuff

end)

end


AddGamePostInit(GenerateFakeGameLogic)

but this return error:

..ps/common/dont_starve/data/scripts/mainfunctions.lua:678: variable 'Profile' is not declared
LUA ERROR stack traceback:
=[C]:-1 in (global) error (C) <-1--1>
D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/strict.lua:23 in () ? (Lua) <21-26>
   t = table: 0E9591B8
   n = Profile
D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/mainfunctions.lua:678 in (global) CheckControllers (Lua) <676-742>
   isConnected = false
D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/mainfunctions.lua:671 in () ? (Lua) <659-673>

scripts/mainfunctions.lua(861,1) LUA ERROR stack traceback:
        D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/mainfunctions.lua(861,1)    
scripts/mainfunctions.lua(862,1) ...ps/common/dont_starve/data/scripts/mainfunctions.lua:678: variable 'Profile' is not declared
LUA ERROR stack traceback:
    =[C]:-1 in (global) error (C) <-1--1>
    D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/strict.lua:23 in () ? (Lua) <21-26>
    D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/mainfunctions.lua:678 in (global) CheckControllers (Lua) <676-742>
    D:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/mainfunctions.lua:671 in () ? (Lua) <659-673>

Is there any way to do this except gamelogic.lua file replacement?

 

 

Share this post


Link to post
Share on other sites