View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0004067 | Spring engine | General | public | 2013-10-15 22:46 | 2013-10-16 19:04 |
| Reporter | Jools | Assigned To | Kloot | ||
| Priority | normal | Severity | minor | Reproducibility | always |
| Status | closed | Resolution | no change required | ||
| Product Version | 94.1.1+git | ||||
| Summary | 0004067: Spring.GetSelectedUnitsCounts() returns 0 table | ||||
| Description | Spring.GetSelectedUnitsCounts ( ) -> { [number unitDefID] = number count, etc... } It should return a table with counts of selected unit types. Instead, it always returns a zero table. Makes widgets such as z-selector to fail. | ||||
| Tags | No tags attached. | ||||
| Attached Files | |||||
| Checked infolog.txt for Errors | |||||
|
|
copy-paste this into a widget of choice that has enabled=true: function widget:MousePress(mx, my, mButton) local selUnits = Spring.GetSelectedUnitsCounts() for k,v in pairs(selUnits) do print("[MousePress] k=\"" .. k .. "\", v=" .. v) end end then select some units and press a mouse button. report back *if and only if* there is 1) no output or 2) nothing besides 'k="n", v=0'. |
|
|
1) That's what you get when you try to iterate an empty table. |
|
|
Then there is some other widget clearing the selection before yours processes it because the callout works on its own (making this report invalid on that basis). |
|
|
I tested with no other widgets that the test widget and z-selector enabled: z-selector modified to echo the following: Echo("Z selector:", #(Spring.GetSelectedUnitsCounts()), Spring.GetSelectedUnitsCount()) It returns: 0, <number of selected units>. The mouseclick from the test widget returns nothing. Tested with /luarules disabled and only these 2 widgets on xta, ba with spring 95, xta 9.729, ba 7.83, nota 1.76 on spring 94.1, and xta 9.729 on spring engines 91.0, 89.0 and 85.0 Since it also fails on earlier engines it may be something local, but dnw also had same issue, and it's present in several games. |
|
|
Oh for the love of... I asked you to copypaste that code *for a reason*, #(Spring.GetSelectedUnitsCounts()) is zero because the return value IS NOT AN ARRAY TABLE AND YOU MUST USE PAIRS TO ITERATE OVER IT. You could save yourself and me a *whole lot* of time by learning these Lua basics before opening a report. |
|
|
The second file contains the copy pasted code. It also does not give any output in these cases. What is more, this is an old widget that before worked this way, it does check the validity of data by the # operator. In any case, iterating the output with pairs doesn't solve the issue. |
|
|
There is nothing wrong with Spring.GetSelectedUnitsCounts (tested in -1373). Jools, read http://lua-users.org/wiki/TablesTutorial and take this as demo code function widget:CommandsChanged() local units = Spring.GetSelectedUnitsCounts() for key,val in pairs(units) do Spring.Echo(key,val) end end |
|
|
I have read that tutorial many times and I obviously know about lookup tables and array tables. This wasn't my widget, it worked before. In any case, that code in CommandsChanged works, so I guess the issue is elsewhere than in engine. Sorry for the report. |
|
|
"What is more, this is an old widget that before worked this way, it does check the validity of data by the # operator." Sorry, but no. The # operator has *never ever* worked on the output of Spring.GetSelectedUnitsCounts and if a widget relied on that it was *broken* from the start. In fact GetSelectedUnitsCounts is one of the few functions that still provides an "n" field for exactly this purpose. |
|
|
Well, then it was broken. But you know yourself that the z-selector widget did work before. |
|
|
? I have never even used anything other than the standard ctrl+z. |
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2013-10-15 22:46 | Jools | New Issue | |
| 2013-10-15 23:04 | Kloot | Note Added: 0011795 | |
| 2013-10-15 23:04 | Kloot | Status | new => closed |
| 2013-10-15 23:04 | Kloot | Assigned To | => Kloot |
| 2013-10-15 23:04 | Kloot | Resolution | open => no change required |
| 2013-10-15 23:05 | Kloot | Status | closed => feedback |
| 2013-10-15 23:05 | Kloot | Resolution | no change required => reopened |
| 2013-10-15 23:05 | Kloot | Note Edited: 0011795 | |
| 2013-10-15 23:05 | Kloot | Status | feedback => closed |
| 2013-10-15 23:05 | Kloot | Resolution | reopened => no change required |
| 2013-10-15 23:06 | Kloot | Status | closed => feedback |
| 2013-10-15 23:06 | Kloot | Resolution | no change required => reopened |
| 2013-10-15 23:06 | Kloot | Note Edited: 0011795 | |
| 2013-10-15 23:06 | Kloot | Status | feedback => closed |
| 2013-10-15 23:06 | Kloot | Resolution | reopened => no change required |
| 2013-10-15 23:55 | Jools | Note Added: 0011800 | |
| 2013-10-15 23:55 | Jools | Status | closed => feedback |
| 2013-10-15 23:55 | Jools | Resolution | no change required => reopened |
| 2013-10-16 00:01 | Kloot | Note Added: 0011801 | |
| 2013-10-16 01:53 | Jools | Note Added: 0011804 | |
| 2013-10-16 01:53 | Jools | Status | feedback => assigned |
| 2013-10-16 01:56 | Jools | File Added: unit_z_selector.lua | |
| 2013-10-16 01:56 | Jools | File Added: dbg_test_zselector.lua | |
| 2013-10-16 11:37 | Kloot | Note Added: 0011808 | |
| 2013-10-16 11:38 | Kloot | Status | assigned => closed |
| 2013-10-16 11:38 | Kloot | Resolution | reopened => no change required |
| 2013-10-16 18:11 | Jools | Note Added: 0011813 | |
| 2013-10-16 18:11 | Jools | Status | closed => feedback |
| 2013-10-16 18:11 | Jools | Resolution | no change required => reopened |
| 2013-10-16 18:20 | silentwings | Note Added: 0011815 | |
| 2013-10-16 18:47 | Jools | Note Added: 0011816 | |
| 2013-10-16 18:47 | Jools | Status | feedback => assigned |
| 2013-10-16 18:48 | Kloot | Note Added: 0011817 | |
| 2013-10-16 18:52 | Jools | Note Added: 0011818 | |
| 2013-10-16 18:52 | Kloot | Note Edited: 0011817 | |
| 2013-10-16 18:54 | Kloot | Note Added: 0011819 | |
| 2013-10-16 19:04 | Kloot | Status | assigned => closed |
| 2013-10-16 19:04 | Kloot | Resolution | reopened => no change required |