[SOLVED] How to remap controls with extension action

Im trying to create a action for making the controls easier, but I dont know how to make it so a variable or text can be selected in, and then a text can be returned to it .

These are the events, though the variables here are examples

This is what the action looks like

Edit:

I want the extension to basically be like any other action in gdevelop, where you enter a text, then the action returns a string to the text, but I have no idea what to do

I’m not sure what you want to do. Do you want to return a value or change a variable?

You can create functions that are conditions, actions, expressions, expression & condition or action with operator

Expressions return values, conditions return true/false which is used to decide whether actions get triggered. Actions are just that actions.

You can add a parameter as type “scene variable” and then copy the variable to another variable, modify that variable and then copy that variable back to the variable in the parameter.

It all depends on what you want to do. Instead of a standalone function. You also create behaviors that you assign to objects just like the “platform” or draggable" behaviors. That’s a bit more complex.

So what you see In the event selected (forgot what to call it) you select a variable or text, but it’s useless unless I can make the selected variable or text change, but idk how to

This might help:
https://wiki.gdevelop.io/gdevelop5/events/functions/

I’m still not understanding your need. If you want a value returned then you can use an expression. Setup the type of data that you want returned and use something like this in the function:

and in the scene (“1234” could also be a variable or object property)
image

If you’re only concerned if there’s a match then you can create a condition and return true or false

in the scene if the condition is true then it triggers the action. This can be used with other conditions for more complex situations. Again “1234” can be a variable or object property

or something with other conditions

It all depends on what you want to do.

(sorry if it’s hard to understand.)

Well since probably only variables matter,

I want it to be like, you select a variable in the events window, let’s say I have 5 variables, for each of them I need it so that when I select a particular variable ingame, it changes the text to the last pressed key, easy but annoying to do manually. But I want it all to be with 1 event for each variable (because it takes alot of events to do all the mouse button clicks)

Honestly I have no idea how to explain

Edit:

Logic would be like this

Events, conditions: cursor on object “”, actions: extension, select any variable.

Wanted outcome, ingame with these events, if the cursor is on specified object (conditions don’t matter, just the logic) and when any keyboard key is pressed, the text of the selected variable will change to last pressed key, or for mouse buttons I also have built in logic for that, the variables will be set to “leftclick” for left click, “rightclick” for rightclick, same goes for all other available mouse buttons, but the outcome is just confusion, because I don’t know how to make it like this, I could do it manually, but that takes so many events for the logic of all mouse buttons to work.

I might be closer to understanding. Do you want a sort of last mouse condition similar to last key pressed expression? What would you do if multiple keys were pressed? Either the first or last could have priority or I guess you could use an array and add all of the actions. IDK.

You would still need to do something with the information in the variable. It kind of seems like you’re adding a middle man or extra step. I don’t see your vision.

A different direction might be to include the actions in the function instead of returning a variable and then have to do things based on the variable. Whether that would be setting an objects variable or moving the object or deleting it. If you add an object parameter then you could make changes directly to the object.

What exactly do you want this for? What is supposed to happen when one of the buttons is clicked?

They currently work like how controls are supposed to, it’s just that they take forever to make another control. I can show you pictures of the events I have to use right now for inputting controls, they’re hella annoying - also I don’t need a last mouse button pressed expression, I have already set that up

The events would help us understand it better.

Alright, here are the main events.

These are just the normal keyboard keys,

This is for mouse inputs,

This is only left click and keyboard events, I have to do all these events for each control

And doing this over and over again is so time consuming, I want to be able to do all keyboard registration and mouse in 1 event, but I would need to make it a selectable variable in the event s window for it to be any good, but idk how to make a text go into the selected variable, I hope this gives a good understanding.

You can set a parameter to the type scene variable then copy the variable in the parameter to a variable that the function changes it and then copy that variable back to the supplied variable in the action.

If you only want to set the variable then you could skip the parameter to variable and only use the variable to parameter.

It doesn’t seem to matter what the variable is.

I don’t think it works with global variables but you can use JSON to convert the scene variable to global.

See this post

To convert a scene variable to a global variable in the scene after the function.

You could skip the conversion if you passed the variable name to the function as text parameter and then used it to build a structure name.

I believe this would have the added benefit of being able to use for each child

This would be the action

Idk what to do, how do you have a scene variable there?

I don’t mean to confuse you. I kind of switched strategies. One involves using a scene variable to return the variable values and then converting the scene variable to global. I think I might have assumed you were using global variables based on the keybindChangeable variable. I apologize for that.

The other uses a text parameter to build a structure name. This is very similar to your existing events.

I think I’m making it more complex than it needs to be. I’m make assumptions because I’m not clear on the purpose. Let’s start over.

It’s tough to understand the concept from seeing snippets. There are multiple strategies. I still don’t know what you’re trying to ultimately do.

If you could either explain what the project is, post a screenshot of the game scene or a link to a playable version. Something because I don’t think we’re on the same page. To help you move this forward, I would even be willing to look at the project if you share a link to it on a file share site.

I want to help but I’m just not understanding the whole picture.

you’re checking a variable of a text object and a global keybindChangable
(I don’t know what keybindChangable is)
You’re checking keys and mouse events.
You’re setting variables based on the events

But how are you using the values in the variable?

The “keybind changeable” variable isn’t irrelevant, that checks what keybind your trying to change, though. That could probably be made better, but that’s not the problem. But I’m gonna think about the best way to explain this.

(Maybe this could help you understand, it would be like how normal actions are, you select a text of any type, then the action will change that variable according to the wanted text)

I understand that part but I don’t understand what you’re doing with the results.

I don’t understand how checking a variable before doing something is easier than checking the property directly.

What is the difference between mouse button is down and is variable… equal to something.

I don’t understand the time saver if you still need to check things afterwards.

Is this for custom keyboard shortcuts or custom buttons or multiple objects or players. I’m missing that one ah-ha ingredient.

I’m just thinking that it might be easier doing it with the built in conditions and using a for each or object variables or a group object list or some other condition.

The left click, etc. Variable is used to know if the keybind is set to left click, otherwise there would not be the possibility of making mouse buttons as keybinds, it just wouldn’t be customizable.

I’ll show a picture of what the controls menu looks like ingame

It’s fully functional, but the amount of events is just not great,

Idk if this will help any.

As for the “each object” thing, i need to make where I can restrict mouse buttons for certain things.

1 Like

Now, we’re talking. I’m sure people here have had experience with that. I personally haven’t but it seems like a relatively easy thing to do.

Let me think about it.

In the meantime, how about changing the title to something like “how to remap controls” or “how to customize player controls”

1 Like

Well that’s not really the problem, and not to do with extensions, but I’ll do “How to remap controls with extension action”

1 Like

An example would be easier for me to explain but here’s a rough idea until I have more time and my pc.

The function could be type expression and style string(text) the first event would be to set some string variable to “” to clear the previous key.

If a key or mouse button is pressed then set that variable like you do to the key or mouse action.

At the end of the function return this value

When one of the boxes that show which key/mouse is currently set is clicked then change it to “press key or mouse … something”
Set a variable like waitingForKey to true
Set a variable that you can use to reference the text object later and save the preference.

If the variable waitingForKey is true then
Action: set variable to expressionName()

Sub event: if the previous variable ≠ “”
Action: set text return value under [other actions] [event functions]

You can then set the waitingForKey to false

That’s really all i have at the moment. I’m better with doing it in the app then in my head alone.

You then use the ine variable to repick the text object. Change its twxt to the value from your extension and using the previous variable set when the setting box is clicked to the new preset.

I realize this part is missing details. I don’t have everything.

Somewhere in there you need to check if another action has the key from your expression. And then decide if you’re going to overide the other preference or ask first.

You then have to update the conflicting one.

Again, an example would be an easier way for me to explain it. But that’s going to have to wait. Hopefully, I didn’t confuse the situation more.

Ok, here’s a rough mockup. The scene is just to test the extension. It’s a bit rough. There’s also an issue with the mouse click because my version will repick a setting. It’s not error free. It’s just an example.

It doesn’t save the new key or mouse click. It just changes the text object but it wouldn’t take much to have it change a structure variable. I might work on that part sometime tomorrow just to learn.

try me: It only does keyboard or mouse left or right.

source: (click green [code]button and then download zip, extract and open JSON file)

This is the extension, it currently has no parameters

.
This is in the scene part. Once the customizeKey variable is set to true, it triggers the function/expression until it doesn’t equal “”. The text object that is being changed has a Boolean selected set to true.

It is good, only problem is with mouse left click, very glitched. Know any fix?