Script-making Tutorial?


CHiZZoPs

Still Fresh
Joined
Dec 26, 2005
Messages
10
Has a tutorial for script-making been created? I can't seem to find one anywhere and it seems integral to being able to enjoy the GP2X in so many ways.

Can someone point us to a link or, if one does not exist, consider making a rudimentary explaination?

Please?
 
script, just look to linux console command (sh script);)

for the GP2x your script always end with:
cd /usr/gp2x/
exec /usr/gp2x/gp2xmenu

and always start with:
#!/bin/sh
 
I'll offer some help. I had a few kind folks get me started so I'll pass on what I've learned :)

• Get programmer's notepad (google it). The line endings need to be set as Unix, so the GP2X can read then correctly.

Here's a basic format:

Code:
#!/bin/sh

 /mnt/sd/FOLDER/
./APPorGAME.gpe
sync

cd /usr/gp2x/
exec /usr/gp2x/gp2xmenu

^ This points to a .gpe file located in a folder and runs it. If you want to over-clock/change the LCD settings and then run a .gpe file, use this:

Code:
#!/bin/sh

/mnt/sd/cpu_speed.gpe 1 2 266 0.6
cd /mnt/sd/FOLDER/
./APPorGAME.gpe
sync

cd /usr/gp2x/
exec /usr/gp2x/gp2xmenu

^ This first runs the cpu_speed.gpe LCD Tweak program ... the first numbers are UPLL and +2 LCD Timing somethingorother ... they work for me, your screen may differ (the readme has more info). 266 is the cpu speed, and the last number 0.6 sets the gamma (in the latest version of cpu_speed, version 1.3) ... then it runs the .gpe file in the folder specified.


Here's one to launch a .gpe located in the root:

Code:
#!/bin/sh
/mnt/sd/APPorGAME.gpe
sync

cd /usr/gp2x/
exec /usr/gp2x/gp2xmenu

^ Voila! you can add the line "/mnt/sd/cpu_speed.gpe 1 2 266 0.6" after the "#!/bin/sh" to OC/Tweak the LCD first.


And here's one Woogal posted to just set the gamma after bootup:

Code:
#!/bin/sh

/mnt/sd/cpu_speed 1 2 200 0.6
sync

cd /usr/gp2x/
exec ./gp2xmenu --boot --disable-autorun

Hope it helps :)
 
i don't remember how to creat a script that creat an log file in the Sd card to see where is the probleme. like in this script i wnat to smbmount creat a log file in the root of the SD card to see where is the problem.

#!/bin/sh
insmod smbfs.o
smbmount //Yod4z/Pc /mnt/ext -o username=administrator,password=pass
cd /usr/gp2x
./gp2xmenu


i have just to modify this line?
smbmount //Yod4z/Pc /mnt/ext -o username=administrator,password=pass > mnt/sd/log.txt
 
Yod4z posted on May 12 2006 at 10:28 AM said:
i have just to modify this line?
smbmount //Yod4z/Pc /mnt/ext -o username=administrator,password=pass > mnt/sd/log.txt

Almost, but you will only get the 'stdout'. To get the error output use:
Code:
smbmount //Yod4z/Pc /mnt/ext -o username=administrator,password=pass  2> mnt/sd/log.txt
or to get both standard output and error output use:
Code:
smbmount //Yod4z/Pc /mnt/ext -o username=administrator,password=pass  &> mnt/sd/log.txt
You can even have two files - one for output and one for errors:
Code:
smbmount //Yod4z/Pc /mnt/ext -o username=administrator,password=pass  1> mnt/sd/log.txt  2> mnt/sd/err.txt

If you want to append to your logs - not overwrite them - replace > with >>
 
Last edited by a moderator:
This is a really good thread! I had no idea that I wasn't really overclocking anything when I ran cpu_speed.gpe to overclock, then went back to the menu, then loaded my game/emu (didn't know that the menu resets the clock speed, doh!). Now that I've actually used scripts to overclock, it makes a huge difference!!

I don't think many n00bs like myself understand that you have to use scripts to overclock unless it is built into the program (eg. psx emu). The above posts helped me greatly in this regard, and I created my own scripts last night (that actually worked!!)! :lol:

Some of the other n00bs that come on this board bashing the 2x after having it for a short while may be confused on this point as well. Nowhere was this spelled out for me, but now that I understand this, it has totally changed my experience with the 2x. Many times people alluded to it in posts, but I always thought it was optional (or a shortcut). Although, maybe I'm just dumb and all this is common knowledge. :unsure:

Maybe this thread should be sticky material?
 
I just found this thread while looking for a solution to my tv-out trouble. Thought I'd bump it as I personally found this very helpful.

Maybe I'm just lazy, but I'd rather not go through a general Linux scripting tutorial just in order to overclock a few programs and such. I'd rather have; A: A good and specific tutorial that tells you how to make the basic scripts you sometimes need in the Gippex, or B: A list of template scripts that do specific things, with instructions on what to change in order to make it work with what you're making the script for. Preferably both.

It seems as though asking for things like this can prompt a slight barrage of "You're lucky we even bother to answer your post! Do it yourself, turd!" so I just want to say right ahead that I'm not demanding that someone get to making a site with a comprehensive list of simple tutorials on GP2X scripting. I was just mentioning the possibility. I might do it myself if I learn some scripting, as I don't mind making things more accessible for the people who don't have the time or energy to invest in just making things work.

When/ if I get a grasp of scripting, I'll talk with a friend of mine about making a php page where you type in factors like overclock speed and the locations of the programs you want to reach and stuff in order to make it output a finished script. Not sure he's that good at PHP, but it might work. Unless someone else wants to try their hand at it, of course.
 
This is driving me absolutely crazy! Can someone help me with this please?

I'm trying to use the example scripts from TelcoLou's post above. I downloaded Programmer's Notepad 2, went to Tools>Options>Defaults and set the default line endings to "Unix (LF)". To be doubly sure I also ticked Tools>Line Endings>Unix (LF).

Then created new file, copied and pasted this script into it:


TelcoLou posted on May 10 2006 at 06:48 PM said:
Here's one to launch a .gpe located in the root:

Code:
#!/bin/sh
/mnt/sd/APPorGAME.gpe
sync

cd /usr/gp2x/
exec /usr/gp2x/gp2xmenu

...modified so the line "/mnt/sd/APPorGAME.gpe" now reads "/mnt/sd/calculator.gpe", pointing to calculator.gpe which is sitting on the root of my SD card. I save this script as "calc.gpe" to the root of my SD, pop the card into the GP2X, turn on and run. This works perfectly - launches calculator for me.

Then, I re-opened calc.gpe in Programmers Notepad 2 and changed it to read:
Code:
#!/bin/sh
/mnt/sd/Data/calculator.gpe
sync

cd /usr/gp2x/
exec /usr/gp2x/gp2xmenu
So it now points to SD/Data/calculator.gpe (Not sure if it's relevant, but I created the folder "Data" and moved calculator.gpe into it using Windows XP).
As before, I check that the line endings are still set to Unix (LF) and save the file as calc.gpe to the SD root. Now, when I run the script the screen goes black for <1 second before exiting to the main menu.

In the same way, I also tried:
Code:
#!/bin/sh

/mnt/sd/Data/
./calculator.gpe
sync

cd /usr/gp2x/
exec /usr/gp2x/gp2xmenu
with exactly the same result. Calculator runs normally when I navigate to it using the GP2X's Game menu, so it's definately a problem with the scripts rather than the program itself.

Any ideas? I don't understand why I can launch a program from sd/ but not from sd/data/

Thanks,
Melville
 
Last edited by a moderator:
When calculator.gpe is in /mnt/sd and run from the menu the working path will be set to /mnt/sd (the location of the .gpe) and then it will be executed. By running a script that is also in /mnt/sd the correct path is being set.

When calculator is in /mnt/sd/Data and the script is in /mnt/sd, it's the script path that is being set by the menu, not the application. If your script is just /mnt/sd/Data/calculator.gpe then is may or may not work (depends if calculator.gpe is trying to find other files, because is will be looking for them in /mnt/sd instead of /mnt/sd/Data). Use 'cd /mnt/sd/Data' first to set the correct path (cd is Change Directory) followed by './calculator.gpe' (the ./ means that calculator.gpe is to be found in the current directory (as set by cd)). Don't use /mnt/sd/Data on it's own because that doesn't do anything.

Also, be careful with mixed case. Data and data are both the same folder to Windows, but two different folders on a linux system.
 
For some reason my card reader has stopped working so I can't try it right now. But thanks very much for your explaination! It makes perfect sense, so I shouldn't have any problems when I get my card reader sorted.

Thanks woogal!
 
Magnulus posted on Jul 10 2006 at 08:49 AM said:
Maybe I'm just lazy, but I'd rather not go through a general Linux scripting tutorial just in order to overclock a few programs and such. I'd rather have; A: A good and specific tutorial that tells you how to make the basic scripts you sometimes need in the Gippex, or B: A list of template scripts that do specific things, with instructions on what to change in order to make it work with what you're making the script for. Preferably both.

See what TelcoLou has posted already - this will cover most of what you will need.

What I find helpful when making scripts is seeing what's going on so you can spot your mistakes and bugs. When you run a scrip from the menu you don't get any feedback - apart from the when the thing finally works!

For this you can use STerm to manually run your script:

Code:
# cd /mnt/sd/whatever/wherever/
# ./my_little_script_o_doom.gpe
and if there are any errors or output you'll see them whizz past. You could also try this:
Code:
# sh -x /mnt/sd/whatever/wherever/my_little_script_o_doom.gpe
which will show each command as it's executed along with and error output.

If you don't have (or want to use :p ) STerm then an alternative would be to put in debug messages in your script to a file which you can then examine to see where you go wrong. An example is below:

Code:
#!/bin/bash
#
# Example script with debuging output
# <--- This marks a comment by the way: use them!!!
#

# The '>' and '>>' are called re-directs and send the output of a
# command to the file. '>' will always create a new file - even if
# an old one's there already. Use '>>' to append to a file. If you
# want the error output sent to a file use '2>' or '2>>' instead.
#
# With this in mind the 'echo "some text" >> filename' lines
# will add the line 'some text' to your debug file.
#
# To save typing the filename out each time I save it to a variable
# called 'my_file':
my_file=/mnt/sd/script_debug.txt

# To start off we'll log the time and date to our file. A bit lame in the
# GP2X as the clock only starts when the system boots so it won't
# be correct but you can atleast know how soon after turnin on you
# tried your script:
date > $my_file

# OK - first of all we need to change to the location of our app:
cd /mnt/sd/somewhere/
echo "The cd command has been done!" >> $my_file

# Good, now we set the over-clock bits. We also log any error
# output to our file by using '2>>'.
echo "About to overclock..." >> $my_file
/mnt/sd/cpu_speed.gpe 1 2 266 0.6 2>> $my_file
echo "Whoa dude! Feel the speed - overclock done" >> $my_file

# And now we can run out app - this time we log all the output
# to our file by using '&>>' which combines normal output and the
# error output:
echo "Here we go - running MySuperApp.gpe" >> $my_file
./MySuperApp.gpe &>> $my_file
echo "Hope that worked 'cause we're back in our script" >> $my_file

# Now to tidy up in the prescribed manner:
sync
cd /usr/gp2x/

echo "Handing back to the gp2xmenu" >> $my_file
exec /usr/gp2x/gp2xmenu
echo "Bye!" >> $my_file
date >> $my_file
exit 0

All you need to do then is run your script and once you're back at the menu use the text reader to look at your log to see where it's going wrong.

Just cobbled this together before going home so there may be some typos but have a look and see if it makes sense before you cut-and-paste it blindly! :eek:

For more flexablility (and :ph34r: points) you can also try changing the part where we assign the log filename to this:
Code:
:
:
# To save typing the filename out each time I save it to a variable
# called 'my_file':
my_file=/mnt/sd/$(date +%H%M%S)_script_debug.txt

# OK - first of all we need to change to the location of our app:
cd /mnt/sd/somewhere/
:
:
which will give your log file a unique filename for each session - based on the system time. This works by 'pasting' the result of the 'date +%H%M%S' command into the filename string so your filename will be '/mnt/sd/<<hours>><<minutes>><<seconds>>_script_debug.txt'

Have fun!
 
Last edited by a moderator:
Back
Top