Log In  

In ROBLOX I am also learning how to code, but one thing stands out that I feel should be necessary.

What is supposed to happen is that it runs:

function _init()
   cls()
   spr(192,20,20,4,4)
   wait(3)
end

But it errors with
"Runtime error line 4 tab 0
wait(3)
Attempt to call global 'wait' (a nil value)
In _init line 4 (tab 0)
At line 1 (tab 1)"

Is there a way to make the program wait a few seconds without taking too much space?

Thanks :)

P#63498 2019-04-14 13:10 ( Edited 2019-04-15 13:53)

1

There is no built-in 'wait' command.
Pico basic program pattern is:

  • update state & game logic (_update)
  • clear + redraw screen (_draw)
    every 1/30s

To fit into this pattern, wait is nothing more than a counter. Once the counter reaches a given value, move on to the next game state:
Ex:

local mode="title"
local mode_t=0

function _update()
 mode_t+=1
 -- wait 3s (e.g. 90 frames)
 if mode=="title" and mode_t>3*30 then
  -- move on to next game state
  mode="game"
  mode_t=0
 end
end

function _draw()
 cls()
 if mode=="title" then
  spr(192,20,20,4,4)
 elseif mode=="game" then
  -- draw game 
 elseif mode="gameover" then
  -- draw game over screen
 end
end

Note: many other variants exist - just find one that suits your design.

P#63503 2019-04-14 15:40 ( Edited 2019-04-14 16:03)

There's also the question: Why do you want to wait? In a "game loop" pattern, like pico-8 uses, waiting the way you seem to want would take away control from the game loop, which would mean that the entire game would simply hang/freeze for a few seconds. That doesn't sound very useful. Try to think about what you want waiting to actually do, and then try to reframe that in a "game loop" model.

P#63510 2019-04-14 20:34

@freds72 Thanks, I'll make sure to use that.

@tobiasvl In console games, typically they fade in and out a logo with an amount of time. That's what I was trying to do. Also, it would help with animation.

P#63511 2019-04-14 20:36

Fade/animation is just using the mode_t counter to switch palette, move things on screen.
(or add other counters as you see fit!)

P#63522 2019-04-15 06:17

@freds72 Thanks!

offtopic: did you know that _update() can have draw stuff and _draw() can have logic stuff? I didn't know that but heck, I'm new to PICO-8 lol

P#63526 2019-04-15 13:51

_update can draw but do not do it
you need code in _draw, but again try to limit game state change as draw calls can be throttled by pico

P#63534 2019-04-15 15:19

So PICO basically makes calls work less if they aren't in the correct function?

P#63536 2019-04-15 15:33
2

Try this? ;)

function wait(_wait)
repeat
_wait-=1
flip()
until _wait<0
end
P#63541 2019-04-15 16:18 ( Edited 2019-04-15 16:19)

@BGelais Ooh, that's cool too!

We don't need any more responses, I get the gist of how to make a custom wait() thing. Thanks you guys :)

P#63543 2019-04-15 17:07
1

So PICO basically makes calls work less if they aren't in the correct function?
No - this is just to avoid your code being a total mess!

P#63544 2019-04-15 17:31
2

What freds72 meant by "throttling" was just that if you do too much CPU work each frame (ie. each callback of _draw and _update), PICO-8 will "drop frames"; it will skip a _draw() call to catch up. If you're just doing graphics stuff in _draw, then no harm, it will just not be drawn for that frame. (This is what usually happens if a game you're playing "lags" or "stutters" when FPS drops.) However, if you're doing actual game logic in _draw, then your game will behave weirdly and stuff will go out of sync.

P#63545 2019-04-15 18:41
1

If I recall correctly, when Pico-8's CPU is at maximum usage, it will instead call _draw() every other frame to keep up, which can cause problems if you have important stuff in _draw() that needs to happen every frame.

Edit: Whoops! I didn't see Tobias's explanation, so this is kinda redundant.

P#63546 2019-04-15 18:42 ( Edited 2019-04-15 18:42)
1

It's okay! All of you are helping which, uh... helps.

P#63547 2019-04-15 18:46

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 22:15:09 | 0.032s | Q:29