Jump to content

Recommended Posts

I'm currently trying to build a mod that auto populates a table of all the spawnable prefabs in the game but I can't seem to get a function working that will return a boolean value if the prefab is spawnable

 

I based this off of the SpawnPrefabFromSim() function which seems to be able to check what I want

local function checkPrefab(prefab)    if prefab == nil or prefab =="rubble" then			return false    end        local inst = prefab.fn(TheSim)    if inst ~= nil then                    return true    else  		print( "Does not exist", name )    	return false     endendfor key,value in pairs(GLOBAL.Prefabs) do 		print(checkPrefab(value))end

This should return true or false as a list for each prefab but instead it crashes.

..data/scripts/components/named.lua:28: bad argument #1 to 'upper' (string expected, got nil)
LUA ERROR stack traceback:
        =[C] in function 'upper'
..data/scripts/components/named.lua(28,1) in function 'SetName'
..data/scripts/prefabs/rubble.lua(72,1) in function 'common_fn'
..data/scripts/prefabs/rubble.lua(81,1) in function 'fn'
..data/../mods/n_tools/modmain.lua(402,1) in function 'checkPrefab'
..data/../mods/n_tools/modmain.lua(428,1) in function 'wish'
..data/../mods/n_tools/modmain.lua(557,1) in function 'onclick'
..data/scripts/widgets/button.lua(37,1) in function 'OnControl'
..data/scripts/widgets/widget.lua(112,1) in function 'OnControl'
..data/scripts/widgets/widget.lua(112,1) in function 'OnControl'
..data/scripts/widgets/widget.lua(112,1) in function 'OnControl'
..data/scripts/widgets/widget.lua(112,1) in function 'OnControl'
..data/scripts/widgets/widget.lua(112,1) in function 'OnControl'
..data/scripts/widgets/widget.lua(112,1) in function 'OnControl'
..data/scripts/widgets/widget.lua(112,1) in function 'OnControl'
..data/scripts/screens/playerhud.lua(254,1) in function 'OnControl'
..data/scripts/frontend.lua(105,1) in function 'OnControl'
..data/scripts/input.lua(127,1) in function 'OnControl'
..data/scripts/input.lua(301,1)

Anyone have any suggestions? It would be much appreciated.

Link to comment
https://forums.kleientertainment.com/forums/topic/29339-need-a-bit-of-help/
Share on other sites

  • Developer

I'm currently trying to build a mod that auto populates a table of all the spawnable prefabs in the game but I can't seem to get a function working that will return a boolean value if the prefab is spawnable

 

I based this off of the SpawnPrefabFromSim() function which seems to be able to check what I want

local function checkPrefab(prefab)    if prefab == nil or prefab =="rubble" then			return false    end        local inst = prefab.fn(TheSim)    if inst ~= nil then                    return true    else  		print( "Does not exist", name )    	return false     endendfor key,value in pairs(GLOBAL.Prefabs) do 		print(checkPrefab(value))end

This should return true or false as a list for each prefab but instead it crashes.

..data/scripts/components/named.lua:28: bad argument #1 to 'upper' (string expected, got nil)
LUA ERROR stack traceback:
        =[C] in function 'upper'
..data/scripts/components/named.lua(28,1) in function 'SetName'
..data/scripts/prefabs/rubble.lua(72,1) in function 'common_fn'
..data/scripts/prefabs/rubble.lua(81,1) in function 'fn'
..data/../mods/n_tools/modmain.lua(402,1) in function 'checkPrefab'
..data/../mods/n_tools/modmain.lua(428,1) in function 'wish'
..data/../mods/n_tools/modmain.lua(557,1) in function 'onclick'
..data/scripts/widgets/button.lua(37,1) in function 'OnControl'
..data/scripts/widgets/widget.lua(112,1) in function 'OnControl'
..data/scripts/widgets/widget.lua(112,1) in function 'OnControl'
..data/scripts/widgets/widget.lua(112,1) in function 'OnControl'
..data/scripts/widgets/widget.lua(112,1) in function 'OnControl'
..data/scripts/widgets/widget.lua(112,1) in function 'OnControl'
..data/scripts/widgets/widget.lua(112,1) in function 'OnControl'
..data/scripts/widgets/widget.lua(112,1) in function 'OnControl'
..data/scripts/screens/playerhud.lua(254,1) in function 'OnControl'
..data/scripts/frontend.lua(105,1) in function 'OnControl'
..data/scripts/input.lua(127,1) in function 'OnControl'
..data/scripts/input.lua(301,1)

Anyone have any suggestions? It would be much appreciated.

Could you upload your whole mod for me to take a look?

Could you upload your whole mod for me to take a look?

 

Here you go, n_tools_1.3_working.zip

 

 

Edit: btw just noticed the  or prefab =="rubble" in there, its not actually in the file that was something i was trying to fix the issue (it didn't work).

Edited by Nycidian
  • Developer

Here you go, attachicon.gifn_tools_1.3_working.zip

 

 

Edit: btw just noticed the  or prefab =="rubble" in there, its not actually in the file that was something i was trying to fix the issue (it didn't work).

The same error happens if you just try and spawn the prefab so I think you've just found a prefab that's actually broken and doesn't get used in the game.  I think you'll just have to skip over it when iterating through the prefabs.

The same error happens if you just try and spawn the prefab so I think you've just found a prefab that's actually broken and doesn't get used in the game.  I think you'll just have to skip over it when iterating through the prefabs.

Before I reply let me say I appreciate the help.

 

Alright I figured out that problem but ended up with another one which I again fixed and ended up with a final problem that I can't figure out here is the updated mod and the crash log. The game is completely crashing after successfully checking hundreds of prefabs I'm not sure why.

 

n_tools_1.31_working.ziplog.txt

 

Edit: NM, I figured out how to do it piece meal. Thanks for all of the help.

Edited by Nycidian

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