Jump to content

Recommended Posts

I feel like I'm going insane.  I'm working on a mod that, among other things, adjusts the working area of the WOBOT/WINbot.  That part works fine, but I'm having trouble understanding what the hell is going on when I try to adjust the range of the placer preview.

If I hard-code the range like so, it works fine for that range, but obviously doesn't change when the mod settings are changed to a different range:

local WorkRange = GetModConfigData("WORK_RANGE")
...
AddPrefabPostInit("winona_storage_robot_placer", function(inst) --winona_storage_robot.lua uses a 10 wall-tile placer scaled up by 1.5 to get a 15 tile ring
	inst.AnimState:SetScale(2, 2) --this creates a 20 wall-tile radius placer, as expected, which is perfect if WorkRange is set to 20
end)

 

However, when I replaced (2, 2) with a variable, things fell apart and I got a ring much larger than expected:

local WorkRange = GetModConfigData("WORK_RANGE") --this is currently set to 20...
local PlacerScale = WorkRange/10 --...so this should be set to 2
...
AddPrefabPostInit("winona_storage_robot_placer", function(inst)
	inst.AnimState:SetScale(PlacerScale, PlacerScale) --this creates a 35 wall-tile radius placer.  Why?
end)

 

So adding some print statements for debugging got me here:

local WorkRange = GetModConfigData("WORK_RANGE") 
local PlacerScale = WorkRange/10 
...
print ("PlacerScale:")
print(PlacerScale) --this prints "2" to the server_log as expected
print(type(PlacerScale)) --this prints "number" to the server_log as expected

AddPrefabPostInit("winona_storage_robot_placer", function(inst)
    print ("PlacerScale inside postinit:")
	print(PlacerScale) --this prints "3.5" to the console.  Where the hell did "3.5" come from?
	print(type(PlacerScale)) --prints "number" to the console as expected
	inst.AnimState:SetScale(PlacerScale, PlacerScale) --this creates a 35 wall-tile radius placer, which is correct if PlacerScale is 3.5 but WHY IS IT 3.5!?!?  I'm going to gnaw my hands off
end)

 

Further testing reveals that if I directly set the value of PlacerScale, things work, but that defeats the purpose of PlacerScale being a variable:

local WorkRange = GetModConfigData("WORK_RANGE")
local PlacerScale = 2
...
print ("PlacerScale:")
print(PlacerScale) --this prints "2" to the server_log as expected
print(type(PlacerScale)) --this prints "number" to the server_log as expected

AddPrefabPostInit("winona_storage_robot_placer", function(inst)
    print ("PlacerScale inside postinit:")
	print(PlacerScale) --this prints "2" to the console as expected
	print(type(PlacerScale)) --prints "number" to the console as expected
	inst.AnimState:SetScale(PlacerScale, PlacerScale) --this creates a 20 wall-tile radius placer, as it should
end)

 

So after beating my head against this for hours, I decided I was defeated, and I would just accept I couldn't do arithmetic to my variable... but I COULD make an ugly if-elseif block that would just manually set the value.  Guess what for some reason DIDN'T work?

local WorkRange = GetModConfigData("WORK_RANGE") --set to 20 for this example
local PlacerScale
...
if WorkRange == 15 then --I'm disgusted that I gave up and tried this, and even more disgusted that it still didn't work
    PlacerScale = 1.5
elseif WorkRange == 20 then
    PlacerScale = 2.0
elseif WorkRange == 25 then
    PlacerScale = 2.5
elseif WorkRange == 30 then
    PlacerScale = 3.0
elseif WorkRange == 35 then
    PlacerScale = 3.5
elseif WorkRange == 40 then
    PlacerScale = 4.0
elseif WorkRange == 45 then
    PlacerScale = 4.5
end

print ("PlacerScale:")
print(PlacerScale) --this prints "2" to the server_log as expected
print(type(PlacerScale)) --this prints "number" to the server_log as expected

AddPrefabPostInit("winona_storage_robot_placer", function(inst)
    print ("PlacerScale inside postinit:")
	print(PlacerScale) --this prints "3.5" to the console and I want to scream
	print(type(PlacerScale)) --prints "number" to the console as expected
	inst.AnimState:SetScale(PlacerScale, PlacerScale) --this creates a 35 wall-tile radius placer.  I'm going to kill a hostage.
end)

I've tried using TUNING values, I've tried gratuitous tonumer() tomfoolery, I've tried stuff too stupid to list, and I still can't get my placer sized correctly.  Any help is appreciated.

winbottweak.zip

  • Like 1

try putting all_clients_require_mod = true in modinfo.lua then rejoin the server

it may be setting it to another value in your mod config cause of that.

this is how i would personally approach changing winbot range

modinfo.lua

Spoiler
{
        name = "WORK_RANGE",
        label = "Winbot Working Radius",
	    hover = "How far the bots will search for items/containers, measured in wall tiles",
        options = {
		    {description = "Default", data = false}, -- we dont know if this will be changed in the future, but you can put 15 in the hover if u want
    		{description = "15", data = 15},
		    {description = "20", data = 20},
		    {description = "25", data = 25},
		    {description = "30", data = 30},
		    {description = "35", data = 35},
		    {description = "40", data = 40},
		    {description = "45", data = 40},
	    },
  		default = 20, -- you only need one default value, i usually put it at the end
    },

 

there is a way to put TUNING in mod config, i detailed how to edit config strings within modmain but it's up to you if you want to go through the trouble in doing that.

modmain.lua

Spoiler
local WORK_RANGE = GetModConfigData"WORK_RANGE"
if WORK_RANGE then
	TUNING.WINONA_STORAGE_ROBOT_WORK_RADIUS = WORK_RANGE -- existing tuning value
	TUNING.WINONA_STORAGE_ROBOT_PLACER_SCALE =  WORK_RANGE/10 -- new tuning value
	AddPrefabPostInit("winona_storage_robot_placer", function(inst)
		local PLACER_SCALE = TUNING.WINONA_STORAGE_ROBOT_PLACER_SCALE
		inst.AnimState:SetScale(PLACER_SCALE, PLACER_SCALE)
	end)
end

also could suggest putting all value(s) you're tweaking in TUNING because it does no harm if named well and you can check whether the tuning is different on Remote and Local console commands

Edited by oregu
  • Thanks 1
19 hours ago, oregu said:

try putting all_clients_require_mod = true in modinfo.lua then rejoin the server

askjdhsjfleagukhjlaeigkjhbnaeslkjghbaelkvaWrgertg

THANK YOU

That was literally all it took.  I spent so long screwing with this that I started feeling like I was going insane, and you hit the nail on the head first go.  You are a saint.

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