Page 1 of 1

widget:CommandNotify

Posted: 30 Dec 2011, 12:10
by djmad
Why does CommandNotify after 83.0 not work as in the versions before

down there is a codesample of the Build-Splitter Widget how was working before

to get in the "if", u have to make 2+ Builders and build some line or quader with the metakey holded

the interesting part is now after the new versions, only one buildcommand is returned if "return true" is set at the end


Code: Select all

function widget:GetInfo()
	return {
		name      = "only a test",
		desc      = "test of the commandnotify",
		author    = "djmad",
		version   = "v1.0",
		date      = "Dez 30, 2011",
		license   = "GNU GPL, v2 or later",
		layer     = 0,
		enabled = true  --  loaded by default?
	}
end

local floor = math.floor
local spGetGameFrame = Spring.GetGameFrame
local spGetSpecState = Spring.GetSpectatingState
local spTestBuildOrder = Spring.TestBuildOrder
local spGetSelUnitCount = Spring.GetSelectedUnitsCount
local spGetSelUnitsSorted = Spring.GetSelectedUnitsSorted
local spGiveOrderToUnit = Spring.GiveOrderToUnit
local spGiveOrderToUnitArray = Spring.GiveOrderToUnitArray
local uDefs = UnitDefs
local buildID = 0
local buildLocs = {}
local buildCount = 0

function widget:Initialize()
	if spGetGameFrame() > 0 then
		widget:GameStart()
	end
end

function widget:GameStart()
	local areSpec = spGetSpecState()
	if areSpec then
		widgetHandler:RemoveWidget(self)
	end
end

function widget:CommandNotify(cmdID, cmdParams, cmdOpts) 
	Spring . Echo ( cmdID , #cmdParams , #cmdOpts, buildCount, spGetSelUnitCount() )	
	if not (cmdOpts.shift and cmdOpts.meta) then return false end
	if spGetSelUnitCount() < 2 then return false end
	if #cmdParams < 4 then return false end
	if spTestBuildOrder(-cmdID, cmdParams[1], cmdParams[2], cmdParams[3], cmdParams[4]) == 0 then return false end
	buildID = -cmdID
	buildOpts = cmdOpts
	buildCount = buildCount + 1
	buildLocs[buildCount] = cmdParams

	return true  --<<< THIS HERE
end

function widget:Update() -- 0 of 0 parameters
	if buildCount == 0 then return end
	Spring . Echo ( "i build now ", buildCount, "jobs" )	
	buildCount = 0
end
now if i change the code (as commented below) the script is working again.
Was there changed some logic in the background?

Code: Select all

function widget:GetInfo()
	return {
		name      = "only a test",
		desc      = "test of the commandnotify",
		author    = "djmad",
		version   = "v1.0",
		date      = "Dez 30, 2011",
		license   = "GNU GPL, v2 or later",
		layer     = 0,
		enabled = true  --  loaded by default?
	}
end

local floor = math.floor
local spGetGameFrame = Spring.GetGameFrame
local spGetSpecState = Spring.GetSpectatingState
local spTestBuildOrder = Spring.TestBuildOrder
local spGetSelUnitCount = Spring.GetSelectedUnitsCount
local spGetSelUnitsSorted = Spring.GetSelectedUnitsSorted
local spGiveOrderToUnit = Spring.GiveOrderToUnit
local spGiveOrderToUnitArray = Spring.GiveOrderToUnitArray
local uDefs = UnitDefs
local buildID = 0
local buildLocs = {}
local buildCount = 0

function widget:Initialize()
	if spGetGameFrame() > 0 then
		widget:GameStart()
	end
end

function widget:GameStart()
	local areSpec = spGetSpecState()
	if areSpec then
		widgetHandler:RemoveWidget(self)
	end
end

function widget:CommandNotify(cmdID, cmdParams, cmdOpts) 
	Spring . Echo ( cmdID , #cmdParams , #cmdOpts, buildCount, spGetSelUnitCount() )	
	if not (cmdOpts.shift and cmdOpts.meta) then return false end
	if spGetSelUnitCount() < 2 then return false end
	if #cmdParams < 4 then return false end
	if spTestBuildOrder(-cmdID, cmdParams[1], cmdParams[2], cmdParams[3], cmdParams[4]) == 0 then return false end
	buildID = -cmdID
	buildOpts = cmdOpts
	buildCount = buildCount + 1
	buildLocs[buildCount] = cmdParams

	return false --<<< THIS HERE
end

function widget:Update() -- 0 of 0 parameters
	if buildCount == 0 then return end
	Spring . Echo ( "i build now ", buildCount, "jobs" )	
	buildCount = 0
end
may someone can tell me, why commandnotify does "clear" its stack-list if i return a true, should it not return a complete list in every case?

btw, this issue is atm in 2 widgets i know, Build-Split + Centralbuild AI

Re: widget:CommandNotify

Posted: 30 Dec 2011, 13:17
by Niobium
Summary:

When queuing multiple buildings (i.e. in a line) what happened previously was that :CommandNotify was fired for every individual building, and widgets could return true/false as they pleased to whichever individual buildings they wanted.

What happens now is that as soon as a widget returns true on :CommandNotify, it ceases firing :CommandNotify for all buildings later in the line (and does not build them either*)

* Which is a problem in itself, as any widget won't know what these buildings later in the line are/were (if any) when it returns false and cancels them too.

Coding a workaround is very hard to do nicely, as the options are basically:
1) Return true - Lose all information about what was queued
2) Return false - Commands are then allowed to go to server, which is a problem for widgets like built split which want to alter the queue, as they then need to reissue another set of commands ontop to overwrite the ones which were just sent, problematic when inserts/queuing is involved.

Re: widget:CommandNotify

Posted: 30 Dec 2011, 13:51
by djmad
thx for the summarize, im lacking of programming skill to describe it in the best words :D

http://springrts.com/mantis/view.php?id=2764

already postet in mantis weeks ago, but closed 2 times by kloot

i see this issue open

Re: widget:CommandNotify

Posted: 15 Jan 2012, 12:19
by klapmongool
Soooo, what is the status on this?

Re: widget:CommandNotify

Posted: 16 Jan 2012, 13:25
by ShineSmith
Soooo, what is the status on this?
PLEASE please fix! Building a long wall of dt with vtol builders was amazing with build split! It made the game look more realistic and widgets like these are why i love spring so much :-)

Re: widget:CommandNotify

Posted: 16 Jan 2012, 16:40
by knorke
abma on mantis 2764 wrote:please retry with a build after https://github.com/spring/spring/commit ... 3f8b2e471d [^]
So I guess go test that..

And for this particular widget it seems djmad posted a fixed version in first post? ("now if i change the code (as commented below) the script is working again.")

Re: widget:CommandNotify

Posted: 17 Jan 2012, 11:05
by klapmongool
Ah, i misunderstood that. I changed that true to false and it works now.

thx