i tried this out, though, as much as i want to go “this is EXACTLY what i want” i don’t know if it is?
i’m not entirely sure how to use it either, even looking at the wiki page. when i did try it out though, it was a bit messy.
for example, three buttons can open up the menu. i can only get one button to work and the menu only stays for how long you hold down the button, which isnt what i want. i’d want the menu up after you press it, and stay up until you press it again, you know?
i’ll try looking into it some other time, though, thank you!
If you are using ContextActionService::BindAction, you bind a function like this:
function(actionName, inputState, inputObject)
...
end
You don’t need to use all the parameters, but suppose you want to make it so that the menu only toggles when you first press a button (not when releasing), you’d check if the inputState is equal to Begin, so the function you feed to BindAction is:
function(_, inputState, _)
if inputState == Enum.UserInputState.Begin then
toggleMenu()
end
end
To feed multiple buttons, you just add more keycodes to the end of your BindAction call. For example:
ContextActionService:BindAction(
"MyMenuAction",
function(_, inputState, _)
if inputState == Enum.UserInputState.Begin then
toggleMenu()
end
end,
false,
Enum.KeyCode.X,
Enum.KeyCode.Y,
Enum.KeyCode.Z
)
This is really the superior option. Don’t convince yourself having a table of inputs and doing it via UserInputService is a better alternative – it’s not.
also, the way i have my controls stored, since they’re used all over in my scripts for various reasons, is in an array. so, with that said, is there any way i can assign an array of buttons to an action?
Just leave that bool createTouchButton as false always, it’s kinda bad API design from Roblox’s side, I don’t really know anyone that uses that.
You can use unpack to have your button table as a trailing argument list:
ContextActionService:BindAction(
"MyMenuAction",
function(_, inputState, _)
if inputState == Enum.UserInputState.Begin then
toggleMenu()
end
end,
false,
unpack(buttongroup) -- 'buttongroup' being your table
)
Since ContextActionService is meant for quick cross-platform support, it seems pretty straightforward - touch devices normally doesn’t have a keyboard to use, so having ContextActionService create a touch button helps mobile / tablet users without a physical keyboard.
Setting createTouchButton to true creates a button in the same style as the touch jump button - you can define the text, image and other properties about it using other of the ContextActionService methods.
Here’s a screenshot from looking on the interwebs, showing it being used (see “Use Skill”)
The style of the jump button has changed and last I checked they didn’t update the CAS button backgrounds. That might have updated though.
Another issue is that with even 2 or a few more buttons, the ones added later will start going off-screen very quickly, there doesn’t seem to be any kind of smart mechanism for how these are positioned on-screen.
I don’t recommend using them for that reason and instead defining your own buttons and connecting those to the same actions. That way you don’t have a dependency on CAS creating them for you first, then having to fetch them through CAS, and adjusting position/size etc. It’s also convenient if you are able to unbind CAS calls without the buttons vanishing (i.e. if you want to disable the menu at certain times and grey out the button responsible for it).