Community Forum

Add Console Command

Forum Overview >> Scripting

Created24.07.2011 15:34

--- --- (Unknown) 24.07.2011 15:41

I'd like to add a new command to the Game Console (Farming Simulator 2011).
To do this I tried :

addConsoleCommand("setName", "Changes the name", "setName", nil);

This function is adapted from the Vehicle.lua out of the Script Docu.
My problem is that I don't know what I havte to fill the 3rd and 4th parameter with.

Every time I call the function via Console it only returns two empty lines.

I hope you can help me making it work.

Best regards

Stefan Geiger - GIANTS Software 02.08.2011 09:15
The 3rd argument is the name of the function that is called, and the 4th is an optional object, that the function is called on.

So, if you have a global or static function, that needs no "self" parameter, you can have nil as the 4th parameter.

The first argument (if used) will be the 4th parameter you passed, and the second argument will be the arguments the user added to the console.

Finally, the return value of your function will be printed to the console. If it is nil or empty, an empty line will be shown.

function setName(args)
if args ~= nil then
-- change name
return "Changed name to "..args;
return "Error: no arguments specified. Usage: setName newName";

addConsoleCommand("setName", "Changes the name", "setName", nil);

Unknown (Unknown) 03.08.2011 19:11
Thank you very much, works great!


Note: Log in to post. Create a new account here.