================================================================== So... you think you're a good programmer??? ================================================================== All ideas by ross8653 ross8653@hotmail.com icq# 21361440 --------------------- First off this is just some tips that I have used in my programs that I thought other people might want to use. Some of these things are basically my preference on how to program but I'll give you my reasons for using certain methods and you can decide if you agree. Topics range from Truth tables to the basic loop, some of you will say "duh I know this crap," well good then just skip that section. ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤Table of Contents¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ 1: Looping 2: Isz 3: pxl plot 4: displaying in the graph screen 5: Locate 6: The Matrix 7: WAIT!! I can't read that fast 8: Speeding up the if command 9: Truth tables 10: Saving some space, and speed tests ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ ****************************************************************** 1: LOOPING Explaining the different types and advantages of each ****************************************************************** There are 3 "real" types of loops plus the lbl and goto command do-lpwhile while-whileend for-to-step-next THE DO-LPWHILE LOOP To create a loop start it with the "Do" command then push enter. Then enter the things you want it to do during the loop. 1 -> X Do 2X -> X lpwhile X<500 This program will continue to times X by 2 then storing it back in X (basically just multiplying it by 2). Since it starts it by making X=1 the first time it gets to the lpwhile X is still less than 500, so it goes back to the Do line. The main problem with this and the while-whileend loops is you have to already have a variable created in most cases to decide when the loop will stop. One of the best ways to use the Do and lpwhile loop are when imputing keys but not numbers. I have seen many variations of how to use the getkey function, but I have decided that the following one is the best way (I think anyway). Do getkey -> G lpwhile G=0 or more advanced lpwhile "Not G" (discussed later) If no key is pressed the getkey is 0 therefore so is G. So it will keep looping till a button is pressed. Below is another popular version to tell what button is pressed. Do lpwhile Getkey=0 REASON: the reason why i use the other one is if you have many "if" statements the user has to hold down the button to have the action preformed (you might have noticed this in many games). My way the getkey is in G so it can't be changed unless you input a different value in G. THE WHILE-WHILEEND LOOP It works almost exactly the same as Do-lpwhile (same speed also) the main difference is that the condition that will break the loop comes at the beginning of the statement so that the loop doesn't have to be executed, the do loop will always be executed at least once 1 -> X While X<500 2X -> X Whileend THE FOR-TO-STEP-NEXT LOOP This is a little more complicated loop (one that I avoided in my early programming days) but once you learn it you will love it. I found that using the Do loop I was normally setting a variable right before I executed (like 1 -> X above) and also adding 1 to the value so I could control the length of the loop, but the for loop makes this easy. One thing that I liked about the Do loop is I could tell directly what was going on at a certain time and where the error occurred. The for loop is a little more complex but only at first, here is how it is set up. I'll convert an example 1 -> X Do X+1 -> X locate 1,1,X lpwhile X<500 For 1 -> X to 500 locate 1,1,X next See the big difference in the size, plus it runs much faster. You can probably see that after the For statement you set a variable, the you decide where you want it to stop at (500). Then program what you want it to do, then type next so it knows where the loop ends. Now what happened to the X+1->X right? The for loop auto adds 1 to the variable set after the For statement (such as X). You can control how many it adds each time through the loop using the step function. If you want 3 to be added to X every loop, change the first line to this. For 1 -> X to 500 step 3 You can also make it subtract by using negative numbers, or have it jump by X every time for the "step" value For 1 -> X to 500 Step 2 locate 1,1,X next this makes it jump two each time, so the first time though the loop X = 1, the second time it's 3 and 5 ... etc SPEED: The for loop runs much faster than the do loop. You should only use the do loop when finding the getkey unless you have huge break conditions SIZE: The for loop is almost always smaller VERCITILITY: You can do much more with the do-lpwhile loop, so if you have large break conditions You should use it ****************************************************************** 2: Isz and Dsz How to use them and what they can do for you ****************************************************************** If you ever add a variable by one then store it in the same variable, (A+1 -> A) the Isz command can really help you. But these can be used as "if" commands at the same time! Yeah confusing so lets start simple, here is what it does basically. 1 -> A Isz A After this gets done A will equal 2, wow neat. And the Dsz just subtracts. Now who cares right? Well it is actually much faster than A+1 -> A and its smaller but here is why you have to be careful, If the result equals zero then it won't execute the line after it. ClrText -1 -> A Isz A Locate 1,1,"one" Locate 1,2,"two" When executed notice how one isn't on your screen, because the result of Isz = 0 (A=0) so it skips that line and goes directly to "two." Now replace -1 -> A with 0 -> A. Now run the program see how both one and two are displayed? I haven't found a good reason to use that I just use it because it so much faster than adding 1 to the variable and I make sure the result wont be 0. The dsz works the same way incase you were wondering. SPEED:Isz and Dsz are much faster than adding or subtracting one from a variable SIZE:Isz and Dsz are smaller than adding or subtracting one VERCITILITY:You could do much more than just adding or subtracting one manually like multiplying and squaring but the Isz and Dsz let you use a "if" command at the same time ****************************************************************** 3: PXL AND PLOT how to use the different coordinates and which is better ****************************************************************** Pxl and plot commands are used to display one pixel at a time on the screen. The plot command is much slower because it converts coordinates depending on the view window. The pxl command displays that pxl no matter what the view window is. The plot command displays a pxl according to the view window so if you put in plot 0,0 then it will display a dot in the middle of the screen (if the view window is normal). Plot uses standard graphing coordinates, first coord is horizontal and starts at left, second is vertical starting at bottom. But the pxl command will always display the same pixel no matter what the view window is (pixel's don't change). The first number is the vertical component starting at the top. The second is the horizontal component starting at the left. So why use the plot command? Well you shouldn't really. You can almost always do a little subtraction problem before it and it will still be faster. Because all you need to convert is the vertical component. But if you're using random numbers or for some reason displaying coordinates in decimals and you cant convert them you have to use the plot command (because there's not 1.4729 pxl). That is pretty much the only case you would want to use the plot command. SPEED:Pxl is much faster and there is no really good reason to use the plot command unless your just lazy SIZE:Same VERCITILITY:The end result is exactly the same ****************************************************************** 4: Displaying in the graph screen Tips and tricks on how to display crap faster ****************************************************************** There are three main functions to display on the graph screen; text, f-line, pxlon/off/chg. Other functions can also be used to display in the graph screen like plot but it is really slow and pxl almost does the exact same thing. Most of these commands if not all are found under optn f6 f6 sketch TEXT This command is used to display text (bet you knew that). Ok anyway the text displayed is much smaller than using locate or using quotes where you only get 8 lines. If your good you can get 9 lines of text, plus many more than 21 characters across. In older calcs each character used the same amount of space in their width, but on the fx2.0 certain characters use 2-3 pxls more which can add up fast (ex W, M, and N). If you don't understand run this program. cls text 1,1,"WWWWW" text 8,1,"IIIII" Now to explain how to use the coordinates, the x coord or the horizontal pos is second, the y coord is first, but starts from the top. And it doesn't matter what the view window is at, the coordinates depend on the pxls not the view window. So the top left corner is 1,1 and VERY bottom right is 63,127 but that is the last pxl and you won't see the text. The position is where the top left of the character starts not the bottom. That's why if you have 1,1 you can see it but 62,1 you can't. The speed is pretty good and using blank text is a good way to erase part of the graph screen without using pictures. Plus it's the only way to display text other than drawing tons of lines and making each letter individually. But don't use extra spaces when your displaying because the less characters per line the faster it goes. ex "abcd " will display slower than "abcd". One thing to note if you used a 9850 or a color calc you could display different color text over each other and the first one wouldn't be deleted, but since this is just monochrome. If you display text it deletes everything that was there. One more nice thing about the text command is that you can display variables, or matrix values, well tons of crap. To do this just don't use quotes and enter what you want after the second comma, Text 1,1,Mat A[1,1] or Text 1,1,R. Notice that it will not display R but it will display the number that is set to R. F-LINE F-line is used to draw 1 pxl in width lines. The coordinate system of the F-line function makes more sense, F-line X,Y,X,Y one X,Y is the start, and the other is the ending spot. X starts at the left, and Y starts at the bottom so low numbers of x,y are bottom left (like you would normally graph something). But unlike Text and pxl commands the f-line depends on what the view window is set at, and uses those coordinates. If you don't understand that it doesn't matter much since you should almost always have your view window set at 1,127,1,63. Make sure you read the compressing section if you use this command a lot in your programs. PXL The Pxl commands are pretty much the fastest way to display something on the fx2.0 but you can only work with one Pxl at a time. The Pxl commands don't care what the view window is at and have the same coordinate system as the Text command but I'll go over it again. The basic set up is Pxl Y,X where Y starts at the top and X starts from the left. There are 4 different commands; On, Off, Change, Test. On, Off, and Change do exactly what they say turn the pxl on off or they change it from what it was. PxlChange is slower than on or off because it has to test what it is first, so try to avoid using that. Test is pretty slow and in my mind there is no real use for it. If you want to know where something was that is on your screen why not just use a variable of what you displayed so you know where it is. But if you want to know how it works it goes like this. PxlTest(Y,X where Y and X are the same coordinate system as above. Then it returns an answer, either 1 or 0, 1 is that pxl is on, 0 is that is off. More on 1 and 0 crap in the truth tables section. SPEED:With F-line the speed depends on how long the line is, but in most cases the text command is a little faster than the F-line. And the pxl is fastest of all but can only do one pxl at a time. SIZE:F-line is a little bigger than other commands because there needs to be a starting and stopping point. Text and Pxl are the same. (without the text counting) VERCILITY:F-line is the basic way to display things in the graph screen and should be used to draw lines. Text you can erase things by displaying spaces, and also display variables. ****************************************************************** 5: Locate How to make stuff scroll, and what is wrong with it ****************************************************************** Locate is the basic way to display text is the text screen (like the run mode or using quotes). Of course Casio has to screw with you some more and change the coordinates again. Here is how it is set up, Locate X,Y,"AAA" The X coordinate is normal, starts at the left, but the Y starts at the top and goes down. There are 7 lines (Y can only be 1-7) and there are 21 characters per line (X can only be 1-21). You have to be careful though because if you display text that is a command then it will put a messed up symbol after it. This is a bug in the ROM and the only way to get around it is using quotes. So why would you display a command? well you don't do it intentionally but here are some commands and if you use capitalize the first letter and leave the others lower case it becomes a command; do and next for or not if send stop return. For more information visit www.casio-programs-avenue.com and go to the documents section to read my document on the locate command. You can only make stuff scroll up since when you display text it pushes everything else up. To make crap scroll (like a-racer games) first clrtext then display a double quotes 7 times (since there are 7 lines). Now display what you want using the locate command (don't display it on line 1 because it will be cleared when you scroll) then run another double quote. Here's an example ClrText "":"":"":"":"":"":"" locate 1,6,"HI" "":"":"":"" Notice how it scrolls up 4 times because there are 4 "" after you display it. This is useful so that you don't have to keep redisplaying HI if you want it to scroll. And like the text command you can display variables and matrixes and lists just don't put in the quotes. Locate 1,1,A Locate 1,1,Mat A[1,1] SPEED:Well it is actually slower than the 9850 calcs and text runs faster than locate so try to use quotes if you can because you can display a whole line of A's faster than displaying one A using locate. SIZE:Quotes would be smaller if you don't have to have tons of spaces, but remember it bumps all the other lines up if they are there, locate doesn't but takes a little more space VERCILITY:You can use the locate but to your advantage, but with quotes you get the scrolling feature. ****************************************************************** 6: The Matrix Beyond the movie ****************************************************************** Matrixes are used mostly for saving info that you want the program to read next time it starts, because if you save high scores in the letter variables, other programs erase them. Other large programs use the matrix because there aren't enough letter variables, like board games. Some people also use lists, matrixes are a little slower when accessing the data, but faster when input values into it. The layout is a little better in matrixes. It is pretty much the programmers choice if I would have learned to use lists when I started programming I probably would have used lists but I was too stupid back then. Here is how you assign variables to matrixes... 1->mat A[2,3] (note that the ] isn't necessary in most cases) A is the matrix letter (A-Z) and 2 is the row number (how far down) and 3 is the column (how far right). There is also another matrix called ans, it is the answer matrix. It works like the ans variable. If you run the command mat A in the RUN mode, mat A is the same as mat ans because it moves everything into it. To recall a matrix just put in the matrix and the cell kinda like you did above. mat A[2,3] will return the value that is inside the matrix a and at cell 2 down 3 across. Remember that you have to create the matrix first you can do this by using the [[]] symbols. The first and last are the start and end of the matrix, the ones on the inside are the rows. [[0,0][0,0]]->mat A This line creates a 2x2 matrix in matrix A formatted like this 0 0 0 0 [[8,6,5,3][9,8,7,6][0,0,0,7]] -> mat A This line creates a matrix with 3 rows and 4 columns like below 8 6 5 3 9 8 7 6 0 0 0 7 Working with matrixes is very similar to regular values. Say you want to display the value in matrix A in row 5 and column 2 at the top left of the screen. Example below shows you how to do this locate 1,1,mat A [5,2 (notice ] isn't needed but if it confuses you add it in) The values in matrixes can be used almost anywhere in a program like numbers, but like letter variables the one exception that you have to remember is that in goto and lbl statements, you can't use variables. One of the most important functions is the swap function if you are making games like Tetris that have to clear lines. This command just switches two rows in the matrix. Here is how you set it up. Lets say were switching the rows in matrix G and we wanted to switch rows 3 and 4. swap G,3,4 Notice how we don't need to put the mat command in there since it is implied ****************************************************************** 7: WAIT!! I can't read that fast Why you need wait commands and the best way to do it ****************************************************************** If you display text and you want the user to read it you have to have a wait command because they can't read at the speed it displays it. And when I looked at many games all I saw were people using for commands like below. Many people don't use math functions in thier games, but remember you are programming on a CALCULATOR, so if you can use your brain a bit and create a function instead of lots of if statements you can speed up your game. For 1 -> X to 500 next That uses 11 bytes and two lines plus it looks kinda weird. I prefer to use the Sigma symbol which uses the same space but looks a lot better because it is one line and if you have large wait commands you can save even more space because it takes longer. So instead of having for 1 -> X to 2000 you can have a much smaller number just by changing the function. So here is how it works (I'll use E for the sigma sign, optn F4 4) E(function,variable,start,finish E(x,x,1,500 the function can be any normal function like 3X^3 + 4X + 9 remember that the more complex the function gets the longer it will take which means the smaller difference you have to have between the start and finish. Example E(X,X,1,10000 takes just as long as E(X^2^pi,X,1,700 because the second one has such a more complicated function SPEED:Sigma is slower than using the for loop which is good for once SIZE:About the same but Sigma uses one line and is easier to understand what it is doing in a long program you don't have to worry about leaving out a next statement, or too much nesting VERCILITY:You can do more with the for loop but if it is just a wait command I use sigma ****************************************************************** 8: Speeding up the if command Think you got it as fast as possible, don't be so sure ****************************************************************** There are ways to make it even faster than talked about here but they are in latter sections and I don't want to confuse people. One of the main things I see people doing is trying to find out what a variable equals. If X=1 Then A+1 -> A Ifend If X=2 Then B+2 -> B Ifend If X=3 Then C+3 -> C Ifend Now of course there would be better ways to rewrite this example (like using => ) but I'm using it to prove a point. If you would use the else command and put all the ifends at the bottom it improves the speed by 60% when X=1 because once it knows that X=1 it doesn't check if it is 2 or 3 which makes since. And even when X=3 It doesn't go any slower it just goes at the same speed, because it has to check for 1 and 2 first. Below is how you would change it with else commands. If X=1 Then A+1 -> A Else If X=2 Then B+2 -> B Else If X=3 Then C+2 -> C Ifend:Ifend:Ifend there's three because you have to close all the If statements Another thing that can speed up large If statements where you use getkeys is try to keep everything between the Then and Ifend statement as small as possible. A good way to do this is use lbls, instead of having large loops and If statements inside an If statement. If you have 3 different getkey statements that display junk, make 3 lbls so it can loop faster. Even if the If statement is false (like If 1=2) It will take longer the more crap you have inside the loop. ****************************************************************** 9: Truth tables A little more complex crap but can speed your program up ****************************************************************** Truth tables aren't too terribly complex, but they're not easy, and can really speed up your game if you have to check variables lots. Here is the basic idea 1 is On/yes/true 0 is No/off/false (I'll explain don't worry). It deals with non-zero numbers. You might have seen games use "If A:Then" this is using the truth tables crap. Try this program A => "abcd" now if A doesn't equal 0 then it will display "abcd" and will return the value 1 in the answer (because it is true). But if it does equal 0 then it would be false and wouldn't display "abcd" and would return 0 in the ans. So why do you care? Because it is much faster, below are samples of programs and how you can make them much faster. But remember it can only tell the difference between zero and non-zero numbers. If A=1 If A A=1 Or B=1 A Or B A=1 and B=1 => "bling bling" A and B => "bling bling" lpwhile Getkey=0 lpwhile Not Getkey Whoa where did the "not" come from right? Well hold on, you can pretty much replace the single variable where you are trying to tell what something equals (X=55) like if, and, or, while and almost any other statement that checks a variable. So the Not gets confusing well it is just doing what we did before only making 0 true and 1 false. If you would replace it with just Getkey then that is saying while getkey equals something non-zero. And your trying to make it say while it equals zero that's why you use the not. You should never have a =0 in your program. This example saves one byte (wow!) but the main advantage is it speeds up the program. ****************************************************************** 10: Saving some space, and speed tests All the small things that save space and make your program better ****************************************************************** In a program you should never have 3 zeros ending a number in a program unless you are displaying this number. Instead you can save space by using the EXP button (next to exe). The speed remains the same but a few bytes here and there add up. Just replace the zeros by E then the number of zeros you deleted. Examples below 1000 8510000 900000000000000 1E3 851E4 9E14 When you have a double If statement or if you have long AND statements, you can just use a double => sign. This makes your program faster because with a long and statement it tests every single statement even if the first is false ex If 1=2 and A=A and B=B and 8653=8653 then "Hi" ifend 1=2 and A=A and B=B and 8653=8653 => "Hi" Of course both of these are false because 1 doesn't equal 2 but the program still goes through a=a, b=b, 8653=8653, this wastes lots of time that doesn't need to be wasted. Instead do this 1=2 => A=A => B=B => 8653=8653 => "Hi" Doing this increases the speed by almost 3 times!! Plus it even saves a little space. But the problem is that you can only have one condition (making it say "Hi"). Also if you have two If statements inside another if statement you can change it like this (but it can only have one condition) If 1=1 then if 2=2 Then "first one" Ifend if 3=3 the "second one" ifend ifend Notice how much space is saved on the two lines below this paragraph. change this long thing above to this... 1=1 => 2=2 => "first one" 1=1 => 3=3 => "second one" If you want your game to have replay value you should have high scores, and saved games. Most people waste massive space for high scores or saved games because it is a little hard to compress it but not that much Ex. if you save 6high scores each letter is probably 2 numbers (the getkey number) so instead of using 1 matrix cell for each letter you can use 1 matrix cell for 8 values!! This is because you calc saves 16 numbers per variable. Even though you can't see them they are there. Try this .12345678901234567890 -> A now keep pushing exe after this statement frac(A/10 Notice how it keeps bumping one number up until it gets to the second 6 that is because it saves 16 numbers in the variable. So why waste one cell for 2 numbers when you can fit 16 in there. It is also makes it harder to change the high scores and saved games if you have an anti-tampering system If you notice you use one number many times in your program especially 2 or 3 digit numbers then create a variable that you don't already use in the program for that number. Ex. f-line 60,1,80,1 f-line 60,5,80,5 f-line 60,60,60,1 Change it to this 60->A f-line A,1,80,1 f-line A,5,80,5 f-line A,A,A,1 Your calc can read variables almost anywhere there is a number. And your calc reads variables faster than numbers! The only exception is if you want the calc to jump to lbl 5 you can't do this 5->A goto A Because this is telling your calc to goto lbl A not lbl 5 If you have lots of If statements try and make an equation that can help you instead. For example I made a program and it had to know what number the user was pushing, not the getkey but the number 1-9 so I came up with this equation by a little thought and speed up my game a great amount Abs (Int (A/10)-8)+3(10Frac (A/10)-2 -> X Where A is the getkey number. neat huh, it takes some brain power but it helps In my tetris game I needed to know where to stop the piece (if there was something under it). So I looked at this really old tetris game but it was helpful here's what I learned, at the end of lots of Or and AND statments you can create a variable if the equation is true. ex 6=6 or 1=2 or 1=2->A running this makes A equil 1 or true (read the truth tables), but if the statment is false then it equils zero. This is much faster and keeps it all in one line. -------SHORT NOTES------- *The divide key is always faster than the fraction key (A b/c) *If your testing a couple lines of code it is easier to do it in run and copy it later *Never use a end parentheses before -> ex. 10(1+A(B -> C *Don't us a multiply sign with a variable just do this 12.3AC means 12.3 x A x C *remember if you need a variable for a short amount of time use the ans key <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< any questions, comments or flames (not flamers)? contact info is above (push ctrl home) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>