Jump to content

problem with strings.actions


Recommended Posts

i have a custom component which adds two custom actions for some prefab

STRINGS.ACTIONS.SIGNREAD = "Sign read"STRINGS.ACTIONS.SIGNEDIT = "Sign edit"ACTIONS.SIGNREAD = Action(2,true)ACTIONS.SIGNREAD.fn = function(act)    local tar = act.target    if tar and tar.components.signdata then        tar.components.signdata:OnLeftClick(tar)        return true    endendACTIONS.SIGNEDIT = Action(2,true,true)ACTIONS.SIGNEDIT.fn = function(act)    local tar = act.target    if tar and tar.components.signdata then        tar.components.signdata:OnRightClick(tar)        return true    endendlocal SignData = Class(function(self, inst)    self.inst = inst    self.oncd = false    self.data = {}    self.done = falseend)function SignData:CollectSceneActions(doer, actions, right)    if right and (not self.oncd) then table.insert(actions, ACTIONS.SIGNEDIT) end    if not right and (not self.oncd) then table.insert(actions, ACTIONS.SIGNREAD) endendfunction SignData:OnLeftClick(target)    print ("OnLeftClick")endfunction SignData:OnRightClick(target)    print ("OnRightClick")end

its work fine except one thing - its shows default "ACTION" string instead of my STRINGS.ACTIONS.SIGNREAD / STRINGS.ACTIONS.SIGNEDIT

 

adding

ACTIONS.SIGNREAD.str = "Sign read"ACTIONS.SIGNREAD.id = "SIGNREAD"ACTIONS.SIGNEDIT.str = "Sign edit"ACTIONS.SIGNEDIT.id = "SIGNEDIT"

doesnt helps too

 

why? :-)

Link to comment
Share on other sites

It's because you're not setting the 'id' key of your entries in the ACTIONS table, which is used to get the corresponding entry in the STRINGS table. Adding a line like this to your actions should fix it:

ACTIONS.SIGNREAD.id = "SIGNREAD" 
The modding API has a function for adding actions, though, so it might be better to use that. From the API examples mod:

 

------------------------------------- Actions and Handlers----  AddAction(action)--		Puts a new action into the global actions table and sets up the basic--		string for it.----	AddStategraphActionHandler("stategraphname", newActionHandler)--		Appends a handler for your action (or an existing action!) to an--		existing stategraph.-------------------------------------local Action = GLOBAL.Actionlocal ActionHandler = GLOBAL.ActionHandlerlocal MYACT = Action(3)MYACT.str = "Do My Action"MYACT.id = "MYACT"MYACT.fn = function(act)	print(act.doer.. " is doing my action!")endAddAction(MYACT)AddStategraphActionHandler("wilson", ActionHandler(MYACT, "doshortaction"))
Link to comment
Share on other sites

oh yes, STRINGS.ACTIONS.... was comented, my fault :)

 

btw AddAction doing same

    env.AddAction = function(action)        assert(action.id ~= nil, "Must specify an ID for your custom action! Example: myaction.id = \"MYACTION\"")        initprint("AddAction", action.id)        ACTIONS[action.id] = action        STRINGS.ACTIONS[action.id] = action.str    end

 

but really good to know about it

 

problem solved :)

Well only one left - there two actions, but only one description is shows, any chance to show them both?

Link to comment
Share on other sites

oh yes, STRINGS.ACTIONS.... was comented, my fault :-)

 

btw AddAction doing same

 

    env.AddAction = function(action)        assert(action.id ~= nil, "Must specify an ID for your custom action! Example: myaction.id = \"MYACTION\"")        initprint("AddAction", action.id)        ACTIONS[action.id] = action        STRINGS.ACTIONS[action.id] = action.str    end
 

but really good to know about it

Yep. I first thought you were adding to STRINGS.ACTIONS manually and then calling AddAction which was overwriting them, but then I realized you weren't even calling AddAction. :-)

 

Well only one left - there two actions, but only one description is shows, any chance to show them both?

I think that might have to do with priority, but I'm not sure. Try setting one action's priority lower than the other and see if that works, and if it doesn't, then try switching them.
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...