to change an icon right click and "set icon." to set the icon, drag the desired image from the icons folder (most are in /usr/local/lib/X11/pixmaps or /usr/local/lib/X11/mini-icons) right onto the box in the middle if the set icon window- typing is optional!
to create an icon, drag the script or binary for it (this may be the only needed step...) from /usr/local/bin (or any other folder) right onto the desktop.
to edit an icon image, goto the icons folder from mtpaint and open it, or goto the icons folder in rox and right click... "open with" and open it it mtpaint. (the second method may not always work.)
you can zoom in on your image by pressing "7" on your keyboard, or other numbers, nothing that "4" will go back to regular size.
most icons are xpm or png, you can use the "transparent" color by selecting from the background with [CTRL]+Paint tool, or you can set a new background color by selecting "save as..." from the mtpaint menu, checking "set transparancy index" and selecting the number next to the new color in the palette. you may need to "convert to indexed" from the "image" menu, but you probably won't.
after saving the image to the same file you loaded it from, the icon on the desktop will refresh after you hover the mouse cursor over it, if not sooner.
ktwi: puppy 2.11, *should* work also in 1.07 and most (or all) other versions...
thanks to: amish
Before You Post, Please Note...
-> Please Note: By Posting, you agree to submit the contents of your post to the Public Domain <- SEE: howto post to this blog
Saturday, February 3, 2007
Friday, February 2, 2007
puppybasic intro ch. 17 - other useful statements
green text is being edited and should not be considered
relevant to the tutorial. for a while, it will make up
the bulk of this section.
black text has been edited to be more accurate with
regards to puppybasic.
........................................................................
other useful statements
1 of 7
an intro to puppybasic
chapter 17: other useful statements
........................................................................
........................................................................
other useful statements
2 of 7
SHELL calls a dos command. dos of course, is not only capable of
managing operations with files and folders, it can call other pieces
of software. running large programs from shell may result in an "out
of memory" error from dos. (usually not an issue.)
here's a nice example for SHELL:
SHELL "dir *.* /a /b > dirfile.txt"
this creates a file called "dirfile.txt" containing a list of all
files in the current folder. then you can load the list with the OPEN
command.
........................................................................
........................................................................
other useful statements
3 of 7
mode co40 is another useful dos command, but doesn't always (if ever)
work in windows xp. (for some reason, every time windows makes a new
dos emulator it does even less of the stuff that dos or the previous
dos emulator did.)
it is better still to use mode con cols=40, which works in xp and can
be used in puppybasic like this:
SHELL "mode con cols=40"
........................................................................
........................................................................
other useful statements
4 of 7
this is better than width 40, as it's more likely to work. i knew of
one project that wouldn't stay in WIDTH 40 unless you first shelled to
run this dos command, then used WIDTH 40 as well.
........................................................................
........................................................................
other useful statements
5 of 7
COMMAND$
quickbasic (compiler) only. reads the arguments typed next to
a standalone exe's name, from dos or windows, so if your compiled
program was called appli01.exe and you were to type:
c:\winnt\>appli01 New.txt /fs
at the dos prompt (for instance) and you put this at the beginning of
your program:
q$=COMMAND$ 'then the string q$ would contain: "New.txt /fs"
........................................................................
........................................................................
other useful statements
6 of 7
SYSTEM
use this instead of END, this is only useful when using the
interpreter. it ends the program, but if the
interpreter is running, exits the interpreter also.
this only works if you've run a program using /run
[file].bas or /run file... etc. (from a script for instance.)
an example:
........................................................................
........................................................................
other useful statements
7 of 7
SYSTEM
END 'you don't need END here, but it hurts nothing and is easy to spot
'when other people are reading your code.
-= end of chapter 17 =-
........................................................................
an intro to puppybasic (chapter 17)
this content is public domain.
........................................................................
click here to go back to the contents page
puppybasic intro ch. 16 - arrays
green text is being edited and should not be considered
relevant to the tutorial. for a while, it will make up
the bulk of this section.
black text has been edited to be more accurate with
regards to puppybasic.
........................................................................
arrays
1 of 7
an intro to puppybasic
chapter 16: arrays
........................................................................
........................................................................
arrays
2 of 7
arrays make variables more useful and offer a powerful way to handle
data. for instance: instead of the following code:
READ a
READ b
READ c
READ d
READ e: PRINT a;b;c;d;e;
DATA 52,21,19,45,73
........................................................................
........................................................................
arrays
3 of 7
you could replace it with this:
FOR q=1 TO 5
READ ab(q)
NEXT q
FOR q=1 TO 5
? ab(q);
NEXT q
...which seems unspectacular until you have a bit more than five
variables to name.
........................................................................
........................................................................
arrays
4 of 7
another advantage of arrays is that you don't need to know exactly how
many items you will be storing. for instance:
DIM q$(1 to 100)
OPEN "file" FOR INPUT AS #1
DO: c=c+1
LINE INPUT #1, q$(c)
LOOP UNTIL EOF(1) or c => 99
q$(c+1) = CHR$(26): c=0: close
........................................................................
........................................................................
arrays
5 of 7
will open "file" and store each line in q$(c), c standing for which line
is stored there. this example limits the possible number of lines to 99,
and sets the last line to ascii 26 to mark it as the last.
note the use of DIM(1 to 100) which is required for arrays more than 10
units in size. it is also necessary to use dim for multidimensional
arrays:
........................................................................
........................................................................
arrays
6 of 7
DIM twod(1 to 5, 1 to 5) AS INTEGER 'integers let you use wider arrays
will allocate an array of 5 units, and each unit will also have 5
subunits:
twod(1,1) twod(2,1) twod(3,1) twod(4,1) twod(5,1)
twod(1,2) twod(2,2) twod(3,2) twod(4,2) twod(5,2)
twod(1,3) twod(2,3) twod(3,3) twod(4,3) twod(5,3)
twod(1,4) twod(2,4) twod(3,4) twod(4,4) twod(5,4)
twod(1,5) twod(2,5) twod(3,5) twod(4,5) twod(5,5)
........................................................................
........................................................................
arrays
7 of 7
you may find that although 3-dimensional arrays are possible, but that
the limitations won't allow a 3d array large enough to be useful all
that often. (i do know someone who used one for a card game, and you may
be able to use one for a program to solve rubik's cube... although such
a program already exists.)
incidently, puppybasic tends to demand that most DIM statements come at
the beginning of a program, but you can change the limits of some arrays
using REDIM.
-= end of chapter 16 =-
........................................................................
an intro to puppybasic (chapter 16)
this content is public domain.
........................................................................
click here to go back to the contents page
puppybasic intro ch. 15 - timing
green text is being edited and should not be considered
relevant to the tutorial. for a while, it will make up
the bulk of this section.
black text has been edited to be more accurate with
regards to puppybasic.
........................................................................
timing
1 of 7
an intro to puppybasic
chapter 15: timing
........................................................................
........................................................................
timing
2 of 7
vital to graphics and games, and useful for many other things you'll
want to do, the following are common functions for accessing the
timer inside the computer and its clock functions:
TIMER
(mentioned earlier for use with RANDOMIZE) is a numeric function that
returns the number of seconds that have elapsed since midnight.
you can code a delay using TIMER this way...
... (only joking, it's on the next page.)
........................................................................
........................................................................
timing
3 of 7
delay = .5 'delay in seconds, in this case: half of one second
t = TIMER + delay: DO: LOOP UNTIL TIMER > t or TIMER < t - delay * 1.2
it is also possible to create a short delay using FOR q=1 TO d: NEXT q
where d is a large number, but the faster computers get, the more
useless this method becomes. also it is unreliable in that the delay is
longer on slower machines, and that the delay it creates can't be
determined exactly on any machine but the one you try it on.
........................................................................
........................................................................
timing
4 of 7
SLEEP
makes a program suddenly sit and do absolutely nothing until a key is
pressed, and if used with a number:
SLEEP 5
works the same way, only gives up waiting for a key after that number of
seconds.
........................................................................
........................................................................
timing
5 of 7
if used enough times in a program, (especially in a loop,) the keyboard
buffer will fill, which adds up to annoying clicking noises. you can
clear this buffer using INKEY$, but i think it makes more sense to
substitute q$=INPUT$(1) for SLEEP, or a variation of the timer code
example (throw in an INKEY$ function) in this chapter for SLEEP N, and
i usually only use SLEEP when i'm busy enough doing other things to
avoid typing parenthesis: (example: SLEEP is very useful during
debugging.)
........................................................................
........................................................................
timing
6 of 7
TIME$
has the double use of checking and setting the time.
to check the time, let q$=TIME$ which will set q$ to an 8-byte string
comprised of "hh:mm:ss" with hh being a pair of hour digits, mm being
minutes, and ss being seconds.
to set the time, create a string in the same 8-byte "hh:mm:ss" format
and let TIME$=q$
easy!
........................................................................
........................................................................
timing
7 of 7
DATE$ works like TIME$ and checks and sets the date with the format
month-day-year as "mm-dd-yyyy"
note: if your computer is outside the united states, it's possible that
your OS and thus puppybasic will use a different date display.
-= end of chapter 15 =-
........................................................................
an intro to puppybasic (chapter 15)
this content is public domain.
........................................................................
click here to go back to the contents page
puppybasic intro ch. 14 - errors
green text is being edited and should not be considered
relevant to the tutorial. for a while, it will make up
the bulk of this section.
black text has been edited to be more accurate with
regards to puppybasic.
........................................................................
errors
1 of 10
an intro to puppybasic
chapter 14: errors
........................................................................
........................................................................
errors
2 of 10
you could do well to always trap and handle errors, i almost never
bother. if you write your program well, you might manage to avoid it.
this applies less to large programs. of course, sometimes error trapping
is quite useful.
whether you use error handling or not, your program, upon encountering
an error, can tell the user the name of the error. if you do not trap
your errors, the program will end as well. if you do use error handling,
you have the option of telling the user a more friendly interpretation
of the problem:
"I'm sorry, no file by that name exists in this folder."
........................................................................
........................................................................
errors
3 of 10
or even fixing it so the program can continue:
"That file does not exist. Create? (Y/N)"
you can even trap errors to detect which screen modes don't work. as
mentioned in the graphics section, there are several screen modes in
puppybasic, and they start with SCREEN 0, or text-only mode and range
from 0 to 13. so, you can tell your program to go to all the possible
screen modes: (none of this is true, this tutorial is being edited.)
........................................................................
........................................................................
errors
4 of 10
okscreen$ = SPACE$(14)
ON ERROR GOTO oops
FOR q = 0 TO 13
SCREEN q
NEXT q: nomorec = 1
and then when it tries to SCREEN [not an available mode] it will cause
an error 5, and GOTO the "oops" routine:
........................................................................
........................................................................
errors
5 of 10
oops:
IF nomorec = 0 THEN
IF ERR = 5 THEN MID$(okscreen$, q + 1) = "x"
END IF
RESUME NEXT
which adds an "x" under the part of the variable okscreen$ for that
mode.
........................................................................
........................................................................
errors
6 of 10
the command RESUME NEXT tells the program "don't worry about that last
error..." and the program then runs the next line, which is the "NEXT q"
of the FOR... NEXT loop.
when you're done trying all the modes, you can go back to SCREEN 0,
which is the default, and should always work:
SCREEN 0: WIDTH 80 'WIDTH 80 should always work, otherwise, remove it.
then print a guide for the numbers 0 to 13:
........................................................................
........................................................................
errors
7 of 10
PRINT " 1111"
PRINT "01234567890123"
and under that:
PRINT: PRINT okscreen$
END 'don't forget to put an END statement between
'your program and routines.
now your program will put a little "x" under the modes that don't work
on your computer!
........................................................................
........................................................................
errors
8 of 10
if we went over this section too fast: here is a review:
ON ERROR... GOTO linelabel
tells the program what routine to goto when an error occurs. there is no
"ON ERROR... GOSUB."
IF ERR=n THEN
will do something in response to the specific error... (you can also use
"SELECT CASE ERR" for handling this part.)
........................................................................
........................................................................
errors
9 of 10
RESUME NEXT
goes back to the part of the program where the error occured, but it
goes to the first line AFTER the problem.
note: error code 5 is "illegal function call" - the error you get when
you try to change to an unavailable mode, although there are other
possible causes.
........................................................................
........................................................................
errors
10 of 10
there are at least a couple other commands for error handling, but
unless you want them enough to look them up, you probably won't ever
need them.
-= end of chapter 14 =-
........................................................................
an intro to puppybasic (chapter 14)
this content is public domain.
........................................................................
click here to go back to the contents page
puppybasic intro ch. 13 - working with text files
green text is being edited and should not be considered
relevant to the tutorial. for a while, it will make up
the bulk of this section.
black text has been edited to be more accurate with
regards to puppybasic.
........................................................................
working with text files
1 of 8
an intro to puppybasic
chapter 13: working with text files
........................................................................
........................................................................
working with text files
2 of 8
working with text files is a bit different than working with binary
files... for one, the way you open the file depends on whether you will
be reading or writing. for this reason and a few others i prefer to
handle text files as if they were binaries and open them for binary
file access. you may find this is easier when you're starting out, you
may not. often i am too lazy and instead open text files as text files.
to print the following lines to a file:
this is a line. skip the next one:
okay, this is another line...
this is, too.
........................................................................
........................................................................
working with text files
3 of 8
always OPEN the file:
OPEN "filename.txt" FOR OUTPUT AS #1
if you do it this way it will start from scratch... that is,
"filename.txt" will be BLANKED if it wasn't before. for this reason you
will use APPEND for now. APPEND, instead of erasing the file, adds to
the end of it. if you are writing to a log, this is exactly what you
want. if you are only storing the data for a saved game file, this may
be problematic. in that case you may prefer OPEN... FOR OUTPUT.
regardless:
........................................................................
........................................................................
working with text files
4 of 8
OPEN "filename.txt" FOR APPEND AS #1
now we'll use the PRINT statement to write our lines to the file. the
file currently open is #1, so we'll use PRINT #1, q$
PRINT #1, "this is a line. skip the next one:"
PRINT #1, ""
PRINT #1, "okay, this is another line..."
q$ = "this is, too."
PRINT #1, q$
........................................................................
........................................................................
working with text files
5 of 8
the last line was printed differently to demonstrate again that a string
is, after all, a string, and that you can PRINT #1, q$ as well as PRINT
an expression in quotes. both of these are examples of valid strings.
always CLOSE the file when you're done working with it:
CLOSE #1
if you are only working with one file, or if you don't have any other
files that you need to leave open, using CLOSE with no file numbers:
CLOSE
will close all the files your program has opened.
........................................................................
........................................................................
working with text files
6 of 8
now to read the file, we open it again, this time for input:
OPEN "filename.txt" FOR INPUT AS #1
the text file is read one line at a time. one of the most reliable ways
to do this is to use line input from within a loop:
........................................................................
........................................................................
working with text files
7 of 8
DO: LINE INPUT #1, q$
PRINT q$ 'print the line to the screen
the program has to know when to stop looping. EOF(1) is a condition that
will be true when the end of the file is reached. it can end the LOOP
this way:
LOOP UNTIL EOF(1)
you may find This LOOP superior for reading text files:
DO WHILE EOF(1) = 0: LINE INPUT #1, q$: LOOP 'it handles 0-length files.
........................................................................
........................................................................
working with text files
8 of 8
if you only wanted to read the first line of course, the loop isn't
needed, only line input #1, q$
close the file when you're done with it. no files are open that need to
stay open, so it's alright to just say:
CLOSE
-= end of chapter 13 =-
........................................................................
an intro to puppybasic (chapter 13)
this content is public domain.
........................................................................
click here to go back to the contents page
puppybasic intro ch. 12 - looping within the program
green text is being edited and should not be considered
relevant to the tutorial. for a while, it will make up
the bulk of this section.
black text has been edited to be more accurate with
regards to puppybasic.
........................................................................
looping within the program
1 of 9
an intro to puppybasic
chapter 12: looping within the program
........................................................................
........................................................................
looping within the program
2 of 9
as promised, here are two ways to remove GOTO from the earlier example:
x=0
alabel:
x=x+1
IF x > 5 THEN ? x ' > means "more than"
IF < 10 THEN GOTO alabel ' < means "less than"
one way is DO... LOOP. it sort of works like this:
alabel:
goto alabel unless condition is met...
........................................................................
........................................................................
looping within the program
3 of 9
but it's better:
DO: 'no line label needed!
LOOP UNTIL cndtn=1
and the example:
x=0
DO
x=x+1
IF x > 5 THEN ? x
LOOP UNTIL x >= 10 ' >= means "more than or equal to"
........................................................................
........................................................................
looping within the program
4 of 9
if you had a very long version of this:
x = 0
DO:
x = x + 1: IF INKEY$ = CHR$(27) THEN EXIT DO
'stop loop if ESC pressed ^^^^
IF x > 5 THEN PRINT x
LOOP UNTIL x >= 2 ^ 17 ' >= means "more than or equal to"
you could stop in the middle with INKEY$!
(2 ^ 17 of course, is 2 raised to the 17th power)
........................................................................
........................................................................
looping within the program
5 of 9
as mentioned before, INKEY$ will not wait for a keypress. if you've been
pressing a key (in this loop, INKEY$ is checked many times each second)
then INKEY$ will detect it (there are some exceptions, like the CTRL
key...) but the program just keeps running whether a key is pressed or
not. it is also possible to pickup the most recent keypress using
INKEY$, because there is a buffer that tracks recently pressed keys. it
can get full, especially if you hold a key down, and you can use INKEY$
to clear it and prevent the computer from beeping at you.
EXIT DO, as used here, stops the DO... LOOP and moves on to whatever
part of the program is after that. another way to do this is with OR:
........................................................................
........................................................................
looping within the program
6 of 9
x = 0
DO:
x = x + 1
IF x > 5 THEN PRINT x
LOOP UNTIL x >= 2 ^ 17 OR INKEY$ = CHR$(32)
'the spacebar sends an ascii 32.
FOR... NEXT
is the way to loop with a number range.
........................................................................
........................................................................
looping within the program
7 of 9
'this is the shorter loop from before, done with FOR... NEXT
FOR x=1 TO 10
IF x>5 THEN ? x
NEXT x
or even:
FOR x=5 TO 10
? x
NEXT x
........................................................................
........................................................................
looping within the program
8 of 9
to go in increments of less than 1, try STEP:
FOR x=5 TO 10 STEP .5
? x ' will print 5, 5.5, 6, 6.5, 7, 7.5, 8, 8.5, 9, 9.5, 10
NEXT x
it adds .5 instead of 1. and you can go backwards, and over 1 at a time:
FOR x=10 TO 1 STEP -2
? x ' will print 10, 8, 6, 4, 2... but not 1, because it will get to 2,
'and STEP -2 again, which is 0...or less than the range 10 to 1, get it?
NEXT x
........................................................................
........................................................................
looping within the program
9 of 9
to recreate the functionality of INPUT$(1) using INKEY$, use this line:
DO: q$=INKEY$: LOOP UNTIL q$ <> "" ' <> means "not equal to"
by the way, you might want to know the Other kind of DO... LOOP:
DO WHILE condition = true 'makes sense?
LOOP
-= end of chapter 12 =-
........................................................................
an intro to puppybasic (chapter 12)
this content is public domain.
........................................................................
click here to go back to the contents page
Subscribe to:
Posts (Atom)