Global nil value when loading mod
Posted: Tue Apr 17, 2018 11:54 am
I have a mod that changes some gun sounds. Everthing works properly. Now that i wanted to add mod settings i am encountering a problem where i get an error message saying i'm trying to index a nil value (see image below). As one can see i have 5 global bool settings that change if a sound gets replaced or not (Submachine gun, Pistol, Shotgun, Combatshotgun and turret). That too works as planned except for the turret (It does get replaced too but the settings bring the trouble). When i comment out the turret part in the data.lua (see below) the settings work just fine (turning sound replacement on and off). But when i uncomment the turret part i get the error from the image below. Anyone who can help?
Code in the settings.lua
Code in the data.lua
Code in the settings.lua
Code: Select all
data:extend({
{
type = "bool-setting",
name = "wsr-replace-submg-sound",
--localised_name = ,
setting_type = "startup",
default_value = true
},
{
type = "bool-setting",
name = "wsr-replace-pistol-sound",
--localised_name = ,
setting_type = "startup",
default_value = true
},
{
type = "bool-setting",
name = "wsr-replace-shotg-sound",
--localised_name = ,
setting_type = "startup",
default_value = true
},
{
type = "bool-setting",
name = "wsr-replace-cshotg-sound",
--localised_name = ,
setting_type = "startup",
default_value = true
},
{
type = "bool-setting",
name = "wsr-replace-turret-sound",
--localised_name = ,
setting_type = "startup",
default_value = true
}
})
Code: Select all
if settings.startup["wsr-replace-submg-sound"].value then
data.raw.gun["submachine-gun"].attack_parameters.sound =
{
filename = "__weaponSoundsRedone__/sounds/submachine_fire.ogg",
volume = 0.8
}
else
data.raw.gun["submachine-gun"].attack_parameters.sound =
{
{
filename = "__base__/sound/fight/light-gunshot-1.ogg",
volume = 0.3
},
{
filename = "__base__/sound/fight/light-gunshot-2.ogg",
volume = 0.3
},
{
filename = "__base__/sound/fight/light-gunshot-3.ogg",
volume = 0.3
}
}
end
if settings.startup["wsr-replace-pistol-sound"].value then
data.raw.gun.pistol.attack_parameters.sound =
{
filename = "__weaponSoundsRedone__/sounds/pistol_fire.ogg",
volume = 0.5
}
else
data.raw.gun.pistol.attack_parameters.sound =
{
{
filename = "__base__/sound/fight/light-gunshot-1.ogg",
volume = 0.3
},
{
filename = "__base__/sound/fight/light-gunshot-2.ogg",
volume = 0.3
},
{
filename = "__base__/sound/fight/light-gunshot-3.ogg",
volume = 0.3
}
}
end
if settings.startup["wsr-replace-shotg-sound"].value then
data.raw.gun.shotgun.attack_parameters.sound =
{
filename = "__weaponSoundsRedone__/sounds/shotgun_fire.ogg",
volume = 0.6
}
else
data.raw.gun.shotgun.attack_parameters.sound =
{
filename = "__base__/sound/pump-shotgun.ogg",
volume = 0.5
}
end
if settings.startup["wsr-replace-cshotg-sound"].value then
data.raw.gun["combat-shotgun"].attack_parameters.sound =
{
filename = "__weaponSoundsRedone__/sounds/autoshotgun_fire.ogg",
volume = 0.8
}
else
data.raw.gun["combat-shotgun"].attack_parameters.sound =
{
filename = "__base__/sound/pump-shotgun.ogg",
volume = 0.5
}
end
if setting.startup["wsr-replace-turret-sound"].value then
data.raw["ammo-turret"]["gun-turret"].attack_parameters.sound =
{
filename = "__weaponSoundsRedone__/sounds/turret_fire.ogg",
volume = 0.5
}
else
data.raw["ammo-turret"]["gun-turret"].attack_parameters.sound =
{
{
filename = "__base__/sound/fight/heavy-gunshot-1.ogg",
volume = 0.45
},
{
filename = "__base__/sound/fight/heavy-gunshot-2.ogg",
volume = 0.45
},
{
filename = "__base__/sound/fight/heavy-gunshot-3.ogg",
volume = 0.45
},
{
filename = "__base__/sound/fight/heavy-gunshot-4.ogg",
volume = 0.45
}
}
end