How do I pass parameters using ContextActionService?

I want to pass a parameter in the function I’m binding to ContextActionService, I wanna make it so I don’t have a bunch of functions.

for example:

local cas = game:GetService("ContextActionService")

function PrintToy(toy)
	print("I am a "..toy)
end

cas:BindAction("Print_Toy", PrintToy, true, Enum.KeyCode.E)

my goal would be to fill the parameter with a toy, however, you can’t do that with cas, I just wonder as to if there are any work-arounds I can use. Thank you for your time!

1 Like
local cas = game:GetService("ContextActionService")

local bear = "teddy"

function PrintToy(toy)
	print("I am a "..toy)
end

cas:BindAction("Print_Toy", function(actionName, inputState, inputObject)
   PrintToy(bear)
end , true, Enum.KeyCode.E)

???
I am not so familiar with context action but you can try this out.

7 Likes

Thank you so much! This is will be really useful! :smiley:

1 Like