Log In  

how much code do you usually write in there?

at around 400 lines it's getting hard to manage for me.

P#10063 2015-04-20 21:12 ( Edited 2015-05-19 01:00)

I've made two incomplete games, one sitting at about 400 lines and the other at about 600 so far.

Some things I found to help:
Make lots of small comments, short and to the point.
Make lots of functions.
Name the functions well, you easily know what they do by name alone.
I like to name my function starting with update or draw. ie. draw_lines() or update_actors(). This goes back to naming them well.
Holding alt and pressing up or down jumps you to the previous or next function. By segregating tasks into functions (even if not necessary) you can later find the block of code you need quickly.

Hope that helps.

P#10069 2015-04-20 21:32 ( Edited 2015-04-21 01:32)

yeah i've found that keeping my code super organized helps

all init functions grouped, all update functions grouped all draw functions grouped in a common order.

P#10078 2015-04-21 07:31 ( Edited 2015-04-21 11:31)

The best shortcut though is still alt-up/down to jump to the previous/next function. But yeah, keeping clean code on such a small editor is quite hard and I'm really tempted to copy/pasta this into vim/Sublime text/notepad to have a better view of the code :/ ...

P#10088 2015-04-21 13:15 ( Edited 2015-04-21 17:15)
:: 23

My LD game got to about 600 lines and by the end I definitely wanted to take vim to it to rearrange some of the functions, thought grouping things like akilism mentioned (draw functions, update functions) helped tremendously.

If I had to pick a few vim features that would help a lot,

  • marks - I don't use these a ton in normal vim, but a list in the top-left would be lovely
  • keyboard visual selection - the mouse is nice but implied scrolling is always a little weird
  • tags - either as a simple "jump to word under cursor" or "jump to [function <word-under-cursor>] or a more sophisticated system this'd be lovely (looks like ctags supports Lua too!)
P#10094 2015-04-22 10:42 ( Edited 2015-04-22 14:42)

311 lines on my super-simple fly-through-the-walls game. I'll probably hit 400 if/when I update it to have a title screen and 2-player/difficulty options.

I kept my code mostly grouped by which part of the game they handle--effects in one place, player's update/draw functions in one place, wall update/draw functions in one place (the collision-handling code went in between them) and then _init, _update, and _draw in that order.

I kept thinking that I'd be happier using Sublime Text to edit this stuff, but I wound up doing all my code in the built-in editor. You'd think I would miss my find/replace, but I really didn't need it.

P#10095 2015-04-22 11:15 ( Edited 2015-04-22 15:15)
:: jph

I have Sublime on the right and pico on the left, cut and past back and forth as needed,. mostly still reading the API but I can see it will be tight to work fully in the little terminal,.

P#10150 2015-04-23 10:20 ( Edited 2015-04-23 14:20)
:: viza

Hmm, I just open the p8 file directly in Sublime, switch the syntax coloring to lua, and code away, no need to cut-and-paste around.
Slightly less convinient to launch the game (after saving in Sublime, switch back to pico-8, and press up,up,enter,up,up,enter (= go back in history to load, and go back in history to run)), but MUCH more convinient to code. :)
Ohh, and you must pay attention that the p8 file contains all other data besides the code too - so if you modify your sprites or sounds or whatever, you must remember to save in pico-8, otherwise you will overwrite you non-code changes with the previous version from the open p8 in Sublime.

P#10276 2015-04-28 09:14 ( Edited 2015-04-28 13:14)
:: luke

Write comments and learn to get used to cmd f + cmd g

P#10290 2015-04-28 17:24 ( Edited 2015-04-28 21:24)
:: toffer

I found this ugly trick to avoid reoad load/run manualy each time when switching back from an external editor.
Put this at the end of the lua souce (replace cartname wiith the current one)

if peek(0x4300) == 0 then
    poke(0x4300,1)
    load("cartname")
    run()
else
    poke(0x4300,0)
end

Run once > edit in external editor & save > switch back to pico8 > Ctrl+R

P#10294 2015-04-28 17:47 ( Edited 2015-04-28 21:47)

Thanks for that trick, toffer! I've been using the heck out of it 'cause I can't live without vim keybindings :)

P#10774 2015-05-18 19:51 ( Edited 2015-05-18 23:51)
:: zep

@toffer -- that's ingenious!

How about this:

Using CTRL-R to run automatically reloads the last loaded/saved filename if there are no unsaved changes.

So if you make edits to code both externally and in pico-8's editor and then CTRL-R, only the later will be observed. If you don't use an external editor at all (and you don't otherwise mess with the cart file while editing), CTRL-R will have the same behaviour as it currently does.

P#10776 2015-05-18 20:51 ( Edited 2015-05-19 00:53)

Yes, please! :D That would be amazing.

P#10778 2015-05-18 21:00 ( Edited 2015-05-19 01:00)

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2020-05-25 06:09 | 0.020s | 2097k | Q:37