Hi,
I’ve got a problem with a script. Unfortunately my tries have failed.
The problem is:
To execute a chunk of code only if a unit belongs to a certain list by name or by object name.
-- if the condition is true
if IsSkirm(ud)==true then
-- the following code to be executed:
IsSkirm(ud) -- the function returns true if the unit is in the list
local function IsSkirm(ud1)
for i, v in pairs(unitArray) do
if (v==ud1.objectname) then
return true
end
end
return false
end
-- the list:
local unitArray = {
"CORCV",
"CORCOM",
"ARMCOM",
"ARMCK",
}
Question about a problem with a script
Moderator: Moderators
Re: Question about a problem with a script
objectname will contain 3do or s3o, why not just use ud1.name?
Also are you passing a unitID or a unitDefID?
Also are you passing a unitID or a unitDefID?
Re: Question about a problem with a script
There is a UnitDefNames table that can be used for this.
example:
http://springrts.com/phpbb/viewtopic.ph ... es#p522427
(see 2nd code block)
If I did not misunderstand, it is excactly what you want to do.
(the "fly" table would be your "IsSkirm" table)
example:
http://springrts.com/phpbb/viewtopic.ph ... es#p522427
(see 2nd code block)
If I did not misunderstand, it is excactly what you want to do.
(the "fly" table would be your "IsSkirm" table)
Re: Question about a problem with a script
I tried to change the widget named Adv Idle Indicator aka IdleBuildersNEW.FLOZi wrote:objectname will contain 3do or s3o, why not just use ud1.name?
Also are you passing a unitID or a unitDefID?
This widget now displays on the screen icons of any idle units that can be used to build - factories, combat engineers, constructors, and the commander. I want to limit the list only by constructors and the commander.
The following codes is used in the widget for selections:
local function IsIdleBuilder(unitID)
local udef = Spring.GetUnitDefID(unitID)
local ud = UnitDefs[udef]
local qCount = 0
if ud.buildSpeed > 0 then --- can build
last line selects all units that may be build.
For my purposes, I added a list of units that I would like to see in the result
local unitArray = {
"CORCV",
"CORCOM",
"ARMCOM",
"ARMCK",
}
Added a function that serves as a criterion for getting a unit to the list
local function IsSkirm(ud1)
for i, v in pairs(unitArray) do
if (v==ud1.objectname) then
return true
end
end
return false
end
and code was changed like this
local function IsIdleBuilder(unitID)
local udef = Spring.GetUnitDefID(unitID)
local ud = UnitDefs[udef]
local qCount = 0
before --if ud.buildSpeed > 0 then --- can build
after if IsSkirm(ud)==true then
after the changes it shows nothing

Re: Question about a problem with a script
Code: Select all
if (v:lower() == ud1.name) then
2. Either make your comparison strings lowercase in the table, or use :lower() to convert them
Re: Question about a problem with a script
thank you very much )))FLOZi wrote:1. Compare ud.name this is e.g. armpwCode: Select all
if (v:lower() == ud1.name) then
2. Either make your comparison strings lowercase in the table, or use :lower() to convert them