We'll here's some more sample work which is just basically a test haven for the functions. One odd, and something that I would consider bad, is the fact that after calling os.sleep and exiting the application(pressing the home button here) I am unable to go back to the application without restarting. I figured out that once it hits os.sleep() again at the next app run it just quits. To me it seems that I'm not cleaning up correctly upon exit. EDIT: When experiencing this the sudoku app seems to fix the issue and runs just fine...

While screwing around in trying to fix this I tried out os.exit();. Now this is supposed to exit the lua interpreter and return back to the main program. When I call it here, the whole thing just dies and I have to push the reset button. Does this mean the entire x-fi2 menu is coded in lua?!

ThievingSix, thanks, that's cool! I was thinking of writing something similar, as I've got a pong app in mind.

And yes, I've run into the same issue with using the home button and then the app always doing a quick dump after starting. That's why I added a close tap to my last script. But yeah, it looks like a cleanup issue.

If I'm correct, I believe dofile() will actually execute X.LUA. In your case I believe you want to use loadfile() instead.

Oh wait, sorry, did you mean like as if the function was called? so that the follwing init(); line is redundant? That didn't occur to me at all. Hmm, I'll have to check. I'll report back how these things behave.Thanks.

Yeh, LUA is brand new to me but I think I have grasp(This reminds me of mIRC scriping lol). Basically when we have a plain text lua file that hasn't been compiled dofile()/loadfile() will compile it and assign it to a function variable.

As such this:

Code:

myfunc() = loadfile("x.lua");

is valid.

dofile() will execute any non-function encased code. If I'm correct the entire shell that we use to browse music, videos, etc on our player is made in lua. If this is the case then when we click on our application it's calling dofile("MAIN.LUA").

OK...
dofile() will load and execute a file as lua code.
loadfile() will allow loading a file as a function.

To use dofile():

Code:

dofile("x.lua");
init();

where X.LUA is:

Code:

function init();
text.draw(0,0,"hi");
end;

An equivalent using loadfile():

Code:

init = loadfile("x.lua");
init();

where X.LUA is:

Code:

text.draw(0,0,"hi");

The benefit of dofile() is that the code just runs, like a PHP include(), good if you want to just run a snippet of code, or add a collection of predefined functions. The benefit of loadfile() is that you get a function that can be named whatever.

this way it doesn't need a control.read() done elsewhere, and doesn't make 2 jumps back to the main menu.

EDIT: It's not perfect though, something is still missimg. Run your app, close with Home, run your app again, it's fine. But run your app, close with Home, run Sudoku, and Sudoku closes right off, but runs a second time.

I just hope in the future firmware they switch to vertical view (like iTouch, S9) instead of horizontal...you need to hold the player with both your hands to make this horizontal angle work by the looks of it...so vertical would be heaps cool.

Edit: Really disappointed that os.execute() is non-existent seeing as it's supposed to be a lua standard.

Edit2: My guess as to why this fixes it is this: The control table accesses a queue. When pressing the home button we activate a down and up sent to the queue. First we see if there is anything to be read with control.read(). Next we see if the thing we read is a button. Then if it's the home button. Finally we remove the entire thing from the queue with button.click(). When we didn't add button.click() nothing got removed from the queue. When we added button.up() we only removed the first part.

yes this control queue is something to sort out. I found that if I did the same test twice, only the first code ran. But if I used the test once to set a boolean flag, I could use that to run both sets of code no problem. I also noticed that if the read() was run once, it was good for subsequent tests. Bizarre.