tlerbao Posted March 4, 2016 Share Posted March 4, 2016 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. Link to comment https://forums.kleientertainment.com/forums/topic/65103-need-help%E3%80%82dynamically-changing-the-properties-of-prefab/ Share on other sites More sharing options...
Arkathorn Posted March 4, 2016 Share Posted March 4, 2016 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? Link to comment https://forums.kleientertainment.com/forums/topic/65103-need-help%E3%80%82dynamically-changing-the-properties-of-prefab/#findComment-729756 Share on other sites More sharing options...
Mobbstar Posted March 4, 2016 Share Posted March 4, 2016 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. Link to comment https://forums.kleientertainment.com/forums/topic/65103-need-help%E3%80%82dynamically-changing-the-properties-of-prefab/#findComment-729764 Share on other sites More sharing options...
tlerbao Posted March 4, 2016 Author Share Posted March 4, 2016 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. Link to comment https://forums.kleientertainment.com/forums/topic/65103-need-help%E3%80%82dynamically-changing-the-properties-of-prefab/#findComment-729774 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now