This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Weird behaviour with nested tables and log
#1
I am going crazy....

Working on a scheduled script and running it manually to check it.

The code below neither print AAAAAAAAAA nor BBBBBBBBBBBB.
However, if I comment out line 19 (log('DDDDDDDDDDD')), everything is printed out fine.

What am I missing?
Dodgy

Thanks in advance for any good input

Rgds
Christian

CODE:
----------

log('AAAAAAAAAAAAAAAAAAAAAAAAAAAA')

tPresenceCheck = {
  {'Area1', 10 , '0/200/0' , {'21/4/19','24/4/19'}},
  {'Area2', 15 , '5/200/0' , {'21/4/19','24/4/19','25/4/9'}}
}

log('BBBBBBBBBBBBBBBBBBBBBBBBBB')

log(tPresenceCheck)
log(#tPresenceCheck)

for i=1,#tPresenceCheck do
  log('CCCCCCCCCCCCCCCCCCCCCC')
  tCurr = tPresenceCheck[i]
  log(tCurr)
  sArea = tCurr[1]
  log(sArea)
  log('DDDDDDDDDDDDDDDD')

end
Reply
#2
Hi,

Not sure if it’s always needed but you are missing the step size of the for loop.

for start, stop, step do, in your case for i=1,#tPresenceCheck, do

BR,

Erwin
Reply
#3
Step is optional, but it's better to use ipairs for loop. Do you have anything in error logs?
Reply
#4
(30.12.2019, 09:11)Erwin van der Zwart Wrote: Hi,

Not sure if it’s always needed but you are missing the step size of the for loop.

for start, stop, step do, in your case for i=1,#tPresenceCheck, do

BR,

Erwin

Thx for the quick reply.

LUA should default the step size to 1 if missing.
Tried anyway to add ,1 but in vain.

It is really odd. I can actually comment out any one of the four "log" statements inside the for-loop and things will work fine.
Once all log statements are there, I do not get any AAAAAAAAA or BBBBBB.

Is it something basic I am missing?

Thx

Rgds
Christian
Reply
#5
Try removing all spaces/tabs before statements in for loop.
Reply
#6
Here is another (simpler) example that is not working. 
The code below does not print the "AAAAAAAAAAAAAAA" (the first line statement). 
If I comment out the log statement in the inner for-loop, everything works fine.

CODE:
-----------------------------------------------------------------
log('AAAAAAAAAAAAAAAAAA')

local pid = os.getpid()
spid = ' (pid=' .. pid .. ')'
log('STARTING SCRIPT ' .. _SCRIPTNAME .. spid)
 
log('BBBBBBBBBBBBBBBBBBB')

for i=1,2,1 do
log( 'CCCCCCCCCCCCCCCCCC')
  for j=1,3,1 do
    log('DDDDDDDDDDDDDDDD')
  end
end



OUTPUT:
-----------------------------------------------------------------
ZZTest 30.12.2019 12:04:03
* string: STARTING SCRIPT ZZTest (pid=5393)


ZZTest 30.12.2019 12:04:03
* string: BBBBBBBBBBBBBBBBBBB


ZZTest 30.12.2019 12:04:03
* string: CCCCCCCCCCCCCCCCCC


ZZTest 30.12.2019 12:04:03
* string: DDDDDDDDDDDDDDDD


ZZTest 30.12.2019 12:04:03
* string: DDDDDDDDDDDDDDDD


ZZTest 30.12.2019 12:04:03
* string: DDDDDDDDDDDDDDDD


ZZTest 30.12.2019 12:04:03
* string: CCCCCCCCCCCCCCCCCC


ZZTest 30.12.2019 12:04:03
* string: DDDDDDDDDDDDDDDD


ZZTest 30.12.2019 12:04:03
* string: DDDDDDDDDDDDDDDD


ZZTest 30.12.2019 12:04:03
* string: DDDDDDDDDDDDDDDD
Reply
#7
Check in LM log tab, it is there.
------------------------------
Ctrl+F5
Reply
#8
(30.12.2019, 11:21)Daniel. Wrote: Check in LM log tab, it is there.
Wow!
Thanks so much. 
I was only looking at the log window which you can pop-up from the code editor. 
In this log-window, apparently not all logs are captured. Weird!, but good to know.
HAPPY NEW YEAR
Rgds
Christian
Smile
Reply


Forum Jump: