I was working on modifications to SCPUI for a future pull request, and found while working on the code to calculate the size of a weapon's volley, that pulling the value from the weapon class' SwarmInfodoes not retrieve any value and thus attempts to perform operations on or concatenate the value will crash. This small script demonstrates the problem. It iterates through tb.WeaponClasses[] one at a time, reporting the name of each weapon with ba.warn() as it goes. When it reaches a swarm weapon, it will use SwarmInfo to set three variables, and print out the second variable, swarmcount, with another ba.warn(). However, the operation to set the variable fails and it will throw an error instead as it will attempt to concatenate a nil value with the surrounding text while composing the warning.
#Conditional Hooks
$Application: FS2_Open
$On Game Init:
[
function iterateWeapons()
for j = 1, #tb.WeaponClasses do
local weapontype = tb.WeaponClasses[j].Name
ba.warning("Weapon type reported as " .. weapontype)
if tb.WeaponClasses[j].SwarmInfo then
local isSwarmer, swarmcount, swarmwait = tb.WeaponClasses[j].SwarmInfo
ba.warning ("Detected swarm weapon " .. weapontype .. " with swarmcount " .. swarmcount)
end
end
end
iterateWeapons()
]
#End
According to Asteroth in the HLP discord, the issue is caused by the swarm count being a short, which apparently causes a problem when it's being stored into an int variable by the lua system.
I was working on modifications to SCPUI for a future pull request, and found while working on the code to calculate the size of a weapon's volley, that pulling the value from the weapon class'
SwarmInfo
does not retrieve any value and thus attempts to perform operations on or concatenate the value will crash. This small script demonstrates the problem. It iterates throughtb.WeaponClasses[]
one at a time, reporting the name of each weapon withba.warn()
as it goes. When it reaches a swarm weapon, it will useSwarmInfo
to set three variables, and print out the second variable,swarmcount
, with anotherba.warn()
. However, the operation to set the variable fails and it will throw an error instead as it will attempt to concatenate a nil value with the surrounding text while composing the warning.According to Asteroth in the HLP discord, the issue is caused by the swarm count being a short, which apparently causes a problem when it's being stored into an int variable by the lua system.