Community Forum

Error LUA attempt to call global

Forum Overview >> Scripting

Created24.12.2018 11:10

Baptiste Brossette (Monsieur_Bab) 24.12.2018 11:10
I have an issue in my first script (i'm beginner, sorry if this error is basic ^^)
I want to write a code that display the current date in the developper console in fs19.

Here is (a part of) my code :
function MoneyTool:keyEvent(unicode, sym, modifier, isDown)
if Input.isKeyPressed(Input.KEY_equals) then
currentDate = getCurrentDate()

When I press the Equals key, an error occurs :
Error: Running LUA method 'keyEvent'
C:/Users/...: attempt to call global 'getCurrentDate' (a nil value)

Do you know where is my error?
And also, do you have a link for a tutorial for beginner in scripting (I saw your 7 tutorials about scripting but this explain not every newest things about LUA in fs19)

Thanks and Merry Christmas !

Ben Sollis (sollisb) 24.12.2018 13:49
nil value means that getCurrentDate is returning nothing.. I have no idea how tro get the date in FS. In typical LUA it's something like os.Date or os.Time..

Also, don't create variables for nothing.. You could just have easily used print(getCurrentDate) and saved time and memory. Not an issue in something small, but all the bad parts add up.. Bear it in mind :) Be efficient and ask is your code optimised.

You might want to visit

Thats chap has done excellent work for us.

Bilbo Beutlin (BBeutlin) 24.12.2018 14:33
The error message "attempt to call global 'getCurrentDate' (a nil value)" means "getCurrentDate" is unknown as global variable.
It is component of the localization "l18N" (see
and must be called
local currentDate = l18N:getCurrentDate()

Baptiste Brossette (Monsieur_Bab) 25.12.2018 12:05
Thanks you for your responses!
All works well. Thanks for the lua doc on github :)

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