Yakuzashi Posted November 8, 2019 Share Posted November 8, 2019 Hi, I have this troublemaker in my master_postinit, but no matter how hard I try I just can't succeed. I want it to be dependent on % chance, but as I said this is far above my reach. I know that first part... handle.deststate = function(inst) return "doshortaction" end ... proceeds without executing the rest of code, but when I want to manipulate all those lines to be harmonized it just ends with clusterdisaster. local master_postinit = function(inst) local function custperc(inst) local handle = inst.sg.sg.actionhandlers[ACTIONS.PICK] if math.random() < 0.5 then handle.deststate = function(inst) return "doshortaction" end return if math.random() < 0.5 then "doshortaction" end end else inst.components.talker:Say("I have to rest...", 2.5,true) end end Thank you kind stranger, just in advance. Link to comment Share on other sites More sharing options...
Ultroman Posted December 8, 2019 Share Posted December 8, 2019 You have to describe in better detail what it is you want. "manipulate all those lines to be harmonized" doesn't tell me anything about your goal. Link to comment Share on other sites More sharing options...
Yakuzashi Posted December 9, 2019 Author Share Posted December 9, 2019 This code allows character to pick flowers etc. faster. The code: Quote local handle = inst.sg.sg.actionhandlers[ACTIONS.PICK] handle.deststate = function(inst) return "doshortaction" end works in 100% cases and I want it to be randomized using this: if math.random() < 0.5 then but the line above is always ignored and I don't know how to make it work. Link to comment Share on other sites More sharing options...
Ultroman Posted December 11, 2019 Share Posted December 11, 2019 (edited) Your code doesn't make much sense, TBH. Sorry if that's a little harsh, but if it was me, I would want to know. Try to read through what you wrote, as if you were the computer trying to decide what to do (basically, assume that you have no knowledge of what is happening, and are just reading instructions to the letter). It's a good debugging tactic. You'll see what I mean. I'll just write something new. local function custperc(inst) local handle = inst.sg.sg.actionhandlers[ACTIONS.PICK] local origDestState = handle.deststate handle.deststate = function(inst) if math.random() < 0.5 then return "doshortaction" else return origDestState end end end This should save the original deststate, whether it is a string or a function, then replace it with a new function, which half the time does "doshortaction" and the rest of the time does whatever the original deststate is. If you want to keep the player from picking things (I saw your talker:Say()), you have to write a bunch more code, in order to keep state of how long before the player can pick things again. Edited December 12, 2019 by Ultroman Link to comment 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