Hi all, I am very new to Lua programming - have been learning a bit of python and Gamemaker GML over the past year so still pretty fresh all round.
I have just finished coding the smoke particle but am getting the following error when trying to run it and I can't work out why:
SYNTAX ERROR LINE 10
<EOF>
')' EXPECTED NEAR '.4'
Here is my actual code:
function make_smoke(x,y,init_size,col)
local s={}
s.x=x
s.y=y
s.col=col
s.width=init_size
s.width_final=init_size+rnd(3)+1
s.t=0 --how long lasts secs
s.max_t=30+rnd(10) --how long lasts secs
s.dx=(rnd(.8).4)
s.dy=rnd(.05)
s.ddy=.02 --simulate yaxis accel.
add(smoke,s)
return s
end
function _init()
smoke={}
cursorx=50
cursory=50
color=7
end
function move_smoke(sp)
if (sp.t>sp.max_t)then
del(smoke,sp)
end
if(sp.t>sp.max_t15)then
sp.width+=1
sp.width=min(sp.width,sp.width_final)
end
sp.x=sp.x+sp.dx
sp.y=sp.y+sp.dy
sp.dy=sp.dy+sp.ddy
sp.t=sp.t+1
end
function _update()
foreach(smoke,move_smoke)
if btn(0,0)then cursorx=1 end
if btn(1,0)then cursorx+=1 end
if btn(2,0)then cursory-=1 end
if btn(3,0)then cursory+=1 end
if btn(4,0)then color=flr(rand(16))end
make_smoke(cursorx,cursory,rnd(4),color)
end
function draw_smoke(s)
circfill(s.x,s.y,s.width,s.col)
end
function_draw()
cls()
foreach(smoke,draw_smoke)
end
|
Any ideas on what I have done wrong?
:) Mike
Thanks to both of you, that fixed that little problem now I have this:
SYNTAX ERROR LINE 53
<EOF>
<EOF> EXPECTED NEAR 'END'
Any idea what I haven't done right at end of code?
function_draw() |
should be
function _draw() |
note the space
(ignore my thoughts on foreach)
if btn(0,0)then cursorx=1 end |
should be
if btn(0,0)then cursorx-=1 end |
otherwise left cursor control doesn't work correctly
then just:
if (sp.t > sp.max_t15) then |
should be
if (sp.t > sp.max_t+5) then |
also see: https://www.lexaloffle.com/bbs/?tid=3260
Thanks so much - it worked with those revisions!
I believe the original intent was
if (sp.t > sp.max_t-15) then |
because the article says "Then we grow the width of the particle if we are within 15 steps of the end of its life".
And it makes sense because smoke thickens as it departs from its origin.
[Please log in to post a comment]



