Page 1 of 1

How do I accept commands with arguments?

Posted: Wed Jun 28, 2017 11:49 am
by Zillo7
I'm trying to have my mod accept console commands with arguments. Here's what I'm using:

Code: Select all

commands.add_command("setTickRate","Sets how often the mod should scan for things. (default: 20)",
  function(list)
    global.tickRate = list[1]
	game.player.print(global.tickRate)
  end
)
The command is entered like:

Code: Select all

/setTickRate 50
However global.tickRate is set to nil. I thought the table named list would contain the arguments I passed, but it doesn't. How do I accept arguments with a console command?

Re: How do I accept commands with arguments?

Posted: Wed Jun 28, 2017 11:51 am
by Helfima

Re: How do I accept commands with arguments?

Posted: Wed Jun 28, 2017 3:47 pm
by Rseding91
Commands pass a table just like events.

The table contains the following parameters:

name - the command name
player_index - the player doing the command if any
parameter - the parameters provided as a string

In your case list.parameter would == "50".

Re: How do I accept commands with arguments?

Posted: Sat Jul 01, 2017 6:46 pm
by Zillo7
Rseding91 wrote:Commands pass a table just like events.

The table contains the following parameters:

name - the command name
player_index - the player doing the command if any
parameter - the parameters provided as a string

In your case list.parameter would == "50".
That worked perfectly, thanks!

Code: Select all

commands.add_command("setRate","Sets some value to something",
  function(arguments)
    global.rateThing = tonumber(arguments.parameter)
    game.player.print(global.rateThing )
  end
)