Page 1 of 1

Unexpected output from getAreaRooms()

Posted: Mon Mar 08, 2021 11:18 am
by visionok
Here's what I get
Code: [show] | [select all] lua
lua getAreaRooms(7)
{
  67,
  64,
  65,
  63,
  [0] = 66
}
I was expecting it to be
Code: [show] | [select all] lua
{
  67,
  64,
  65,
  63,
  66
}
I've tried a number of different areas and they all have that

[0] = nn

entry at the end of the table. Is it supposed to behave that way? I'm using the AppImage v4.10.1.

Re: Unexpected output from getAreaRooms()

Posted: Mon Mar 08, 2021 11:31 am
by Vadi
Yeah, unfortunately it starts indexing from 0 which is legal, but not the norm in Lua. That is OK at the end of the day.

Re: Unexpected output from getAreaRooms()

Posted: Mon Mar 08, 2021 7:14 pm
by visionok
That's a shame. I'm using a tempTimer() to call a function to process that table using table.remove(), so each time the timer is activated it removes and process the first item in the table then if table is not empty creates a new tempTimer() to call the function again. table.remove() does not work on the [0] = nn entry so I had to put in a little bit of extra code to handle it.

Re: Unexpected output from getAreaRooms()

Posted: Tue Mar 09, 2021 7:09 am
by Vadi
Yeah, agreed. We don't build such functions anymore - it's a mistake from the early versions. That said we have made proper equivalents for some that are this way, for example https://wiki.mudlet.org/w/Manual:Lua_Fu ... ExitStubs1 - so we could do it with getAreaRooms as well.

Re: Unexpected output from getAreaRooms()

Posted: Tue Apr 06, 2021 7:10 pm
by SlySven
Technically the output:

Code: Select all

lua getAreaRooms(7)
{
  67,
  64,
  65,
  63,
  [0] = 66
}
is actually:

Code: Select all

lua getAreaRooms(7)
{
  [1] = 67,
  [2] = 64,
  [3] = 65,
  [4] = 63,
  [0] = 66
}
The table printing code assumes that when the indexes are monotonically incrementing from 1 it is a Lua list/indexed table and suppresses the index number from the output, until it can't and then it treats the data as a Lua (associative) array and then displays the keys as well as the values - and for that rogue key value of (the number) 0 it shows it at the end as the last (only) key that does not fit the expected series of item keys for a list...