Hope this is a good place to ask. <.< >.>
I try to do this
DasShip = mn.getShipByIndex( Index )
-- checky stuff here
X, Y = DasShip.Position:getScreenCoords()
if X then
DrawTarget( X, Y )
end
function DrawTarget( X, Y )
gr.drawString( X, 5, 20 )
end
and FS dies. Seems to die when ever I try to do something with X (or Y). But it passes the "if X then" part. :x
If I replace the function's contents with gr.drawString( "p", 5, 20 ), it works fine. And "p"s on my screen a million times because it's called a million times.
Here's what the whole thing looks like :
-- TestHud.lua
-- Test things here.
XMax = gr.getScreenWidth()
YMax = gr.getScreenHeight()
Index = 1
-- We do this so we don't have to call the function billions of times.
-- A variable is cheaper than a function call, performance wise.
NumShips = mn.getNumShips()
gr.setColor( 0, 255, 0, 96 )
gr.drawString( NumShips, 5, 5 )
-- Reticle
gr.drawLine( XMax / 2, YMax / 2 - 5, XMax / 2, YMax / 2 + 5 )
gr.drawLine( XMax / 2 - 5, YMax / 2, XMax / 2 + 5, YMax / 2 )
while Index < NumShips do
DasShip = mn.getShipByIndex( Index )
-- Is this ship alive? --
if DasShip then
if DasShip.HitpointsLeft > 0 then
-- Returning multiple values! :O
X, Y = DasShip.Position:getScreenCoords()
if X then
DrawTarget( X, Y )
end
end
end
Index = Index + 1
end
-- TestInit.lua
-- Initialize things for testing here.
-- Set these in the hud code.
XMax = 0
YMax = 0
function DrawTarget( X, Y )
gr.drawString( X, 5, 20 ) -- Always dies if X is used... Is X a number/int/real/whatever? Or something far more sinister...?
end