abi>>forums

abi>>forums (http://www.anythingbutipod.com/forum/index.php)
-   Zen X-Fi2 Applications & Development (http://www.anythingbutipod.com/forum/forumdisplay.php?f=221)
-   -   FAQ for Application/Game making (http://www.anythingbutipod.com/forum/showthread.php?t=53192)

Tetrajak 03-07-2010 05:16 PM

FAQ for Application/Game making
 
I figured it was about time we had one of these since there are a few questions that keep popping up in multiple threads.
Last Updated 18th March 2010 for firmware version 1.11.01

Got a question about programming for the ZEN X-Fi2 and it's not on this list? Why not ask it in a reply to this thread?


F.A.Q.

Q. I want to make an application/game, but I'm not sure what kind of thing to make, got any ideas?

A. Check out the Application/Game Ideas thread to see what other people have suggested.


Q. I want to make an application/game, but I don't know how to code, can someone teach me?

A. There are a lot of online resources that can teach you the programming language used to make applications for the X-Fi2. Creative have a very useful development kit to help people who want to program applications for it. The development kit also contains an introduction document that gives a lot of useful information on programming for the X-Fi2.


Q. What coding language are the X-Fi2 applications made with?

A. The applications are made with a coding language called Lua. You can read all about it and also get tutorials from the language's main site.


Q. What program should I use to code applications with?

A. Some of the members here use Notepad++ or LuaEdit to make their applications.


Q. My application crashes on my player, what's wrong?

A. You may want to check out Creative's Applications Developer Kit which includes a very useful simulater that can usually tell you where things are going wrong.


Q. Some of the functions from the Lua.org documentation don't seem to work on the X-Fi2, why?

A. Creative decided not to include some of the other functions in their Lua interpreter. The functions that do work are documented at ThievingSix's X-Fi2 Lua Wiki. If you want the functions added, I recommend you head over to the Creative MP3 Player forums and start a thread about it, or contribute a post to one of the other relevant threads.


Q. One of the functions doesn't work like it's supposed to, what's wrong?

A. Some of the functions, such as the thickness in the screen.drawline function and the reading of lines from a file in io.lines don't work entirely correctly. You can report these to Creative through their technical support page. The more people that report the fault, the more likely it is to get fixed!


Q. The sound in my application doesn't work, what's wrong?

A. Make sure the sounds you're using in your application are .WAV files at 44100Hz (44.1kHz), 16bit and stereo. To do this use a program such as Audacity or Formatoz. Got another program you use to alter your .wav files? Why not let the FAQ know?


Q. How do I convert a sound file I have to the right kind of .WAV file using Audacity?

A. Open the sound file you have in Audacity. On the bottom left of the window is a small button called Project Rate. Set the rate to 44100Hz. Once you've done that, click the file menu and "Export as WAV". Done!


Q. My image files don't display on the screen where I want them to, what's wrong?

A. Did you know that the x,y position you give for where on the screen the image should display is the top left pixel of the image, not the center?


Q. The accelerometer doesn't work in the ADK simulator, what's wrong?

A. Creative didn't implement an accelerometer in the simulator, so the only way to test an application that uses the accelerometer is to test it on the X-Fi2 itself. If you get errors, it may be a good idea to look at the code of other people's applications that use the accelerometer and try and figure out where your code went wrong.


Q. My application works in the simulator, but still not on the player, why?




A. There are a number of reasons for this to happen. Sometimes one of the functions hasn't been written properly for the player's Lua interpreter, other times the simulator doesn't account for some of the player's limits. Therefore there are multiple answers to this question;
  • First, check to see if any of the other questions in this FAQ answers your question more specifically, then come back here.
  • If you are using control.read() in your application you must have (at least) an os.wait(40) or os.sleep(4) in an else statement. You can go without os.wait() or os.sleep() if you use control.read(1) instead.
  • Drawing images or pixels outside the edge of the screen (less than 0,0 is usually the cause) can cause the player to shut down.
  • Drawing large .PNG that have translucent pixels that are bigger than the screen (400,240) can cause the player to crash.
Got another cause for this? Why not let the FAQ know in a reply on this thread?


Q. I've finished my application and it no longer has any errors, where on the net should I post it to share it with people?

A. You can post it on these forums in the Finished Games & Applications sub-forum or at Xeroo.net. Got another place people can share their apps? Why not let the FAQ know with a reply to this thread?

Habhome 03-07-2010 05:23 PM

Nice one Tetrajak, this will definitely be useful! Thanks for taking the time to compile it.
(Thread stickied)

Tetrajak 03-07-2010 05:26 PM

Quote:

Originally Posted by Habhome (Post 449046)
Nice one Tetrajak, this will definitely be useful! Thanks for taking the time to compile it.
(Thread stickied)

You're welcome! I was kind of surprised one hadn't been made yet, so I thought I'd fill the gap. I hope people find it useful!

Habhome 03-07-2010 05:30 PM

Quote:

Originally Posted by Tetrajak (Post 449047)
You're welcome! I was kind of surprised one hadn't been made yet, so I thought I'd fill the gap. I hope people find it useful!

I think we've all been too focused on the apps themselves to think of making an FAQ. Though I believe it was just a matter of time before somebody got tired of answering the same questions over and over again.
Thanks yet again, now let's leave the replies to those who want to contribute to the FAQ :)

delirius 03-07-2010 06:13 PM

Quote:

Originally Posted by Tetrajak (Post 449043)
Q. My application works in the simulator, but not on the player, why?

A. If you are using control.read() in your application you must have (at least) an os.wait(40) or os.sleep(4) in an else statement. You can go without os.wait() or os.sleep() if you use control.read(1) instead. Got another cause for this? Why not let the FAQ know in a reply on this thread?

I have run into another reason for app crash. When implementing tileengine, loading tilemaps in png somewhat bigger then screen resolution (400x240) crashed player, but run fine in simulator. Weirdest part is that big jpg pictures worked fine. Maybe extra chunk of memory needed for alpha channel was problematic.

Tetrajak 03-07-2010 06:56 PM

Quote:

Originally Posted by delirius (Post 449060)
I have run into another reason for app crash. When implementing tileengine, loading tilemaps in png somewhat bigger then screen resolution (400x240) crashed player, but run fine in simulator. Weirdest part is that big jpg pictures worked fine. Maybe extra chunk of memory needed for alpha channel was problematic.

It may well be the way the image encoding is read by the player's OS, although I'm not sure. As you say, another possibility may be the memory buffer or the use of alpha channels on larger images. I have updated the FAQ to reflect this, thank you for your addition.

b.wofter 03-15-2010 02:27 AM

I'm not sure if anyone here knows or if this is really the right place but I was wondering if there was any information on the X-Fi2s processor and ram specs? And, also, if it would be possible to make an emulator of sorts for something like the gameboy color for it? Just a small thought.

Tetrajak 03-15-2010 12:51 PM

Quote:

Originally Posted by b.wofter (Post 451287)
I'm not sure if anyone here knows or if this is really the right place but I was wondering if there was any information on the X-Fi2s processor and ram specs? And, also, if it would be possible to make an emulator of sorts for something like the gameboy color for it? Just a small thought.

The specs can be found on wikipedia (I think). A small rundown of the hardware can be found here; http://en.wikipedia.org/wiki/Creative_ZEN#Hardware . Someone on this forum (ThievingSix, perhaps?) also took one apart to see what was inside.

As for a GB emulator, I'm not sure. It all depends how clean the code is and whether it can read roms. I'd say no because Lua is such a high level language that building a program for such a spe******ed purpose is difficult, considering all the other background stuff it does as a language, you'd be better off coding something like an emulator in C or C++. I could, however, be wrong.

b.wofter 03-16-2010 09:19 PM

if the processor is what it says it is, hardware-wise it should be possible. (given the fact the Gameboy Color and Gameboy had a 4mhz processor and apparently the x-Fi2 has at most 300mhz), though you might be right about the coding problem. The x-Fi2 can't run C++ based programs can it?

Tetrajak 03-16-2010 09:26 PM

Quote:

Originally Posted by b.wofter (Post 452031)
if the processor is what it says it is, hardware-wise it should be possible. (given the fact the Gameboy Color and Gameboy had a 4mhz processor and apparently the x-Fi2 has at most 300mhz), though you might be right about the coding problem. The x-Fi2 can't run C++ based programs can it?

Well, the device can as the OS it runs (Nucleus RTOS) can run C++. However, having said that, Creative haven't set the OS up to be able to run C++ as it doesn't have an interpreter. They've also disabled the C and auxillary libraries in the Lua interpreter, so you can't run it through that either.

Brett_val 03-25-2010 01:54 PM

Is it possible to draw a scissor rectangle of a stretched image?

I'm looking for a combination of these two:
myimage:draw(0,0,0,0,32,32) --only draws part of the image
and
myimage:draw(0,0,x,y) --to stretch an image.

If you're wondering why:
Since it is possible to stretch an image beyond the screen resolution as long as the original image is not bigger than 400x240, and thus creating a scrollable environment larger than the screen, I'd like to be able to only redraw the parts that have changed, because loading the whole image every frame is way too slow.

Tetrajak 03-25-2010 03:27 PM

Quote:

Originally Posted by Brett_val (Post 455139)
Is it possible to draw a scissor rectangle of a stretched image?

I'm looking for a combination of these two:
myimage:draw(0,0,0,0,32,32) --only draws part of the image
and
myimage:draw(0,0,x,y) --to stretch an image.

If you're wondering why:
Since it is possible to stretch an image beyond the screen resolution as long as the original image is not bigger than 400x240, and thus creating a scrollable environment larger than the screen, I'd like to be able to only redraw the parts that have changed, because loading the whole image every frame is way too slow.

As far as I know, the answer to your question is no.

Brett_val 03-27-2010 03:38 PM

Quote:

Originally Posted by Tetrajak (Post 455163)
As far as I know, the answer to your question is no.

Thanks for the information. I've ditched the idea. It was for ZenDuck, so that's why there is no background in the Chase Mode.

I've got another thing on my mind:
I see everyone using true and false in their code, at places where I use 1 and 0. For example here in Gruffler's Minigolf:
Code:

                elseif (control.isButton() == 1) and (button.click() == 1) then
                        if menu == true then
                            endgame = true
                        elseif menu == false then
                                menu = true
                        end
                end

In my ZenDuck code, I have something similar:
Code:

                elseif control.isButton()==1 then
                        if button.click()==1 then
                                if mode==0 then
                                        menu=0
                                else
                                        mode=0 win=0
                                end
                        end
                end

(the loop is a while menu==1 loop, so therefor it quits the application)

Is there an advantage in using true and false, or is it just the same as using 1 and 0?
To be honest I think working with numbers provide more possibilities, because true and false are just two options, while a number can be nil, 0, 1 and so on..
But as the more advanced codes are using true and false, I must be overlooking something?

(I thought this would be the best thread to ask questions about lua coding, if it's not, please say so and I'll stop asking questions here.)

Tetrajak 03-27-2010 06:06 PM

Quote:

Originally Posted by Brett_val (Post 455828)
Thanks for the information. I've ditched the idea. It was for ZenDuck, so that's why there is no background in the Chase Mode.

I've got another thing on my mind:
I see everyone using true and false in their code, at places where I use 1 and 0. For example here in Gruffler's Minigolf:

Is there an advantage in using true and false, or is it just the same as using 1 and 0?
To be honest I think working with numbers provide more possibilities, because true and false are just two options, while a number can be nil, 0, 1 and so on..
But as the more advanced codes are using true and false, I must be overlooking something?

(I thought this would be the best thread to ask questions about lua coding, if it's not, please say so and I'll stop asking questions here.)

I think ThievingSix would be able to answer that one better than me, but I think it's because true and false, as values and variables, are less data in the memory than a number variable. Boolean variables may also be assessed a lot quicker than numbers. I haven't personally investigated this, and I could be wrong.

delirius 03-27-2010 07:25 PM

Quote:

Originally Posted by Brett_val (Post 455139)
Is it possible to draw a scissor rectangle of a stretched image?

I'm looking for a combination of these two:
myimage:draw(0,0,0,0,32,32) --only draws part of the image
and
myimage:draw(0,0,x,y) --to stretch an image.

If you're wondering why:
Since it is possible to stretch an image beyond the screen resolution as long as the original image is not bigger than 400x240, and thus creating a scrollable environment larger than the screen, I'd like to be able to only redraw the parts that have changed, because loading the whole image every frame is way too slow.

use tiles http://www.anythingbutipod.com/forum...64&postcount=7

ThievingSix 03-28-2010 10:07 PM

Quote:

Originally Posted by Brett_val (Post 455828)
Thanks for the information. I've ditched the idea. It was for ZenDuck, so that's why there is no background in the Chase Mode.

I've got another thing on my mind:
I see everyone using true and false in their code, at places where I use 1 and 0. For example here in Gruffler's Minigolf:
Code:

        elseif (control.isButton() == 1) and (button.click() == 1) then
            if menu == true then
                endgame = true
            elseif menu == false then
                menu = true
            end
        end

In my ZenDuck code, I have something similar:
Code:

        elseif control.isButton()==1 then
            if button.click()==1 then
                if mode==0 then
                    menu=0
                else
                    mode=0 win=0
                end
            end
        end

(the loop is a while menu==1 loop, so therefor it quits the application)

Is there an advantage in using true and false, or is it just the same as using 1 and 0?
To be honest I think working with numbers provide more possibilities, because true and false are just two options, while a number can be nil, 0, 1 and so on..
But as the more advanced codes are using true and false, I must be overlooking something?

(I thought this would be the best thread to ask questions about lua coding, if it's not, please say so and I'll stop asking questions here.)

"An important point to note is that the value 0 is not a false test condition in Lua."

So 0 does not equal false. So it's the developers of the firmware that made that choice. Personally I don't see any advantage to either one.

Brett_val 03-30-2010 03:44 PM

Wow thanks a lot, all of you ! :) I finally see what not is for, and why a code sometimes just says while menu do.

And actually I do see advantages; simpler and cleaner coding and therefore less bytes in a code, and because true and false are less data in the memory, and may also be assessed a lot quicker, there's no reason not to use them when you can, I think.

ThievingSix 03-30-2010 03:51 PM

true and false came after the 0, 1. I don't think it's less data because true and false is 0 and 1.

Brett_val 03-31-2010 04:05 PM

Quote:

Originally Posted by ThievingSix (Post 456832)
true and false came after the 0, 1. I don't think it's less data because true and false is 0 and 1.

Okay, in that case, you'd only have the advantage of some bytes less because you can omit the true sometimes, and toggling takes less writing.
I guess it's just a personal choice indeed.

ThievingSix 03-31-2010 04:36 PM

Well it's still the same number of bytes in memory. Once it gets compiled into byte code when you run it or if you precompile it, you will still get it as if Boolean = true, even if you omit the "true".

So true, it is personal choice. But as for the original question as to why Creative does it, we'll never know.


All times are GMT -5. The time now is 02:05 PM.