Log In  


I've started doing something in Pico-8, but when i am trying to follow the particle tutorial from Picozine 1 (even if i get the text correct) and run it i get an error like

This is the code: http://hastebin.com/akaqebefav.lua

Any help?



on line 40 you have

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

maybe it should be

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

i'm not sure what the intention of that line is so i'm just guessing


That worked but i got another error:


Can you paste the code somewhere?


Here it is.

pico-8 cartridge // http://www.pico-8.com
version 5
__lua__
--super wheelbot!!
--by dynamicill

function _init()
 level=2
 px=10
 py=104
 pstate=0
 pspr=0
 pdir=0
 pat=0
 pdied=false

 smoke={}
 cursorx=50
 cursory=50
 color=7

 if level==1 then
  px=10
  py=104
 end
end

function canfall()
 --get the map tile under the player
 v=mget(flr((px+4)/8),flr((py+8)/8))
 --see if it's flagged as wall
 return not fget(v,0)
end

function change_state(s)
 pstate=s
 pat=0
end

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 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 draw_smoke(s)
 circfill(s.x,s.y,s.width,s.col)
end

function _update()
 if pdied==false then
  b0=btn(0) --button0 state
  b1=btn(1) --button1 state
  b2=btn(2) --button2 state

  px=(px+128)%128 --no bounds left and right
  pat+=1

  --idle state
  if pstate==0 then
   pspr=0
   if (b0 or b1) change_state(1)
   if (b2) change_state(3)
   if (canfall()) change_state(2)
  end

  --walk state
  if pstate==1 then
   if (b0) pdir=-1 sfx(0)
   if (b1) pdir=1 sfx(0)
   px+=pdir*min(pat,2)
   pspr=flr(pat/2)%2

   if (not(b0 or b1)) sfx(1) change_state(0)
   if (b2) change_state(3)
   if (canfall()) change_state(2)
  end

  --fall state
  if pstate==2 then
   pspr=32
   sfx(2) 
   if (canfall()) then
    if (b0)px-=1 --steer left
    if (b1)px+=1 --steer right
    py+=min(4,pat) --move the player
    if (not canfall()) py=flr(py/8)*8 --check ground contact
   else
    py=flr(py/8)*8 --fix position when we hit ground
    change_state(0)
   end
  end
 end

 --jump state
 if pstate==3 then
  pspr=1
  py-=6-pat
  if (b0) px-=2
  if (b1) px+=2
  if (not b2 or pat>7) change_state(0)
 end

 --player death
 if py>=134 then
  if pdied==false then
   sfx(3)
   pdied=true
  end
 end

 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
end

function _draw()
 --draw the world
 map(0,0,0,0,16,16)
 --draw the player
 spr(pspr,px,py,1,1,pdir==-1)
 --draw smoke
 foreach(smoke,draw_smoke)
end

Looks like you have an extra "end" at the end of this block:

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
end


Aw shot! didn't notice that, but then next i have another problem:

What i could tell is that the tutorial was made before some bugs were fixed in this version. :|


if (sp.t > sp.max_t15) then

should be something like

if (sp.t > sp.max_t - 15) then

here's code that runs: https://transfer.sh/ZksND/smoke.p8

though it doesn't look like it should, so there'll be a few more things to fix in there


thanks, this worked out, the picozine had grammatical errors sometimes, :P

Also, do anyone know how to make the player bump from the ceiling of the block and aswell how to do single-screen levels?


Yes, but it won't be of any use to you. Do you understand what the program from picozine does and how it works? There is no point in just typing in the source code. I recommend starting with something very very simple, like a pixel moved by arrow keys. Can you do that?


Yeah. Seems simple. i'm doing a platformer based off the tutorial from Picozine 2


Hey Dynamicill, if it helps here's a template I put together for making platformer games. I tried to comment it helpfully; it's an adaptation of this one: https://www.lexaloffle.com/bbs/?tid=2119. I copied it out manually to really get familiar with it.


Oop, here it is, I think this time.

Cart #18106 | 2015-12-31 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

Once having copied it out, I made the necessary changes where I saw fit. I aimed for it to be reasonably customisable, but it was intended for personal use so may be a bit of a hassle to reuse, best of luck regardless!


Looks good.



[Please log in to post a comment]