As I'm unable to see the entirety of your code I will just have to give you this, you should be able to use this to give you an idea where you went wrong.
// Project: TypesExample
// Created: 22-01-11
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "TypesExample" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 )
createDefense(0, 0, 255, 0, 0)
createDefense(2, 4, 0, 255, 0)
createDefense(0, 8, 0, 0, 255)
do
Sync()
updateplayerdefenses()
updatebullets()
clearinactivebullets()
loop
Global playerdefense as Unit[]
global bullets as Projectile[]
Type Unit
sphere as integer
x as float
z as float
firetimertarget as integer
Endtype
Type Projectile
active as integer
sphere as integer
x as float
z as float
endtype
function createDefense(cellx, cellz, r, g, b)
id as Unit
sphere as integer
sphere = CreateObjectSphere(1, 10, 10)
SetObjectPosition(sphere, cellx * 1, 2, cellz * 1)
SetObjectColor(sphere, r, g, b, 100)
SetObjectCastShadow(sphere, 1)
id.sphere = sphere
id.x = cellx
id.z = cellz
id.firetimertarget = GetMilliseconds() + 2000
playerdefense.insert(id)
endfunction
function createbullet(cellx, cellz)
bullet as Projectile
sphere as integer
sphere = CreateObjectSphere(0.4, 10, 10)
SetObjectPosition(sphere, cellx * 1, 2, cellz * 1)
SetObjectColor(sphere, 255, 0, 255, 100)
SetObjectCastShadow(sphere, 1)
bullet.active = 1
bullet.sphere = sphere
bullet.x = cellx
bullet.z = cellz
bullets.insert(bullet)
endfunction
function updateplayerdefenses()
for i = 0 to playerdefense.length
updateplayerdefense(playerdefense[i])
next i
endfunction
function updateplayerdefense(defense ref as Unit)
if GetMilliseconds() >= defense.firetimertarget
createbullet(defense.x, defense.z)
defense.firetimertarget = GetMilliseconds() + 2000
endif
updateplayerdefensesprite(defense)
endfunction
function updateplayerdefensesprite(defense ref as Unit)
SetObjectPosition(defense.sphere, defense.x, 2, defense.z)
endfunction
function updatebullets()
for i = 0 to bullets.length
updatebullet(bullets[i])
next i
endfunction
function updatebullet(bullet ref as Projectile)
dec bullet.x, 0.3
if bullet.x <= -10
bullet.active = 0
endif
updatebulletsprite(bullet)
endfunction
function updatebulletsprite(bullet ref as Projectile)
SetObjectPosition(bullet.sphere, bullet.x, 2, bullet.z)
endfunction
function clearinactivebullets()
for i = 0 to bullets.length
if bullets[i].active = 0
DeleteObject(bullets[i].sphere)
bullets.remove(i)
endif
next i
endfunction