Auto Complete

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
User avatar
Cooldude2606
Long Handed Inserter
Long Handed Inserter
Posts: 86
Joined: Sat Sep 16, 2017 9:04 pm
Contact:

Auto Complete

Post by Cooldude2606 »

TL;DR
Allow api access to auto complete in the console for a player.

Adding Would Allow
  • Sub-commands to be used with greater ease using auto complete. Examples of game command with auto complere is /config <get/set>
  • Game commands and the command word (ie /he going to /help) have auto complete along with player names but nothing else.
  • Scripts could be given context for an auto complete and insert something; for example names of items or give priority to admin names.
  • Common community phrases such as "8x" going to "8 to 8 balancer" could be added by a script.
  • A script to have names of offline (never joined) saved from an external location and allow auto complete for them.
  • Auto complete for colour names could be added via a script.
  • Possibly allow auto complete out side of the console, ie text boxs
Possible Ways to Implement
  1. Adding an event called "on_auto_complete" which is emited when a player presses the auto complete button in the console. This could contain: the player index of the player who triggered it, the message that the player has typed (for context), the current word, and where the text is typed. This could be paired with a function under LuaPlayer::auto_complete(suggestion) which inserts the suggestion string in place of the current word.
  2. A place where a string can be registered (possibly under game with a register function). An example would be to have game.auto_complete('Hello, world!') where "Hello, world!" is added to a list similar to player names so "hello" could auto complete to "Hello, world!"
  3. Simmilar to 2 but a filter function is checked first, game.auto_complete(filter,string), so the string is only a suggestion when the filter returns true. The filter could only have the message typed as a param or the message and the player.
Arguments
"Yeah, so what's going to be the benefit of having /command subcommand vs /command-subcommand ?"
> Allowing an auto complete system beyound what we currently have (first word only) would be much cleaner as we would not have to register a new command for every sub-command just to be able to have auto complete. A wider system would also allow more than just player names to be auto completed in side the command, like an item name or the key of a table which has locations in it. Also having a single command means that we are able to group the sub-commands together rather than just have a long list of commands of simmilar name.

"Sure, but that doesn't make it easier for the person that wants to find use of the sub-commands"
> Although sub-commands like this would not have a string under /help it does not mean that we cant add our own help subcommand or just list the sub-commands in the help string, it would just place the need for us (mod makers) to set up a good help message that talks about the sub-commands or add a message that says that the sub-command was missing. There is no reason for the factorio developers to add a full sub-command function when auto commplete could be used in many other places.

"Aliases are a pain"
> Yes they are and we would need a single command for every alias. Using one command we can handle all the aliases we wanted to but at the moment we lose the abilty to have auto complete for these sub-commands aliases. For example you could have "/player kill <name>" with the alias "/player k <name>" or "/player heal" with the alias "/player h <name". Doing this with a command for each would give you 4 commands rather than just the one here.

"What about when auto completes clash with each other; from the same mod or different mods"
> I see no reason why it could not have it be done as it currently is where it prints to console all the possible suggestions, or even make it so every time tab is pressed it moves to the next one in the list of suggestions. This would mean that when there is a conflict there is already a nice way to deal with them.

"Sub-command auto complete should only work for that specific command, how do you control that"
> I have suggested different ways this could be done above: either by using a filter function which is given the message that was typed, an event which has the message and the current word to be replaced and so on. Having it as part of a command means that we just to filter for when that command is present in the message.
--- Developer for Explosive Gaming factorio community. Find our code on GitHub. Please contact me via our Discord. ---

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Auto Complete

Post by Rseding91 »

I have no objection to the concept but currently autocomplete isn't part of the game state meaning I can't just ask a Lua function to give me an autocomplete result and be sure it didn't mutate some game state.

If I can find a way around that I'd be fine adding this in.
If you want to get ahold of me I'm almost always on Discord.

Post Reply

Return to “Modding interface requests”