Zackreaver Posted February 13, 2015 Share Posted February 13, 2015 (edited) I have been trying to figure this out for days, but even after all they comparing between other mods I can not for the life of me figure out why this isn't working. I'm trying to create a custom action for an item I made. It's not a complicated action at all, it's actually just an exact copy of the "read" action that is used on books. The code for the item works perfectly when I substitute "watch" and "predict" with "reader" and "book". But I want to figure out how to create a custom action to both change the name of the text that shows up when the player puts their mouse over the item, and to figure out how to create custom actions for the future. Here is the code I have in modmain local Action = GLOBAL.Actionlocal ActionHandler = GLOBAL.ActionHandler local PREDICT = Action(3) PREDICT.str = "Predict" PREDICT.id = "PREDICT" PREDICT.fn = function(act) local targ = act.invobject or act.target if targ.components.watch then return act.doer.components.predictor:Predict(targ) end end AddAction(PREDICT) AddStategraphActionHandler("wilson", ActionHandler(PREDICT, "book")) local function predictactivate(inst, doer, actions, right) if doer:HasTag("predictor") then table.insert(actions, GLOBAL.ACTIONS.PREDICT) endendAddComponentAction("SCENE", "watch", predictactivate)local function predictactivate_inv(inst, doer, actions, right) if doer:HasTag("predictor") then table.insert(actions, GLOBAL.ACTIONS.PREDICT) endendAddComponentAction("INVENTORY", "watch", predictactivate_inv)Here is the component watch (identical to the component book)local Watch = Class(function(self, inst) self.inst = instend)function Watch:OnPredict(predictor) if self.onpredict then return self.onpredict(self.inst, predictor) end return trueendreturn Watchand the component predictor (Identical to the component reader)local Predictor = Class(function(self, inst) self.inst = inst inst:AddTag("predictor")end)function Predictor:OnRemoveFromEntity() self.inst:RemoveTag("predictor")endfunction Predictor:Predict(watch) if watch.components.watch then if watch.components.watch:OnPredict(self.inst) then if watch.components.finiteuses then watch.components.finiteuses:Use(1) end return true end endendreturn PredictorFor my Item prefab-- inst:AddComponent("book") --Using this makes it work fine-- inst.components.book.onread = onpredict inst:AddComponent("watch") --But this always shows up as "Examine" inst.components.watch.onpredict = onpredictfor my Character prefab inst:AddComponent("predictor") --Item still shows as "Examine"-- inst:AddComponent("reader") --Works perfectlyThe function that triggers when the item actually gets used works perfectly, but I'm trying to create a custom action for my item for a number of reasons. Mostly learning purposes. But I don't know what I'm missing here, why does the item only show "Examine" for the right click option? Edited February 13, 2015 by Zackreaver Link to comment https://forums.kleientertainment.com/forums/topic/50897-trying-to-add-a-custom-action/ Share on other sites More sharing options...
Zackreaver Posted February 13, 2015 Author Share Posted February 13, 2015 Okay I don't know if this is fate playing some kind of ******* joke on me, but it seems like EVERYTIME I come here and post code and say "This doesn't work" I go back and try it one more time and IT ******* WORKS!! Seriously, this happened so many times now... I don't even know what I did to make it work, it just suddenly decided to out of nowhere... Link to comment https://forums.kleientertainment.com/forums/topic/50897-trying-to-add-a-custom-action/#findComment-612645 Share on other sites More sharing options...
rezecib Posted February 13, 2015 Share Posted February 13, 2015 it just suddenly decided to out of nowhere... Welcome to coding But glad you got it working, actions are a little confusing. Link to comment https://forums.kleientertainment.com/forums/topic/50897-trying-to-add-a-custom-action/#findComment-612648 Share on other sites More sharing options...
Zackreaver Posted February 13, 2015 Author Share Posted February 13, 2015 Welcome to coding But glad you got it working, actions are a little confusing. Yeah, but ya know I was expecting it to be easier since I was BASICALLY just copying an action that already existed. But this nonsense took me more than a week to figure out. Now I wanna know why it just suddenly started working out of nowhere, my suspicion is on this. local PREDICT = Action(3) I had that originally, but then I looked at your throwing spears mod local SPEARTHROW = GLOBAL.Action(4, -- priority false, -- instant (set to not instant) true, -- right mouse button 10, -- distance check false, -- ghost valid (set to not ghost valid) false, -- can force (false) nil) -- range check functionI figured maybe that would get it to work since I had never dealt with custom actions before. And I was swapping them back and forth for a while. Added in ComponentActions after finally realizing that was a thing but it still didn't work. referenced a post made on WallGates, kept comparing and contrasting the codes to see whats different. Then right before posting this thread, I went back to local PREDICT = Action(3) And it worked. Now my question is why did the other fail? Why did changing this to an action with less arguments make the action suddenly spring up and start working? Also what does the 3 stand for? Is it priority? Priority for what exactly? Priority for when it would show up to the player? Link to comment https://forums.kleientertainment.com/forums/topic/50897-trying-to-add-a-custom-action/#findComment-612651 Share on other sites More sharing options...
rezecib Posted February 13, 2015 Share Posted February 13, 2015 Also what does the 3 stand for? Is it priority? Priority for what exactly? Priority for when it would show up to the player? Yes. So when you mouse over an object, there might be four+ valid actions for interacting with it. Let's say you have a spider gland on your cursor, mousing over a spider. The valid actions should be Heal, Give, Attack, and Examine, I think. But there are only two mouse buttons to map actions to, so the two with highest priority get mapped to left and right click. I'm sure there's more nuance to it, but that's basically the idea. As for why it worked when you dropped the extra arguments... One of the extra ones you added must've been messing it up. Link to comment https://forums.kleientertainment.com/forums/topic/50897-trying-to-add-a-custom-action/#findComment-612834 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