Community Forum

attempt to print g_currentMission - getting nil value

Forum Overview >> Scripting

Created11.06.2018 11:50

Mario Todeschini (Unknown) 11.06.2018 11:50
Hi, I must say that I am new to scripting.
I was trying to print this table in order to see what's in there. My goal was to edit fillLitersPerSecond for all siloTriggers, but I'm getting a nil value for this table. This is what I tried:

if g_currentMission~= nil then
for k, v in pairs(g_currentMission) do
print (k, " - ", v);
else print "---nil value---";

I put the condition because I got a "trying to index a nil value" error, and I get only the "---nil value---" text on the log.
I tried both adding this LUA file to a map, and creating a zip file with a modDesc.xml and reference to this LUA.

It loads, but I keep getting this error. Where is my mistake?

Thanks for your help,

Kevin K. (kevink98) 11.06.2018 12:59
g_currentMission is not nil... but i think you call it at a wrong position. You can put your code the loadMap -function ... or others, but not at the top of the script!

Mario Todeschini (Unknown) 12.06.2018 14:24
That was what I thought myself. Can you tell me where I can find a tutorial of these functions? I found this script, do you think it will work?

myClass = {};


function myClass:loadMap(name)

function myClass:deleteMap()


function myClass:keyEvent(unicode, sym, modifier, isDown)


function myClass:mouseEvent(posX, posY, isDown, isUp, button)


function myClass:update(dt)


function myClass:draw()


Do I need all those functions? What is their purpose? Do I need to insert the map name? Or to call those functions?

Bilbo Beutlin (BBeutlin) 16.06.2018 18:51
There are some functions, which MUST be present also if they are empty and do nothing (due to a LUA dispatcher).

Your idea printing a table within the "loadMap()" function will work. But at this time, the table/s are not complete yet.
Better you do it in the update() function, initialized by a key stroke, eg.
if InputBinding.hasEvent(InputBinding.MY_KEY) then
This has also the advantage, that you can print multiple, perhaps after certain conditions.

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