I am having trouble inserting code that I tested in a "stand alone" program" into another file as a function. The intent is to create a particle explosion for blowing up asteroids. In the stand alone test program, it worked. Here's the code:
do
if spacekey()=1 and kill=0
delete object 100
kill=1
for n=101 to 199
make object cube n,1
position object n,0,0,0
color object n,rgb(255,0,0)
hide object n
next n
endif
if kill=1
for x=101 to 199
if object exist(x)
show object x
if spray#>=0
xrotate object x,rnd(360)
yrotate object x,rnd(360)
move object x,5
dec spray#,.1
else
delete object x
endif
endif
next x
endif
sync
loop
But, if I try and build it into the other prgram (as 2 functions, in this case) I get an error. Here's the code where the functions are called:
for n=100 to asteroids step 100
if object exist(n)
if mouseclick()=1 and intersect object(n,object position x(9998),object position y(9998),object position z(9998),limb position x(9998,1),limb position y(9998,1),limb position z(9998,1))
particles(n)
asplode(n)
score=score+1
kill=0
endif
endif
next n
and the function code:
function particles(target)
for a=target+1 to target+99
make object cube a,5
position object a,object position x(target),object position y(target),object position z(target)
color object a,rgb(255,0,0)
next a
endfunction
`the asplode function
function asplode(target)
kill=1
spray#=200
for b=target+1 to target+99
if object exist(b) and kill=1
if spray#>=0
xrotate object b,rnd(180)
yrotate object b,rnd(180)
move object b,5
spray#=spray#-1
else
delete object b
endif
endif
next b
endfunction
NOTE: some object numbers differ between the stand alone code and the program/function code simply by virtue of the former existing only to see if I could make a particle explosion.
Unfortunately, I have been fiddling with this for a while now, so neither of he coe sets exist in their original state and, as I have changed things, the errors have ranged from the particle appearing but not flying to getting an "object already exists" error (I already ran through the whole program code to make sure I wasn't calling or creating an object that I had made previously).
I am pretty sure that I am just missing something -- not even so much about functions, but about levels of if..endif statements and/or for..next loops.
Thanks a ton.