I head dev for Bitfighter , and we use Lua as a scripting language to allow players to program their own robotic ships.
In Lua, you do not need to declare variables, and all variables are global by default, unless otherwise specified. This leads to some problems. Take the following snippet, for example:
loc = bot:getLoc()
items = bot:findItems(ShipType) -- Find a Ship
minDist = 999999
found = false
for indx, item in ipairs(items) do
local d = loc:distSquared(item:getLoc())
if(d < minDist) then
closestItem = item
minDist = d
end
end
if(closestItem != nil) then
firingAngle = getFiringSolution(closestItem)
end
In this fragment, if findItems () does not return any candidates, then closestItem will still refer to the last ship it found, and in the meantime this ship could be killed. If the ship is killed, it no longer exists, and getFiringSolution () will fail.
Did you notice a problem? Well, my users too. It is subtle, but with a dramatic effect.
, - . , , .
Lua vars / , ? , (, Perl) .
!
, !
Lua "strict". , , , , .