I’m a bit lost. I have this function below in its own LUA model, and the database is open. When I run this now, I get attempt to index global row. This did work at first. Is this a scope issue? Just not sure why I am seeing this.
function returnUnfinishedPuzzleCount()
sqlString=“SELECT COUNT(*) as INCOMPLETE FROM PUZZLEDATA WHERE COMPLETE=‘N’;”
Specially what’s wrong with your code is how Lua handles index variables. This block of code:
for row in db:nrows(sqlString) do print (row.INCOMPLETE) end return row.INCOMPLETE
is really more like:
for local row in db:nrows(sqlString) do -- row is local to the for block. print (row.INCOMPLETE) end -- row doesn't exist here, it only exists inside the for loop. return row.INCOMPLETE
Now of course you can’t put the word local in the for loop but Lua effectively does. Your syntax is right, but row is local to the block and any context to that variable doesn’t exist outside the block.
Specially what’s wrong with your code is how Lua handles index variables. This block of code:
for row in db:nrows(sqlString) do print (row.INCOMPLETE) end return row.INCOMPLETE
is really more like:
for local row in db:nrows(sqlString) do -- row is local to the for block. print (row.INCOMPLETE) end -- row doesn't exist here, it only exists inside the for loop. return row.INCOMPLETE
Now of course you can’t put the word local in the for loop but Lua effectively does. Your syntax is right, but row is local to the block and any context to that variable doesn’t exist outside the block.