Jump to content

Recommended Posts

I was testing my music mod by following a youtube tutorial but now upon death and fading out it crashes with this error. I tried fiddling with dynamic music.lua but I just ended up breaking it more. Youtube keeps deleting my comments when I tried messaging the video's creator.

Rev. 562556 WIN32_STEAM WARNING!
[string "../mods/workshop-3008939982/scripts/compone..."]:197: attempt to index local 'player' (a nil value) LUA ERROR stack traceback:
../mods/workshop-3008939982/scripts/components/dynamic music.lua:197 in (upvalue) IsOnLunarIsland (Lua) <196-199> 
../mods/workshop-3008939982/scripts/components/dynamicmusic.lua:238 in (upvalue) StartBusy (Lua) <219-271> 
../mods/workshop-3008939982/scripts/components/dynamicmusic.lua:424 in (upvalue) StopDanger (Lua) <407-427> 
../mods/workshop-3008939982/scripts/components/dynamicmusic.lua:709 in (upvalue) StopSoundEmitter (Lua) <707-721> 
../mods/workshop-3008939982/scripts/components/dynamicmusic.lua:746 in (local) fn (Lua) <742-748> scripts/entityscript.lua:1152 in (method) PushEvent (Lua) <1139-1166>
scripts/prefabs/player_common.lua:696 in (upvalue) Deactivate Player (Lua) <681-698> scripts/prefabs/player_common.lua:1084 in (method) OnRemoveEntity (Lua) <1041-1086>
This error may have occurred due to a mod you have enabled!

20230724144412_1.jpg

dynamicmusic.lua

When it fades out, the player no longer exists (becoming a nil value)

It crashes when the code gets to line 197 and tries to index the given player variable, which at this point is nil. It can't look at the components of a nil variable and therefore crashes. To prevent this, in the return statement in IsOnLunarIsland prepend 'player ~= nil and' to it

 return player ~= nil and player.components.areaaware ~= nil
        and player.components.areaaware:CurrentlyInTag("lunacyarea")

 

Thanks!!! That fixed the crashing but do I need to do the same for these functions?

line 191:

local function IsInRuins(player)
    return player.components.areaaware ~= nil
        and player.components.areaaware:CurrentlyInTag("Nightmare")

line 562:

local function IsInRuins(player)
    return player.components.areaaware ~= nil
        and player.components.areaaware:CurrentlyInTag("Nightmare")

line 567:

local function IsOnLunarIsland(player)
    return player.components.areaaware ~= nil
        and player.components.areaaware:CurrentlyInTag("lunacyarea")

7 hours ago, Warioman said:

Thanks!!! That fixed the crashing but do I need to do the same for these functions?

line 191:

local function IsInRuins(player)
    return player.components.areaaware ~= nil
        and player.components.areaaware:CurrentlyInTag("Nightmare")

line 562:

local function IsInRuins(player)
    return player.components.areaaware ~= nil
        and player.components.areaaware:CurrentlyInTag("Nightmare")

line 567:

local function IsOnLunarIsland(player)
    return player.components.areaaware ~= nil
        and player.components.areaaware:CurrentlyInTag("lunacyarea")

Possibly, yes. It doesn't hurt anything to add the check for each to make sure it will catch that problem each time

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...