Log In  

Hi. Going through the Smoke Particle section of zine #1 and found an error I couldn't solve. If you copy paste the following 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
 s.max_t = 30+rnd(10)
 s.dx = (rnd(.8).4)
 s.dy = rnd(.05)
 s.ddy = .02
 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

.. you get 'syntax error line 10. ')' expected near '.4'. I changed the line to

 s.dx = (rnd(.8))*.4

which seems to have fixed the problem, but then you get 'line 27: attempt to compare nil with number. in _f line 27. in _update line 37'

Anyone know a fix?

The cartridge that the tutorial points to at the end seems broken as well (https://www.lexaloffle.com/bbs/?tid=1920)

Edit: if you replace 'sp.max_t15' with a number it works ok.

P#20018 2016-04-27 05:55 ( Edited 2016-09-08 18:23)

:: tbsp

I suspect 'sp.max_t15' should be 'sp.max_t+15'.

P#20045 2016-04-28 14:22 ( Edited 2016-04-28 18:22)

oh yeah, that was it. thanks!

P#20055 2016-04-29 09:32 ( Edited 2016-04-29 13:32)
:: dw817

This line too:

if btn(0,0) then cursorx-=1 end

Otherwise hitting left just flushes the plotter against the edge.

P#28112 2016-09-06 20:56 ( Edited 2016-09-07 00:56)
:: mimick

I think sp.max_t-15 would be even better, it would allow the particles to grow just before disapearing.

P#28204 2016-09-08 14:23 ( Edited 2016-09-08 18:23)

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2021-12-03 15:55:34 | 0.010s | Q:13