CyBasics
Lesson 6
Lesson 2
Lesson 3
Lesson 1
Lesson 7
Lesson 5
Lesson 4
Screen Tricks First and foremost, you'll wanna know how to manipulate the screen. The command you'll use most often is PRINT. It's wonderful. Without it, you couldn't show things on the screen, and, as we all know, that is an intergral part of programming! Here's an example of the simple use of the print command: Print "Palm reallly suxl!" wait 60 Type the above code in CyBasic and press FN+R. Incredable huh? Of course, you don't have to have the wait command, but if you don't have it, the cybiko will print the text and finish the program so fast, you wont be able to see it. Another great command is the CLS command. Without this command, text would just pile up, one after another, until the screen is full. Sometimes, that's ok, but.. ehh.. sometimes it's not. So, Type the following code in CyBasic: Print "Palm really suxl!" wait 40 Print "Palm reallly suxl!" wait 40 Print "Palm reallly suxl!" wait 40 Run the code (with FN+R, you should know that by now!). See how text piles up on the screen? Try putting CLS after every WAIT 40. Then run the code. See how the text appears on the screen, and the disapears, only to reveal the next row? Neat huh? As a rule, keep whatever your trying to print less than 23 charecters. You can do more, but anything after 23 gets cut off the screen. Whihc reminds me, you can only print 7 rows before ya gotta call the CLS command. That pretty much covers the print command. Remeber, Print commands should always in case what your trying to print in two quotation marks. Forget a quotation mark, and cybasic will give an error. The wait command is pretty simple, so we wont go into that to much. The WAIT command just makes cybasic stop and think for the specified number of milliseconds. (It cant be over 60.) Btw, to print an empty line, just type PRINT With nothing following it. And, while we are on the subject of the screen, a few simple codes to manipulate it: (Just type these codes in CyBasic and any code after then will follow suit.) Ink # It determines the ink color. The points, lines and text are displayed by specified color. Replace # with 0,1,2, or 3 to change the color. Paper # It determines the background color. There are four colors: 0,1,2,3. A screen is filled by the background color if the operator Cls is executed. TEST 1 Make a simple code to animate simple flames at the bottom of the cybikos screen with the charecters / & \
Variable Picture a variable like a tuppaware container. It's nothing by it's self, but it can hold food. Plus, you can change the food that's in it. Such is the power of the variable. The variable is just a place to stick some info that you'll use later. However, variables don't just come out of nowheres. First, you have to DIM them. Dimming variables is just like naming what they'll hold. Before choosing a name for your variable, take note it's name can't be longer than 19 charcters ,have no spaces, and that every variable you DIM must have a different name. So, let's say your name was Billy Jo Bob Hick. What if, in your program, you wanted to display your name alot of times, but didn't want to type your full name alot? VARIABLES TO THE RESCUSE! IMPORTANT! There are different types of variables. For instance, the char variable only hold letters. The int variable will only hold numbers.First, you'd name your variable MYNAME dim myname [18] as char Above, we just dimmed a variable. But, what's with the 17? Well, like a tupperware container, you dont want to stuff a whole cow in it. As Billy Jo Bob Hick is 17 charecters (including spaces), we DIM myname (the variable) as being able to hold that many charecters. We can type more, but only the first 18 charecters will be recogzied. Now, we have to stuff something into myname. dim myname [18] as char input myname In the above code, we just asked for the user to type what the value of my name is. Now that's we've done that, type the following code into CyBasic and run it: dim myname [18] as char input myname Print "What's up ",myname,"?" wait 60 Fun huh? Now, through your entire program you could just CALL(view) myname anywhere you wanted, instead of typing your whole dorky name again! But, say, what if you wanted to stores numbers in a VARIABLE? It's just as easy as using a char variable, only you dont have to use brackets. Just dim that sucker and keep going! dim myage as int myage=15 IN the above code, we DIMMED the my age variable as only being able to hold numbers. Then, we DECLARED that that number is 15. Now, let's manipulate it. dim myage as int myage=15 Print "In 30 years, I'll be ",myage+30," years old." wait 60 What was that? Was that...*GASP*... Math?! Yes. THrough your cybasic adventure, you will be destined to encounter your horrible foe. But fear not, math in cybasic is pretty dang easy. Addition: Use the + Operator. Subtraction: Use the - Operator. Multiplication: Use the * Operator. Less than: Use the Operator. Greater than: Use the > Operator. Less than or Equal to: Use the <= Operator. Greater than or Equal to: Use the / Operator. Equal: Use the = Operator. Not equal: Use the <> Operator. Easssy. No big deal right? Few things to remeber before we end this lesson. You may type operators and variables in small or capital letters � it doesn�t matter. And finally, int variable can only be from -32768 to 32767. TEST 2 Make some code to take a INT variable, multiple it by 5, subtract 2, and then add 17. Then, make it print the variable.
If-Then-Input In all actuality, you've come pretty dang far. I mean, GEE WIZ, That was a lot of stuff to read. Just, pat yourself on the back, take a whiz, and get ready. Here comes the hard part. Input Statements Sooner or later, it would get boring if you had to program in every thing you wanted the Cybiko to do and have it be totally automated. You need user INPUT. Ingeniously, Cybiko Inc. thought to include this feature :) An input statement is where CyBasic stops, waits for the users to type something, then takes what the user typed and does something with it. What a great thing to have! dim name1 [10] Print "What is your name?" input name1[10] Print "Hiya ",name1 wait 60 In the above code, you find that we dim the input variable, but not as a specific type (DIM or CHAR). This is because we dont know if the user will type numbers or letter. In this case, just DIMming it works fine. Then, input is asked for, then spit right back. Pretty simple, and a very important part of programming. Now, lets get a little trickier.. If...Then Statements Some times you need to check and see if something is true or false. When you wanan do this, you wanan use an If..Then statement. It's not as hard as you might think. CyBasic is pretty much just typing english in a way a computer can understand. For example: dim name1 [10] Print "What is your name?" input name1 [10] If name1="Tommy" Then Print "Hey! Tommy is a really cool guy!" Wait 60 end if The above code is pretty understandable. We DIMMED an input variable, asked for input, got the input, then looked to see if the input was "Tommy". If it was, the program would have printed "Hey! Tommy is a really cool guy!". Then of course, we addend END IF at the end of the code. You must ALWAYS End an If...Then statment with an END IF, or CyBasic will give an error. Understand? Thought you would. It's not that hard, but it's getting tougher. But what if you wanted to check for one specific thing, and if it wasn't that specific thing, to go on? Enter the ELSE statement. Let's modify that code we did a little while ago a bit: dim name1 [10] Print "What is your name?" input name1 [10] If name1="Tommy" Then Print "Hey! Tommy is a really cool guy!" Wait 60 Else Print "Your Not Tommy. Go Away." end if Obviosuly, the above code check to see if the input is "Tommy" or not. If it is, your greeted cheerily. If not, your hurridly ushered away. Neat huh? That raps up this lesson. Get ready to bear down.. cause it's gonna get rougher.. TEST 3 Make a program that takes a users's numerical input, divides it by 2, and checks to see if it is greater than or less than 5. If it is, print a statement, and if it's not, print another statement.
For-Next statements Sometimes, it's not enough for your program to run through some code once and be done with it. Sometimes, you need code to be run LOTS of times. But you don't wanna type the same code over and over right? Right! So, you use For...Next statements. Here's an example: for jingle=1 to 1 step 0 Print "^*^*^*^*^*^" wait 10 cls Print "*^*^*^*^*^*" Wait 10 cls Next The above code makes a simple text based (YAY!) jingle bells animation. In the first line, FOR declares this is the first line you want to begin at in the loop. jingle is the name of the loop. Now, as for 1 to 1 step 0, there are certain parts to it. The first one indicates the starting number, the second one indicates the finishing number, and the 0 indicates how much is added to the starting number everytime the loop is done. This example above is an INFINITE loop, meaning it will go on and on until the program ends. However, should it have been 1 to 5 step 1, the loop would be processed 5 times, then end. Simple huh? Remeber, whenever you DECLARE a For...Next state ment, the name must be unique, and, every For...Next statement MUST have a Next at the end. The Next tells cyBasic to go back to the last FOR line it encountered, and start processing code there. That about covers it for the incredable For...Next statement.
Subs This is one of the easier lessons. A SUB Is just a block of code that you can run anytime ya want. Here's an example: sub instruct Print "To play this game," Print "just use the arrow keys." Wait 60 cls end sub That's pretty simple right? However, a sub on it's own won't do squat. It's like a dog. First, you have to CALL it. Let's add some more code to it.. (type this in cybasic, you need hands on experince you know!) sub instruct Print "To play this game," Print "just use the arrow keys." Wait 60 cls end sub dim sel Print "Type 1 for instructions." input sel1 If sel1=1 then call instruct end if By now, you should pretty easily be able to figure out what the above code does. Remeber, all IF...THEN statements must have an END IF at the end of the statement. So, above, we ask for input, check to see if it is "1", and if it is, call the sub. Once the sub is called, the code in the sub is run, and then CyBasic begins running code from the End If line downwards (but since there isn't any code below End If, the programs ends.) That covers it..
Working with files Yes, CyBasic can do some simple file stuff. And I mean VERY simple. In fact, it's limited to text files, but it's useful, in it's own way. I guess I'll just start off with an example: open "test1.bs.txt" for write as 1 dim text [30] as char input text put 1, ,text close 1 In the above code on the first line, we open (create) test1.bs.txt FOR WRITING. This means we can put stuff in it.AS 1 Is merely naming the file 1, so we can call it later. On the line below that one, we dim text as being able to hold 30 charecters, we ask for input, and then we PUT what was typed in the file. With the PUT You type Put (File),(Space),(What you want to put. Not that hard huh? But what about reading files? Let's add some more code.. open "test1.bs.txt" for write as 1 dim text [30] as char dim gottext [30] as char input text put 1, ,text close 1 open "test1.bs.txt" for read as 2 get 2, ,gottext Print gottext close 2 Now in the above code, we right the text that was typed to a file, then, we open that file so we can READ from it, get the text, print it, and close the file. Easy enough.
Sounds and Lines Cybiko Inc, in their infinite wisom, provided a way to add deep engaging sound to your app. NOT! Sound in CyBasic is limited to 6 different beeps. Beeps 1-6. Descriptive huh? Just Type Beep # in your code and you'll be greated by a wonderful little beep. I used this in the intro for BOF III, but not for much else. Oh Well. On to lines... well. Hmph. Either I'm sleepy or I'm stupid.. but i never did get the lines and points command. So, instead of telling you how to use them in my own words, I'll lets cybiko inc. tell ya: Line X1, Y1, X2, Y2 X1, Y1, X2, Y2 � numeric expressions. There is a virtual rectangular coordinate system in the screen: the X-axis is horizontal, with the positive direction going to the right; the Y-axis is vertical, with the positive direction going up. (X1, Y1) are coordinates of the origin of line, while (X2, Y2) is coordinates of the point of line. Remember that -20000 is less than X,Y is less than 20000! However, you can draw on the screen only in the fixed range of coordinates: -80is less than X is less than 79, -43 is less than Y is less than43. If your coordinates don�t satisfy these conditions, you won�t see the result of the program, because it is beyond the bounds of the screen. This is not an error. It simply means that you cannot see it on the screen. Point Statement A Point Statement draws a point on the screen. Syntax Point X, Y X, Y � numeric expressions that correspond to the coordinates of the point. There is a virtual rectangular coordinate system in the screen: the X-axis is horizontal, with the positive direction going to the right; the Y-axis is vertical, with the positive direction going up. Remember that -20000 is less than X,Y is less than 20000! However, you can place a dot on the screen only in the fixed range of coordinates: -80 is less than Xis less than 79, -43 is less than Y is less than 43. If your coordinates don�t satisfy these conditions, you won�t see the result of the program, because it is beyond the bounds of the screen. This is not an error. It simply means that you cannot see it on the screen. So this ends this lesson and them all!!!! Good for you! NOW SEE IF YOU CAN MAKE A GAME!!!!!