widget:CommandNotify

widget:CommandNotify

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
djmad
Posts: 13
Joined: 25 May 2009, 16:09

widget:CommandNotify

Post 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
User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: widget:CommandNotify

Post 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.
djmad
Posts: 13
Joined: 25 May 2009, 16:09

Re: widget:CommandNotify

Post 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
klapmongool
Posts: 843
Joined: 13 Aug 2007, 13:19

Re: widget:CommandNotify

Post by klapmongool »

Soooo, what is the status on this?
ShineSmith
Posts: 59
Joined: 25 Jul 2010, 20:23

Re: widget:CommandNotify

Post 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 :-)
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: widget:CommandNotify

Post 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.")
klapmongool
Posts: 843
Joined: 13 Aug 2007, 13:19

Re: widget:CommandNotify

Post by klapmongool »

Ah, i misunderstood that. I changed that true to false and it works now.

thx
Post Reply

Return to “Lua Scripts”