Jump to content

Recommended Posts

local function PPP(inst)
		TheInput:AddKeyDownHandler(292, function()
			function PickAxeChop(inst) 
				print('This is not executed.')
				inst.components.tool:SetAction(ACTIONS.MINE, 15)
			end
			function PickAxeChopOff(inst) 
				print('This is not executed.')
				inst.components.tool:SetAction(ACTIONS.MINE, 1)
			end

			if not GetPlayer():HasTag("tfast") then GetPlayer():AddTag("tfast")
				AddPrefabPostInit( "pickaxe", PickAxeChop )    --Why not executed here
				AddPrefabPostInit( "goldenpickaxe", PickAxeChop )
				inst.components.talker:Say("Fast PickAxe [On]")
			elseif GetPlayer():HasTag("tfast") then GetPlayer():RemoveTag("tfast")
				AddPrefabPostInit( "pickaxe", PickAxeChopOff )
				AddPrefabPostInit( "goldenpickaxe", PickAxeChopOff )
				inst.components.talker:Say("Fast PickAxe [Off]")
				
			end
		end)
	end
	AddSimPostInit( PPP )

I need a function to implement the keys to dynamically change the properties of the Prefab, however, why AddPrefabPostInit does not executed it?

I am a super rookie, if you want to achieve the above functions, how to do.

 

AddPrefabPostInit() stores the function given in a list of things to do to the given prefab after its base code has been executed.

You should call AddPrefabPostInit directly from modmain.lua and not via another postinit function, nor mid-game.

I suggest you modify the specific instance of the tool held at the time of pressing the key. It's cleaner and compatible with DLC/mod pickaxes.

56 minutes ago, Arkathorn said:

Firstly, post init functions should only be called once, before any initialization (NOT every time a key is pressed).

Why don't you explain precisely what you want to accomplish?

I am learning... I am a super beginner.

The code I listed above is just an example,I want to achieve: for example, in the game using the shortcut keys to open or close the quick pick

Can you teach me?

39 minutes ago, Mobbstar said:

AddPrefabPostInit() stores the function given in a list of things to do to the given prefab after its base code has been executed.

You should call AddPrefabPostInit directly from modmain.lua and not via another postinit function, nor mid-game.

I suggest you modify the specific instance of the tool held at the time of pressing the key. It's cleaner and compatible with DLC/mod pickaxes.

I am sorry, I am a Chinese, English is very bad, and can not find the Api document. I can't understand a lot of tutorials.

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