Thanks for the feedback!
The problem seems to be something to do with the scope of variables... converting the function i was calling clone object in, to a gosub fixed the problem, and my pawns now spawn! Yay!
However... I now get an illegal object number error when trying to move the objects ive just cloned...
If someone with time on their hands could explain why the code below doesnt work, I'd appreciate it!
Type Cloud
id as integer
h20 as integer
EndType
`*** handy tweakable variables
global WorldSize:WorldSize=2000
global CamHeight:CamHeight=100
global NumSeeds:NumSeeds=100
global NumClouds:NumClouds=10
global CloudHeight:CloudHeight=400
global WindSpeed:WindSpeed=50
global WindDirection:WindDirection=45
global WindNoise:WindNoise=50
global PAUSED as boolean:PAUSED=1
dim Clouds(0) as Cloud
gosub _SetupWorld
`********** begin main loop
do
CheckUserInput()
if PAUSED=0 then gosub _Simulate
sync
loop
`********** end main loop
_Simulate:
`if there are no clouds or seeds, create some
if array count(Clouds()) = 0
for a = 1 to NumClouds
Spawn("cloud",rnd(WorldSize)-(WorldSize/2),CloudHeight,rnd(WorldSize)-(WorldSize/2))
next a
endif
gosub _CloudThink
return
_CloudThink:
for a = 0 to array count(Clouds())-1
`drift on the wind
move object Clouds(a).id, (WindSpeed/10)
`stick a label on the cloud
text object screen x (Clouds(a).id),object screen y (Clouds(a).id), "cloud_" + str$(Clouds(a).id)
next a
return
function Spawn(sType as string, sX as integer, sY as integer, sZ as integer)
`get a free object number
newID=FreeObject()
if sType = "cloud"
`get new cloud number
newCloud = array count(Clouds())
`add new cloud to array
array insert at top Clouds()
`initialise cloud
Clouds(newCloud).id=newID
Clouds(newCloud).h20=100
`clone a new model
clone object newID,obj_Cloud
`set position
position object newID, sX,sY+rnd(100),sZ
`align to wind
rotate object newID, 0,WindDirection,0
`set scale
scale object newID, 100+rnd(50),25+rnd(50),100+rnd(50)
`set colour
color object newID, rgb(200,200,200)
endif
endfunction
_SetupWorld:
`screen stuff
randomize timer()
set window on
hide mouse
set display mode 800,600,32
set window layout 1,1,0
sync on
sync rate 50
autocam off
backdrop on
color backdrop rgb(0,0,0)
fog on
fog distance WorldSize
fog color rgb(0,0,0)
`camera stuff
set camera range 1,WorldSize
position camera 0,130,0
rotate camera 20,0,0
global camera_dolly:camera_dolly=FreeObject()
make object box camera_dolly,10,10,10
hide object camera_dolly
`make base procedural objects
make matrix 1, WorldSize,WorldSize,(WorldSize/100),(WorldSize/100)
position matrix 1, (0-WorldSize/2),0,(0-WorldSize/2)
global obj_Cloud:obj_Cloud=FreeObject()
make object sphere obj_Cloud,250
hide object obj_Cloud
return
function CheckUserInput()
`handle key input
if spacekey() then PAUSED = (1-PAUSED)
If Upkey()=1 then Move object camera_dolly, 20
If Downkey()=1 then Move object camera_dolly, -20
If Leftkey()=1 then move object left camera_dolly, 20
If Rightkey()=1 then move object right camera_dolly, 20
if keystate(201) = 1 and CamHeight <= 1000 then CamHeight = (CamHeight+10)
if keystate(209) = 1 and CamHeight >= 20 then CamHeight = (CamHeight-10)
`sync camera to dolly
position camera object position x(camera_dolly), CamHeight, object position z(camera_dolly)
`handle mouse movement and rotate camera
tY=camera angle y() + mousemovex()*0.3
tX=camera angle x() + mousemovey()*0.3
if tX > 90 then tX = 90
yrotate camera tY
xrotate camera tX
`sync dolly to camera
yrotate object camera_dolly, tY
`handle mouse clicks
`ob = pick object(mousex(),mousey(),101,399)
endfunction
function FreeObject()
local o as dword
repeat
inc o
until object exist(o) = 0
endfunction o