Skip to content

Optionally forward command name as first argument to command execution callback function #59

@starwolfy

Description

@starwolfy

I am implementing this console add-on for a client in a networked server-client project.

When my client connects to the server, the client & console addon will dynamically register new commands that get sent from the server.

The problem is that I can only link all the callback functions to the same function as GDScript doesn't allow me to generate new function bodies and link those, see example below:

func consoleAddCommands(commandName : String, commandDescription : String, commandArguments : Dictionary) -> void:

  var functionName : String = "sendServerSideCommand" + str(commandArguments.size())
  var commandBuilder = Console.add_command(commandName, self,functionName)\
  .set_description(commandDescription)

  for argumentName in commandArguments:
	  commandBuilder.add_argument(argumentName,typeof(commandArguments[argumentName]))

  commandBuilder.register()




func sendServerSideCommand0(commandName) -> void:
	networkhound.send_message("serverSideCommand", [commandName])
func sendServerSideCommand1(commandName, arg0) -> void:
	networkhound.send_message("serverSideCommand", [commandName, arg0])
func sendServerSideCommand2(commandName, arg0, arg1) -> void:
	networkhound.send_message("serverSideCommand", [commandName, arg0, arg1])
func sendServerSideCommand3(commandName, arg0, arg1, arg2) -> void:
	networkhound.send_message("serverSideCommand", [commandName, arg0, arg1, arg2])
=> Etc..

This code does not work because the console add-on does not provide commandName to the callback functions, a way to circumvent that is to have the user input the same command twice, both as command name and as the 1st argument but this is not ideal.
So each time a callback fires from a dynamically added command, I get the correct variating arguments, but no way of identifying which exact command was executed.

Implementing a way to optionally register some commands that are expected to provide the commandName as the first argument to their callback functions would be really useful!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions