Jump to content

Why is GetGroundTypeAtPosition recieving NIL


seronis

Recommended Posts

I'm making a mod to allow you to plant captured rabbits to make rabbit holes in the same manner that you can use butterflies to plant flowers. Just something basic since the similar mod on the steam workshop isnt up to date. 

 

My modmain.lua file contains the following:

local function testground(inst, pt)	local tiletype = GetGroundTypeAtPosition(pt)	local ground_OK = tiletype ~= GROUND.UNDERROCK and tiletype ~= GROUND.IMPASSABLE and tiletype ~= GROUND.ROAD and tiletype ~= GROUND.ROCKY and tiletype ~= GROUND.CARPET and tiletype ~= GROUND.CHECKER and tiletype ~= GROUND.WOODFLOOR		if ground_OK then		return true	end	return falseendlocal function ondeploy(inst, pt)	local hole = GLOBAL.SpawnPrefab("rabbithole")	if hole then		hole.Transform:SetPosition(pt.x, pt.y, pt.z)	end endfunction makePlantable(inst)	inst:AddComponent("stackable")	inst:AddComponent("deployable")	inst.components.deployable.test = testground	inst.components.deployable.ondeploy = ondeployendAddPrefabPostInit("rabbit", makePlantable)

I've looked through the sample mods and based this on how the pinecone prefab was handled. As soon as  "local tiletype = GetGroundTypeAtPosition(pt)" the game crashes saying it recieved a nil value. Looking inside deployable.lua the only place i see the 'test' method called, it recieves a point.

 

Can someone help me understand why im getting this crash?

 

 

-edit-

 

Problem now solved.  Needed to adjust the method call to look like

 

local tiletype = GLOBAL.GetGroundTypeAtPosition(pt)

Link to comment
Share on other sites

its in  ~/.klei   not in   ~/Documents/klei

 

 
../mods/rabbithole/modmain.lua:8: attempt to call global 'GetGroundTypeAtPosition' (a nil value)
LUA ERROR stack traceback:
        ../mods/rabbithole/modmain.lua(8,1) in function 'test'
        scripts/components/deployable.lua(35,1) in function 'CanDeploy'
        scripts/components/deployable.lua(48,1) in function 'CollectPointActions'
        scripts/components/playeractionpicker.lua(67,1) in function 'GetPointActions'
        scripts/components/playeractionpicker.lua(239,1) in function 'GetRightClickActions'
        scripts/components/playeractionpicker.lua(316,1) in function 'DoGetMouseActions'
        scripts/components/playercontroller.lua(474,1) in function 'OnUpdate'
        scripts/update.lua(103,1)
scripts/frontend.lua(479,1) SCRIPT ERROR! Showing error screen
Link to comment
Share on other sites

 

its in  ~/.klei   not in   ~/Documents/klei

 

 
../mods/rabbithole/modmain.lua:8: attempt to call global 'GetGroundTypeAtPosition' (a nil value)
LUA ERROR stack traceback:
        ../mods/rabbithole/modmain.lua(8,1) in function 'test'
        scripts/components/deployable.lua(35,1) in function 'CanDeploy'
        scripts/components/deployable.lua(48,1) in function 'CollectPointActions'
        scripts/components/playeractionpicker.lua(67,1) in function 'GetPointActions'
        scripts/components/playeractionpicker.lua(239,1) in function 'GetRightClickActions'
        scripts/components/playeractionpicker.lua(316,1) in function 'DoGetMouseActions'
        scripts/components/playercontroller.lua(474,1) in function 'OnUpdate'
        scripts/update.lua(103,1)
scripts/frontend.lua(479,1) SCRIPT ERROR! Showing error screen

 

what does it say above that?, since the warning message is just the conflicts not the cause

EDIT; Im unable to help for now since stuff popped up. if your query is not answered by the time I return I'll continue helping

Link to comment
Share on other sites

Complaints about 2 of my character mods i have from the workshop having non 'power of 2' dimension textures and

 

'scripts/mainfunctions.lua(85,1) Can't find prefab rabbit_placer '

 

-edit-

 

That particular warning shows up 30 times so I assumed it was a non fatal thing and unrelated to the crash. 

 

The stack trace I pasted above shows that inst.deployable.test() method is being called and immediately afterwards GetGround...() is called in my local function but it recieves a 'nil' value. This means that  'pt' is nil I assume but pt should have been assigned to a value before it ever reached my mods code.

Link to comment
Share on other sites

Its the exact same method name used in the default 'test' method inside deployable.lua

 

I thought the error was stating that i was calling the method using a nil value, meaning that 'pt' was nil.  Not that the method was returning nil.

Link to comment
Share on other sites

The function call in deployable.lua didnt use the GLOBAL prefix so i assumed it wasnt needed.  Testing now

 

 

 

The one on the workshop may be outdated, but still works.

Thanks for the tip. Subscribed to it and looked at its code. The modder just makes any place valid with no check so avoids the issue im having while making it possible to plant rabbits in wood floors. I think i'll just try to get a proper check working.  

 

 

-edit-

 

Using the global prefix fixed the issue. Thanks for the help

Link to comment
Share on other sites

The function call in deployable.lua didnt use the GLOBAL prefix so i assumed it wasnt needed.  Testing now

 

 

 

Thanks for the tip. Subscribed to it and looked at its code. The modder just makes any place valid with no check so avoids the issue im having while making it possible to plant rabbits in wood floors. I think i'll just try to get a proper check working.  

 

 

-edit-

 

Using the global prefix fixed the issue. Thanks for the help

You have to understand when to use GLOBAL. It simply is the case that you are currently in the MOD space (or whatever real programmers call it) and have thus no direct access to anything which is in the GLOBAL space. The same goes the other way around which is why you cannot simply call things like AddPrefabPostInit from outside modmain.

That means you need the GLOBAL prefix if you are in modmain or modworldgenmain.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...