Global nil value when loading mod

Place to get help with not working mods / modding interface.
M.Colcko
Inserter
Inserter
Posts: 21
Joined: Sun Dec 04, 2016 7:23 am
Contact:

Global nil value when loading mod

Post by M.Colcko »

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: 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 in the data.lua

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
Attachments
Error message
Error message
2018-04-17.png (15.75 KiB) Viewed 1358 times
betrok
Fast Inserter
Fast Inserter
Posts: 101
Joined: Wed Feb 28, 2018 12:08 pm
Contact:

Re: Global nil value when loading mod

Post by betrok »

It points directly to line with error... data.lua, line 77. 'setting' instead of 'settings'
M.Colcko
Inserter
Inserter
Posts: 21
Joined: Sun Dec 04, 2016 7:23 am
Contact:

Re: Global nil value when loading mod

Post by M.Colcko »

Oh my god how did i not see that...
Post Reply

Return to “Modding help”