Confusing order of custom list
Bubb
Member Posts: 1,005
in UI Modding
Hi everyone,
I have recently been tinkering around with expanding the vanilla cheat menu, and I seem to be having a very weird behavior. I'll try to explain what I am trying to do:
Basically, I am trying to create a list that displays all the resrefs and names of all the creatures in the game. So far it's been easy enough; I've written a very simple WeiDU script that populates a M_ lua file with all the relevant information... but for some odd reason I'm hitting a wall with the actual list implementation. It seems that the in-game list is displaying the elements of the table out of order, even when the table is already sorted in the M_ lua file. I'm probably doing something stupid here, but I've been staring at this for an hour or two now, and just can't find the (what should be very simple) error.
I've attached my override folder so you guys can look at the code, (the files are for BG2EE). The problematic list starts at line 237 of UI.MENU. You can view the list in-game by hitting ctrl+space, and pressing the "Browse Creatures" button in the cheat menu. I expect the resrefs to be displayed alphabetically, as that is the order they are presented in the M_ChtMen.lua file, but alas they seem to be in a completely random order. I've rigged the clicking of a row to output the resref of the row in the feedback area, and for some odd reason THIS provides the correct feedback, while the list itself is wrong.
Any help would be greatly appreciated!
I have recently been tinkering around with expanding the vanilla cheat menu, and I seem to be having a very weird behavior. I'll try to explain what I am trying to do:
Basically, I am trying to create a list that displays all the resrefs and names of all the creatures in the game. So far it's been easy enough; I've written a very simple WeiDU script that populates a M_ lua file with all the relevant information... but for some odd reason I'm hitting a wall with the actual list implementation. It seems that the in-game list is displaying the elements of the table out of order, even when the table is already sorted in the M_ lua file. I'm probably doing something stupid here, but I've been staring at this for an hour or two now, and just can't find the (what should be very simple) error.
I've attached my override folder so you guys can look at the code, (the files are for BG2EE). The problematic list starts at line 237 of UI.MENU. You can view the list in-game by hitting ctrl+space, and pressing the "Browse Creatures" button in the cheat menu. I expect the resrefs to be displayed alphabetically, as that is the order they are presented in the M_ChtMen.lua file, but alas they seem to be in a completely random order. I've rigged the clicking of a row to output the resref of the row in the feedback area, and for some odd reason THIS provides the correct feedback, while the list itself is wrong.
Any help would be greatly appreciated!
0
Comments
as does this:
That was it! I never would have guessed that it was in the M_ lua file; I thought for sure it was something in UI.MENU. I experimented a bit with table order, and it seems that lua's pairs function honors the order if no keys are present in the table declaration, but will not honor the order if the keys are explicitly stated (just like you said). Very weird behavior, to say the least. Maybe by declaring the keys, lua is treating the table as a dictionary instead of an array? Anyways, thanks for your help!
Edit: It seems I was partially right. I was searching around a bit for more clarification on why this behavior was occurring, and I came across this article: lua-users.org/wiki/TableConstructors. If you look at the bytecode difference between the {1, 2, 3} syntax and the {[1] = 1, [2] = 2, [3] = 3} syntax, you will see that the former generates a SETLIST call, while the latter generates a SETMAP call. Turns out the syntax I was using was generating an unordered map instead of a list; an interesting behind the scenes difference between the syntaxes, especially since they are stated as being identical in the official lua docs.