Jump to content

Recommended Posts

Good day everyone. How to write correctly so that the value changes inside the "tuning" script? My code doesn't change the value inside this script.

EXAMPLE:

local MyTable = 
{
  {"tent", TUNING.TENT_USES, MyCustomTent},
  {"siesta", TUNING.SIESTA_CANOPY_USES, MyCustomSiesta},
  ..........................................................................
}

for i = 1, #MyTable, 1 do
  	MyTable[i][2] = MyTable[i][3]
end
  

 

The problem is that you save the tuning value in the table and not the path to the tuning value.

Change it to

local MyTable = 
{
  {"tent", "TENT_USES", MyCustomTent},
  {"siesta", "SIESTA_CANOPY_USES", MyCustomSiesta},
}

for i = 1, #MyTable, 1 do
  	GLOBAL.TUNING[MyTable[i][2]] = MyTable[i][3]
end

and it should work.

  • Like 1
2 hours ago, Monti18 said:

The problem is that you save the tuning value in the table and not the path to the tuning value.

Change it to


local MyTable = 
{
  {"tent", "TENT_USES", MyCustomTent},
  {"siesta", "SIESTA_CANOPY_USES", MyCustomSiesta},
}

for i = 1, #MyTable, 1 do
  	GLOBAL.TUNING[MyTable[i][2]] = MyTable[i][3]
end

and it should work.

Thanks!

And what to do in such situations?

Have trouble:

....
{"CHECKER", 				   "floor", 	GetModConfigData("CheckerFloorChange")},
..........
..........................
elseif (param == "floor" and value) then
		AddPlayerPostInit(function(inst)
			if inst.components.locomotor then
				inst.components.locomotor:SetFasterOnGroundTile(GROUND[value], true)
 --LocoMotor:SetFasterOnGroundTile(ground_tile, is_faster) 
-- GROUND.CHECKER
			end
		end)
string "scripts/components/locomotor.lua"]:414: table index is nil
LUA ERROR stack traceback:
        scripts/components/locomotor.lua(414,1) in function 'SetFasterOnGroundTile'
        ../mods/Configurate Storage(TEST)/modmain.lua(209,1) in function 'fn'
        scripts/modutil.lua(505,1)
        =(tail call) ?
        =[C] in function 'xpcall'
        scripts/mods.lua(169,1) in function 'prefabpostinitany'
        scripts/mainfunctions.lua(322,1)
        =[C] in function 'SendResumeRequestToServer'
        scripts/prefabs/world_network.lua(30,1) in function 'fn'
        scripts/scheduler.lua(177,1) in function 'OnTick'
        scripts/scheduler.lua(371,1) in function 'RunScheduler'
        scripts/update.lua(191,1)	

 

Edited by DiRten
10 hours ago, Monti18 said:

What exactly is value in this context?

Seems like value is nil or GROUND[value] is nil, if you post the entire code I can see where it's going wrong :)

 

 

local ChangeListItems =
{
	{"backpack",	 	 		   "cango",  	GetModConfigData("BackpackCango")},
	{"piggyback",	 			   "cango",  	GetModConfigData("PiggybackCango")},
	{"krampus_sack", 	 		   "cango", 	GetModConfigData("KrampussackCango")},
	{"icepack",	 	 		  	   "cango", 	GetModConfigData("IcepackCango")},
	{"spicepack",	 	 	 	   "cango", 	GetModConfigData("SpicepackCango")},
	{"seedpouch",	 	 		   "cango",     GetModConfigData("SeedpouchCango")},
	{"backpack",	 	 		   "preserver", GetModConfigData("BackpackPerish")},
	{"piggyback",	 	 		   "preserver", GetModConfigData("PiggybackPerish")},
	{"krampus_sack", 	 		   "preserver", GetModConfigData("KrampussackPerish")},
	{"seedpouch",	 	 		   "preserver", GetModConfigData("SeedpouchPerish")},
	{"treasurechest", 	 		   "preserver", GetModConfigData("ChestPerish")},
	{"dragonflychest", 	 		   "preserver", GetModConfigData("DragonflyPerish")},
	{"sisturn", 	 	 		   "preserver", GetModConfigData("SisturnPerish")},
	{"heatrock", 	 	 		   "nofuel", 	GetModConfigData("HeatrockTemperatureInfinityChange")},
    {"flowerhat", 	 			   "speed", 	GetModConfigData("FlowerhatMult")},
	{"goggleshat", 	 	 	   	   "speed", 	GetModConfigData("GoggleshatMult")},
	{"raincoat",     			   "speed",	    GetModConfigData("RaincoatMult")},
	{"yellowamulet", 	 		   "speed", 	GetModConfigData("YellowamuletMult")},
	{"orangestaff",  	 		   "speed",     GetModConfigData("OrangestaffMult")},
	{"PERISH_FRIDGE_MULT",         "tuning",    GetModConfigData("IceboxPerish")},
	{"PERISH_SALTBOX_MULT",        "tuning",    GetModConfigData("SaltboxPerish")},
	{"PERISH_FOOD_PRESERVER_MULT", "tuning",    GetModConfigData("SpicepackPerish")},
	{"TENT_USES",        		   "tuning",    GetModConfigData("TentUsesCount")},
	{"SIESTA_CANOPY_USES",         "tuning",    GetModConfigData("SiestaUsesCount")},
	{"PORTABLE_TENT_USES",         "tuning",    GetModConfigData("PortableTentUsesCount")},
	{"TRAP_USES",        		   "tuning",    GetModConfigData("TrapUsesCount")},
	{"TRAP_TEETH_USES",        	   "tuning",    GetModConfigData("TrapTeethUsesCount")},
	{"TRAP_BRAMBLE_USES",          "tuning",    GetModConfigData("TrapBrambleUsesCount")},
	{"FISHINGROD_USES",       	   "tuning",    GetModConfigData("FishingrodUsesCount")},
	{"BUGNET_USES",        		   "tuning",    GetModConfigData("BugnetUsesCount")},
	{"UMBRELLA_USES",        	   "tuning",    GetModConfigData("UmbrellaUsesCount")},
	{"CANE_SPEED_MULT",        	   "tuning",    GetModConfigData("CaneSpeedMult")},
	{"WOODFLOOR", 				   "floor", 	GetModConfigData("WoodFloorChange")},
	{"CAPRET", 	 		 		   "floor", 	GetModConfigData("CarpetFloorChange")},
	{"CHECKER", 				   "floor", 	GetModConfigData("CheckerFloorChange")}

}
local function Changer(prefabName, param, value)
--tuning
	if param == "tuning" then
		TUNING[prefabName] = value
--Preserver
	elseif (param == "preserver" and value ~= 1) then
		AddPrefabPostInit(
			prefabName,
			function(inst)
				if GLOBAL.TheWorld.ismastersim then
					inst:AddComponent("preserver")
					inst.components.preserver:SetPerishRateMultiplier(value)
				end
			end)
--Cango
	elseif (param == "cango" and value) then
		AddPrefabPostInit(
			prefabName,
			function(inst)
				if GLOBAL.TheWorld.ismastersim then
					inst.components.inventoryitem.cangoincontainer = true
				end
			end)
--Nofuel
	elseif (param == "nofuel" and value) then
		local old_TemperatureChange
		local old_heatrock_fn
		local function new_TemperatureChange(inst, data)
				inst.components.fueled = 
				{
				GetPercent = function() return 1 end,
				SetPercent = function() end,
				}
				old_TemperatureChange(inst, data)
				inst.components.fueled = nil
			  end
		local function new_heatrock_fn(inst)
				if GLOBAL.TheWorld.ismastersim then
					inst:RemoveComponent("fueled")
					local function switchListenerFns(t)
							local listeners = t["temperaturedelta"]
							local listener_fns = listeners[inst]
							old_TemperatureChange = listener_fns[1]
							listener_fns[1] = new_TemperatureChange
						  end
					switchListenerFns(inst.event_listeners)
					switchListenerFns(inst.event_listening)
				end
			  end
		AddPrefabPostInit(prefabName, new_heatrock_fn)
--Speed
	elseif param == "speed" then 
		if value ~= 1 then
			AddPrefabPostInit(
				 prefabName,
				 function(inst)
					if GLOBAL.TheWorld.ismastersim then
						inst.components.equippable.walkspeedmult = value
					end
				end)
		end
	elseif param == "floor"  then
		AddPlayerPostInit(function(inst)
			if (inst.components.locomotor and value) then
			inst.components.locomotor:SetFasterOnGroundTile(GROUND[prefabName], true)
			end
		end)
	end
end
for i = 1, #ChangeListItems, 1 do
	Changer(ChangeListItems[i][1], ChangeListItems[i][2], ChangeListItems[i][3])
end

ERROR:

[00:00:33]: [string "scripts/components/locomotor.lua"]:414: table index is nil
LUA ERROR stack traceback:
        scripts/components/locomotor.lua(414,1) in function 'SetFasterOnGroundTile'
        ../mods/Tets/modmain.lua(213,1) in function 'fn'
        scripts/modutil.lua(505,1)
        =(tail call) ?
        =[C] in function 'xpcall'
        scripts/mods.lua(169,1) in function 'prefabpostinitany'
        scripts/mainfunctions.lua(322,1)
        =[C] in function 'SendResumeRequestToServer'
        scripts/prefabs/world_network.lua(30,1) in function 'fn'
        scripts/scheduler.lua(177,1) in function 'OnTick'
        scripts/scheduler.lua(371,1) in function 'RunScheduler'
        scripts/update.lua(191,1)	

 

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...