Hi Bouncy_block, welcome!
Can you give us a bit more context so we can help you find appropriate resources?
Do you have previous experience with programming and just need pico-8/lua specific resources? Or do you need help learning basic programming concepts as well?
What type of resources do you prefer? Written? Video? Either? Both?
Can you post a link to the tutorial you tried so we have an idea what didn't work for you?
In the meantime, some general recommendations:
- MBoffin's Top-Down Adventure Game Tutorial is a series of bite-sized videos which don't require any pico-8 experience. (https://www.lexaloffle.com/bbs/?tid=35135)
- Krystman has recently started a beginner tutorial series for Making a Shmup. New episodes come out twice a week, I think. He has other tutorial series as well like one for creating a Roguelike game. I wouldn't consider that one a beginner's tutorial though.(Shmup-link Roguelike-link)
- I've seen people recommend the Nerdy Teachers YouTube channel before. There aren't a ton of videos but what's there seems pretty good for learning the basics. (https://www.youtube.com/c/NerdyTeachers)
I have done a little bit of Lua coding in the past, (I was doing tic-80, and decided to switch) can't consider myself an expert at all though.
I like using video/written tutorials, and here is the video I was using: https://www.youtube.com/watch?v=XNTHqatlJsY&list=PLyhkEEoUjSQtUiSOu-N4BIrHBFtLNjkyE&index=6 It's just one in the series, but I don't feel like I was learning how to use functions, ect.
(I did the other ones. Even the website they have didn't really help)
Okay, so step one: ignore the third recommendation I gave you above since it's the one you've already tried! Do have a look at the other two though and see if those are more to your liking.
Also, if you haven't already head over to the resources page and try some of the stuff there. In particular Game Development with PICO-8 assumes you have no previous knowledge and walks you through how to use the various editors and creating two full (though very simple) games. And if that's a bit too easy there's a section which goes a bit more in-depth on some slightly more advanced topics, like how to manage game state, particle effects, etc. There are also links to additional resources at the end of the pdf.
When you say, "learning how to use functions," do you mean learning how to use the built-in functions that pico-8 provides you with? Or do you mean how/when/why to write your own functions? The official documentation is pretty comprehensive if you just need to find your way around the pico-8 API.
Otherwise, learning how to write your own functions is just a matter of learning the syntax, so that won't take you very long. It's just this:
function your_function_name_goes_here(parameter1, parameter2) -- code which does something goes here end -- call the function like this your_function_name_goes_here(1, 2)
There's a bit more to it than that but not much. You can have more or fewer than 2 parameters depending on what you need. You can, and usually will, return values from functions, like this:
-- this is a pretty useless function function two() return 2 -- this value is "sent back" to where the function was called from end x = two() print(x) -- will print 2 to the console.
The more difficult question is when and why would you write your own functions and that starts getting into issues of software design. Most tutorials won't cover that explicitly because they've either already done the design up front and are just walking you through the code, or because the project is simple enough that it's kind of designed-on-the-fly. So they'll define a bunch of functions but won't necessarily tell you why they made the decision to implement this function instead of some other function.
One guideline (not a rule!) is to have functions which only do one thing. So if you're writing a function and you notice that it's actually trying to do two (or more) things, then you can try to break up each "thing" into it's own function. Here's a sketch of the idea:
function _update() -- code which does the first thing for i=1,20 do -- does something 20 times end -- code which does the second thing if x == true then -- some code to execute when x is true else -- some code to execute when x is false end end
When we break that up into separate functions it looks like this:
function _update() first_thing() second_thing() end function first_thing() -- code which does the first thing for i=1,20 do -- does something 20 times end end function second_thing() -- code which does the second thing if x == true then -- some code to execute when x is true else -- some code to execute when x is false end end
There are a few advantages of this. The first is that if you want to remember what
_update does it's much quicker/easier to see: it does the first thing, then the second thing. You don't have to get bogged down in the details of how it's doing those things unless you want to. Another is that
second_thing() can now be re-used by other parts of your program. And since they only do one thing the chances of you being able to re-use them increases because they're fairly general.
Here's an admittedly contrived example: I'll write a function which finds the highest number in an array and then replaces all elements of the array with that number.
function replace_with_max(array) -- find the max value local max = array for i=2,#array do if array[i] > max then max = array[i] end end -- replace all elements with the max value for i=1,#array do array[i] = max end end
You can see that clearly has two "things" so I'll break them into their own functions, like so:
function find_max(array) -- find the max value local max = array for i=2,#array do if array[i] > max then max = array[i] end end return max end function replace_all(value, array) -- replace all elements with value for i=1,#array do array[i] = value end end
replace_with_max becomes this:
function replace_with_max(array) local max = find_max(array) replace_all(max, array) end
Notice in particular that
replace_all is more general. In the original I was always replacing with the max value but with
replace_all I can replace with any value I want. In
replace_with_max I'm still replacing with the max value, obviously, but in other parts of the program I could replace with other values, like the minimum value or 'bob' or whatever, so it's more versatile.
One great thing about PICO-8 is you have all the code for any cart you download. So a good way to learn is to play a bunch of games and anytime you come across a particular feature or something that you like you can dig around the code and try to figure out how the author did it. Don't try to understand the entire game but maybe there's a reflection effect or something that you really like, try and figure out just how that was done and then try to recreate it in a project of your own. Even just as a stand-alone demo of that effect all by itself.
Finally, if you're having trouble with something specific most people here are happy to help you figure it out if they can.
[Please log in to post a comment]