Log In  


Hi everyone,

In a try to make my code cleaner, I am trying to get all the junk I was putting in _update into its own function, but failing.

I copy pasted the exact same code and put it in a function called "game_update", then called "game_update()" from the _update function, and I get a runtime error: Attempt to call global 'game_update' (a nil value)

If I copy that back into update, the game works.

I read that in lua the order you define things in is important. My init, update and draw are at the bottom of the code so this shouldn't be the problem (I moved them atop and also didn't work).

Any idea what could be happening here??

1


The order in which you define functions is not important, unless you have code that is in the top level outside any function, and that code tries to call a function. Lua will first read all the code and execute it in order. _update() is not called until after that, so all your functions are already defined.

Something else must be going on, but I think the best way we will be able to tell is if you post the code (or an equivalent example that reproduces the error) here.


Well I went through the whole code, cleaned up, undid and re-did everything, and now it's working. I have no idea what was causing it, but pico8 was even reporting errors at the wrong lines, so it wasn't much help. I wish debugging was easier, the error reporting is not very precise and that makes me get stuck.

So I learned nothing from this mistake, because I don't really know what fixed it. To me it looks the same. Oh well.

Thanks for your help kittenmaster!


It helps to record the exact state of things. Multiple copies of your source code everytime you change things. Screenshots, etc. For us and for you, that way you CAN learn what was going on.

Personally I've found the Pico8 debugger to tell me what I did wrong nearly every time I did something wrong. Very rarely does it every get the line wrong in my experience unless there actually is a seperate problem earlier in the code. Usually closed brackets, braces, parenthesis, or quotations.

Version control isn't always necessary but if you're practicing neat and tidy coding methods might as well go the full distance with neat and tidy version control. Coding Pico8 on github or similar is a pretty simple setup and it will help you really understand each and everytime something goes wrong, exactly what it was. Not to mention it makes sharing your code with others very simple and it allows others to come in and make changes if you so allow it to.


You might have had a typo you weren't seeing.

The first program I ever wrote in C was hello world:

#include <stdio.h>

void main()
{
    prinf( "Hello, world!\n" );
}

Took me two hours to figure out why it was complaining that "prinf" wasn't defined.

I'd missed the 't' in "printf" and my brain was refusing to notice it.


Also, agreed, version control is a good idea, even if you're not working with other people. Lets you diff versions to see what changed.

For that matter, learn to use a good visual merge/diff program. I like Beyond Compare, but mileage varies pretty strongly among differs. I used to prefer Araxis Merge, but it's too expensive for personal use. BC is probably the cheapest of the paid programs, but there are good open-source ones as well.


i have no idea about version control, i'm not reall a coder, and it sounds a bit... scary and boring :P

I DO however normally keep tons of backups, i have notepad++ setup to save one every time I click save, but unfortunately for me, this time, I had cleaned my pile of backups the day before :/

I am pretty sure that here my problem was a missing bracket, comma or extra "end" statement.

y problem with the error is that it kept reporting the problem at a line where there was literally nothing, or absolutely nothing related to the error in question. That's why I feel that maybe there wasa misplaced delimiter that was making the program think things were arranged nin a different way.

I might learn that version control down the line mayb, but for the time being, i want to focus on lerning how to make things with pico8! Even if I have to pull my hairs out every now and then :P

Thanks again guys!


Version control is just tooling to help you make organized backups, really. Don't be scared, it's your friend. :)


Version control means basically what you have notepad++ setup to do, but a DIFFERENT save file each and every time. So you'll always have every change you've ever made. Places like github make this very simple as they keep up with all of the changes for you


If you mean like what a Word document does, where it shows you exactly what's different, yeah notepad++ doesn't do that, although it does save a new file every time i hit "save". It's just harder to compare (but you can roll back perfectly to whatever point in time you want).

I'll look into github at a later point. Thanks for all your input!


Suggest to switch to Visual Studio Code - gives you Git integration and code compare (and much more!)



[Please log in to post a comment]