Log In  

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

P#22986 2016-06-16 09:30 ( Edited 2016-09-06 20:48)

When I ran into this problem, I just put a * in front of the .4! I don't think parenthetical multiplication works when the parentheses are calling a function.

P#22987 2016-06-16 09:38 ( Edited 2016-06-16 13:38)
change
s.dx=(rnd(.8).4)
to
s.dx=(rnd(.8)*.4)

should do the trick

P#22988 2016-06-16 09:44 ( Edited 2016-06-16 13:44)

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?

P#22989 2016-06-16 09:52 ( Edited 2016-06-16 13:52)
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

P#22995 2016-06-16 11:30 ( Edited 2016-06-16 17:54)

Actually foreach() is a built-in function that takes a sequence and a function. It calls the function for each element in the sequence. It is not a loop and doesn't take a block (no do or end). It looks correct in the above code.

P#22999 2016-06-16 12:56 ( Edited 2016-06-16 16:56)

My apologies, I was thinking of for

P#23005 2016-06-16 13:52 ( Edited 2016-06-16 17:52)

Thanks so much - it worked with those revisions!

P#23043 2016-06-17 02:00 ( Edited 2016-06-17 06:00)

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.

P#28104 2016-09-06 16:48 ( Edited 2016-09-06 20:48)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2023-01-30 07:21:32 | 0.007s | Q:19