Jump to content

Recommended Posts

I began making a component action, and in modmain, i can print the action, which logs a table number. However, the action does not actually get added to GLOBAL.ACTIONS, and trying to print this results in nil. I suspect the line with AddAction does not work, but I cannot understand why it doesn't.

The action's string does not show up hovering over the ground in game.

Could you post the snippet of code in question to get a better understanding of the problem?
Otherwise, it could simply be that one of the conditionals in the if statement prior to adding the action to the table in AddComponentAction isn't ever true, or similarly to the if statement in AddAction.

Spoiler

local ActionHandler = GLOBAL.ActionHandler
local ACTIONS = GLOBAL.ACTIONS
local Action = GLOBAL.Action

local MYACTION = Action({priority = 4 , distance = 99})
 

MYACTION.str="action"
MYACTION.id = "MYACTION"
MYACTION.fn=function(act)
    print("hi")
    return true
end
AddAction(MYACTION)

print(MYACTION) --returns table number
print(ACTIONS.MYACTION) --returns nil

AddComponentAction("POINT", "MYACTION_component", function(inst, doer, pos, actions, right)
    if right then
        table.insert(actions, ACTIONS.MYACTION)
    end
end)

Sorry for the late response. This is some of the code in modmain.

1 hour ago, ChubbyBacon said:
  Reveal hidden contents

local ActionHandler = GLOBAL.ActionHandler
local ACTIONS = GLOBAL.ACTIONS
local Action = GLOBAL.Action

local MYACTION = Action({priority = 4 , distance = 99})
 

MYACTION.str="action"
MYACTION.id = "MYACTION"
MYACTION.fn=function(act)
    print("hi")
    return true
end
AddAction(MYACTION)

print(MYACTION) --returns table number
print(ACTIONS.MYACTION) --returns nil

AddComponentAction("POINT", "MYACTION_component", function(inst, doer, pos, actions, right)
    if right then
        table.insert(actions, ACTIONS.MYACTION)
    end
end)

Sorry for the late response. This is some of the code in modmain.

Your problem probably actually has to do with it being a 'POINT' action specifically. I'm not extremely well versed in how point actions work so I could stand corrected, but POINT actions tend to need something equipped or on the cursor with the component in order to function properly. For instance, if I take your exact code here and then add the component to an equippable, like say the spear, the action does work as expected.

Its kind of noticeable that this is the case because the best example I can think of that would be a point action not tied to an item is Wortox's soulhop, which has its own workaround using the "pointspecialactionsfn" from the playeractionpicker component. Depending on how you want your action to work, you can maybe look into using that.

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