View Issue Details

IDProjectCategoryView StatusLast Update
0004067Spring engineGeneralpublic2013-10-16 19:04
ReporterJools Assigned ToKloot  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionno change required 
Product Version94.1.1+git 
Summary0004067: Spring.GetSelectedUnitsCounts() returns 0 table
DescriptionSpring.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.
TagsNo tags attached.
Attached Files
unit_z_selector.lua (Attachment missing)
dbg_test_zselector.lua (Attachment missing)
Checked infolog.txt for Errors

Activities

Kloot

2013-10-15 23:04

developer   ~0011795

Last edited: 2013-10-15 23:06

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'.

Jools

2013-10-15 23:55

reporter   ~0011800

1)

That's what you get when you try to iterate an empty table.

Kloot

2013-10-16 00:01

developer   ~0011801

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).

Jools

2013-10-16 01:53

reporter   ~0011804

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.

Kloot

2013-10-16 11:37

developer   ~0011808

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.

Jools

2013-10-16 18:11

reporter   ~0011813

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.

silentwings

2013-10-16 18:20

reporter   ~0011815

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

Jools

2013-10-16 18:47

reporter   ~0011816

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.

Kloot

2013-10-16 18:48

developer   ~0011817

Last edited: 2013-10-16 18:52

"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.

Jools

2013-10-16 18:52

reporter   ~0011818

Well, then it was broken. But you know yourself that the z-selector widget did work before.

Kloot

2013-10-16 18:54

developer   ~0011819

?

I have never even used anything other than the standard ctrl+z.

Issue History

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