Log In  
Follow
astinad
[ :: Read More :: ]

function very_tiny_silly_but_also_hey_WTF_rant()

Could the built-in demo variable names be any less helpful for n00bs? From demos/hello:

for i=1,11 do
  for j0=0,7 do
  j = 7-j0
  col = 7+j
  t1 = t + i*4 - j*2
  x = cos(t0)*5
  y = 38 + j + cos(t1/50)*5
  pal(7,col)
  spr(16+i, 8+i*8 + x, y)
  end
 end

What does j0 mean? jack0ff? What about j for that matter? I see col, which could mean column, but then I would expect row or something similar for a multi-dimension loop. t1? The t-1000 terminator? Bah! Humbug!

There's a ton of greatly helpful advice in the pico zines and in the forums here, but it just strikes me as frustrating to show n00bs the hello world demo and it just purposely uses these incredibly unhelpful variable names. I've always been taught that function names and variable names should be self explanatory as to their purpose for ease of code reading, particularly in an example meant to demonstrate program functionality.
end

P#71432 2019-12-27 04:18

[ :: Read More :: ]

Does print() in _update() work?

Hi there! Just purchased PICO-8 and Voxatron last week and I'm trying to recreate some classic pong action as a way of getting familiar with the ins and outs of the scripting environment (this is my first time ever interacting with anything related to Lua). Right now I've got a paddle that responds to up/down keyboard presses and a ball that bounces around the screen and collides with the paddle.

I'm trying to print some debug text at the moment of paddle + ball collision, but my print function appears to be doing nothing.

Here's what my current gameplay looks like:

And here's the code:
(the print function that appears to not be working is in line 53 - i.e. the 3rd line from the bottom)
(unrelated: sure would be nice to have line numbers on code snippets here in the forums!)

ball_x = 64
ball_y = 64
ballspeed_x = 3
ballspeed_y = 2
pad_x = 20
pad_y = 50
pad_w = 4
pad_h = 20

function _draw()
    rectfill(0,0,127,127,5)
    circfill(ball_x,ball_y,2,14)
    rectfill(pad_x, pad_y, pad_x + pad_w, pad_y + pad_h, 10)
end

function _update() 
    moveball()
    updateballcollisions()
    movepaddle()
    updatepaddlecollisions()
end

function moveball()
    ball_x += ballspeed_x
    ball_y += ballspeed_y
end

function updateballcollisions()
    if (ball_x < 0 or ball_x > 127) then
        ballspeed_x *= -1;
    end
    if (ball_y < 0 or ball_y > 127) then
        ballspeed_y *= -1;
    end
end

function movepaddle()
    if btn(2) and pad_y+(pad_h/2) > 0 then
        pad_y -= 4
    end
    if btn(3) and pad_y+(pad_h/2) < 127 then
        pad_y += 4
    end
end

function updatepaddlecollisions()
    pad_top_y = pad_y
    pad_bot_y = pad_top_y + pad_h
    pad_left_x = pad_x
    pad_right_x = pad_left_x + pad_w
    if ((ball_x > pad_left_x) and (ball_x < pad_right_x) and (ball_y > pad_top_y) and (ball_y < pad_bot_y)) then
        ballspeed_x *= -1
        print("paddle collision", 6, 6, 11)
    end
end

As you can see in the gameplay gif, my updatepaddlecollisions() function seems to be working correctly when the ball collides with the paddle except that there should also be a string "paddle collision" that prints at (6, 6) colored green (color 11), but that string never prints! :(

I'm aware of the printh() function but I'd really like to stay within the editor and just have my debug text print directly onto the app screen.

So! Am I crazy or does the print() function not work if it's in _update() or some function that gets called within _update()? Thanks so much! I'm so excited to actually build cooler things with this amazing tool!

P#68968 2019-10-17 17:52 ( Edited 2019-10-17 17:54)

Follow Lexaloffle:          
Generated 2024-03-28 12:10:55 | 0.068s | Q:10