From b14019f9a952ec718d597fe80954974ec7f6592b Mon Sep 17 00:00:00 2001 From: n00b Date: Thu, 24 Oct 2024 22:51:34 -0400 Subject: [PATCH] Added top navbar rcdoc files --- doc/files/arrays.txt | 44 ++++ doc/files/comments.txt | 17 ++ doc/files/conditions.txt | 39 ++++ doc/files/constants.txt | 8 + doc/files/func_sub.txt | 136 ++++++++++++ doc/files/graphics.txt | 77 +++++++ doc/files/hello_world.txt | 440 ++++++++++++++++++++++++++++++++++++++ doc/files/intro.txt | 6 + doc/files/io.txt | 25 +++ doc/files/license.txt | 21 ++ doc/files/loops.txt | 61 ++++++ doc/files/scope.txt | 16 ++ doc/files/setup.txt | 47 ++++ doc/files/sound.txt | 22 ++ doc/files/udt.txt | 52 +++++ doc/files/var_data.txt | 39 ++++ 16 files changed, 1050 insertions(+) create mode 100644 doc/files/arrays.txt create mode 100644 doc/files/comments.txt create mode 100644 doc/files/conditions.txt create mode 100644 doc/files/constants.txt create mode 100644 doc/files/func_sub.txt create mode 100644 doc/files/graphics.txt create mode 100644 doc/files/hello_world.txt create mode 100644 doc/files/intro.txt create mode 100644 doc/files/io.txt create mode 100644 doc/files/license.txt create mode 100644 doc/files/loops.txt create mode 100644 doc/files/scope.txt create mode 100644 doc/files/setup.txt create mode 100644 doc/files/sound.txt create mode 100644 doc/files/udt.txt create mode 100644 doc/files/var_data.txt diff --git a/doc/files/arrays.txt b/doc/files/arrays.txt new file mode 100644 index 0000000..b9985d4 --- /dev/null +++ b/doc/files/arrays.txt @@ -0,0 +1,44 @@ +#title RCBasic Arrays [RCBasic Doc] +#header ARRAYS + + +In complex programs there is often a need to be able to store large amounts of data. It would be unreasonable to have to create a variable for each piece of data we may need to store. This is where an array can come in handy. Arrays are simply ways of using one variable to store multiple different values. You can create arrays of numbers or strings. Look at the following: +#code +Dim A[5] +#/code + +The above example creates an array of numbers called A. A can store five numbers which are retrieved using A[0] to A[4]. Notice that A[4] is the last element in the array and not A[5]. That is because the first index in the array is 0 and the array only stores 5 numbers. To set the values in this array you could do the following: +#code +A[0] = 3 +A[1] = 2 +A[2] = 7 +A[3] = 1 +A[4] = 0 +#/code + +You would access and array just like you would a variable. Look at the following: +#code +X = A[0] + A[3] '( Based on the above example the variable X would be set to 4. ) +#/code + +To make a string variable you would do the same thing you do to make a number variable except you would use the $ just like you would use to make a normal string variable. Look at the following: +#code +Dim B$[3] + +B[0] = "ABC" +B[1] = "DEF" +B[2] = "I KNOW THE ALPHABET" +#/code + +Arrays can have up to 3 dimensions. Adding more dimensions to an array can make organizing data in the array easier depending on the situation. Look at the following: +#code +Dim X[2, 3] +Dim Y[3, 4, 5] +#/code + +The above example creates a 2 dimensional array called X which has 2 indices in its first dimension. Its second dimension has 3 indices. This means that each of the 2 indices in the first dimension can store 3 different values. So X can store a total of 6 different values. The second line creates a 3 dimensional array called Y. Y has 3 indices in its first dimension. Each of those 3 indices has 4 indices in its 2nd dimension. Each of the 4 indices has 5 values it can store. This means that Y can store a total of 60 different values. Look at the following for an example on how to work with these multi-dimensional arrays: +#code +X[0, 2] = 5 '(This line sets the 3rd value in the first index to 5. Remember that the first index is always 0 so the 3rd index will be 2.) + +Y[1, 2, 3] = 6 '(This line sets the 4th value of the 3rd index in the 2nd index in the array to 6. That was a mouth full. ) +#/code diff --git a/doc/files/comments.txt b/doc/files/comments.txt new file mode 100644 index 0000000..f839f32 --- /dev/null +++ b/doc/files/comments.txt @@ -0,0 +1,17 @@ +#title RCBasic Comments [RCBasic Doc] +#header COMMENTS + +Comments are remarks you can add to your code which will be ignored by the compiler. To make a comment you would use a single quote. Look at the following: +#code +' THIS IS A COMMENT +Print HELLO WORLD" ' THIS IS ANOTHER COMMENT +#/code + +MULTI-LINE COMMENTS + +Multi-line comments are comments that can span multiple lines. To start a multi-line comment you would use forward slash followed by a single quote and you would end it with a single quote followed by a forward slash. Look at the following: +#code +/' THIS IS +A +MULTI-LINE COMMENT '/ +#/code diff --git a/doc/files/conditions.txt b/doc/files/conditions.txt new file mode 100644 index 0000000..071cc7f --- /dev/null +++ b/doc/files/conditions.txt @@ -0,0 +1,39 @@ +#title RCBasic Conditions [RCBasic Doc] +#header CONDITIONS + +RC BASIC uses the same conventions of other programming languages to control the flow of the program. There are two main ways of getting your program to decide on its next course of action. The most common way is with the IF statement block. + +If 5 > 6 Then + Print "THIS WILL NOT PRINT" +ElseIf 5 < 6 Then + Print "THIS WILL PRINT" +Else + Print "THIS ALSO WILL NOT PRINT" +End If + +The above example does different comparisons and will output text to a console depending on which condition is true. + +The next method of control flow is the SELECT statement block. + +Select Case 5 +Case 6 + Print THIS WILL NOT PRINT" +Case 5 + Print "THIS WILL PRINT" +Default + 'Note: Default will be true if every other case is false. + ' Default is optional and can be excluded if you don't need it + Print "THIS WILL NOT PRINT" +End Select + +The above example will compare each case in the block to the SELECT CASE. If the case is equal to the select case then the code in that case will be executed. You can also add multiple values to compare to each CASE. +Select Case 5 +Case 6 + Print THIS WILL NOT PRINT" +Case 4, 5 + Print "THIS WILL PRINT" +Default + Print "THIS WILL NOT PRINT" +End Select + +The above example is mostly the same as the previous example. The difference is that in our second CASE we are comparing both 4 and 5. If either of them are equal to our SELECT argument then the code inside the CASE block will execute. diff --git a/doc/files/constants.txt b/doc/files/constants.txt new file mode 100644 index 0000000..e03751c --- /dev/null +++ b/doc/files/constants.txt @@ -0,0 +1,8 @@ +#title RCBasic Constants [RCBasic Doc] +#header CONTANTS + +RCBasic has a special type of variable called a constant which can hold an expression. This means it can hold an expression and not determine its value until its used. For example you can have a constant called C that is equal to A + B. Everytime you change the value of A or B, C's value will also change. Because constants hold expressions, any valid expression in RCBasic can be stored in a constant. +#code +const A = 5 +const MY_PRINT = print "hello world" +#/code diff --git a/doc/files/func_sub.txt b/doc/files/func_sub.txt new file mode 100644 index 0000000..7437549 --- /dev/null +++ b/doc/files/func_sub.txt @@ -0,0 +1,136 @@ +#title RCBasic Functions and Sub Routines [RCBasic Doc] +#header FUNCTIONS AND SUB ROUTINES + +Functions and Sub Routines are blocks of code that can be executed any where in your program. + +The biggest difference between Functions and Sub Routines is that Functions can return a value. Basically Functions and be used as a string or number value in an expression. RCBASIC has several built-in functions to perform different task such as compute square roots, get the time, etc. Functions are either numbers or strings just like variables and arrays. As such, functions can be used anywhere a variable or array can be used. Look at the following: + +#code +Dim x[2] +x[0] = Sqrt(25) +x[1] = Sqrt(36) +Print "THE SQUARE ROOT OF 25 IS "; x[0] +Print "THE SQUARE ROOT OF 36 IS "; x[1] +#/code + +The above code creates a number array called X with 2 elements in it. It stores the square root of 25 in the first index and stores the square root of 36 in the second index. It then outputs both values to the console. The output should look like this: + +THE SQUARE ROOT OF 25 IS 5 +THE SQUARE ROOT OF 36 IS 6 + +String functions can be used in a string expression just like number functions can be used in a number expression. Look at the following code: + +#code +B$ = Mid$("HELLO WORLD", 0, 2) +Print "THE FIRST TWO CHARACTERS IN HELLO WORLD ARE ";B$ +#/code + +The above code creates a string variable called B and stores 2 characters starting from position 0 in the string HELLO WORLD. It then outputs the value to the console. The output should look like the following: + +THE FIRST TWO CHARACTERS IN HELLO WORLD ARE HE + +Sub Routines can execute code in other parts of your program just like a function. However Sub Routines cannot return values and cannot be used in expressions. So why would you want to use a Sub Routine over a function? Well Sub Routines have less over head since it does not have to internally push a value onto the stack like a function does. So in cases where you do not need to return a value you should use a Sub Routine. RC BASIC has several built-in Sub Routines to perform task where a return value is not necessary. Look at the following: + +#code +FPrint("test") +#/code + +FPrint is a Sub Routine that outputs text to the console. Since FPrint doesn't perform calculations of any kind it did not need to be implemented as a Function. + +In addition to the built-in Functions and Sub Routines RCBASIC also allows programmers to build there own Functions and Sub Routines. You do this using the FUNCTION or SUB keywords. + +#code +Function MyFunc(a, b) + c = a + b + Return c +End Function +#/code + +The above code creates a function called MyFunc which takes in two arguments: a and b. To use this function you would call it like this: + +#code +MyFunc(3, 4) +#/code + +The code above will pass 3 and 4 to the variables A and B in MYFUNC respectively. The function creates a variable called C and sets it equal to the sum of 3 + 4. It then returns C. So the function equals 7. Since this is a number function you could store the value in a number variable or use PRINT to output the value to the console. + + +To make a string function you simply add $ to the end of the function name when you create it just like with variables and arrays. + +#code +Function MyString$ ( G$ ) + Return "YOU ENTERED " + G$ +End Function + +Print MyString("SOMETHING") +#/code + +The above code should output the following: + +YOU ENTERED SOMETHING + +Functions can also return a UDT(User Defined Type) as well. Look at the following: + +#code +Type test_type + Dim a$ + Dim b +End Type + +Function test(a$, b) As test_type + Dim ret_val As test_type + ret_val.a = a + ret_val.b = b + Return ret_val +End Function + +Dim myVar as test_type + +myVar = test("hello", 42) +#/code + +You can also have a UDT as a parameter in a function: +#code +Function test2(n as test_type, j) + Return 0 +End Function +#/code + +Sub Routines are created using the SUB keyword. Look at the following: +#code +Sub MySub ( ) + For i = 1 To 5 + Print i + Next +End Sub + +MySub ( ) +#/code + +The code above creates a Sub Routine called MYSUB which uses a FOR loop to output the numbers 1 to 5 to the console. + +Functions and Sub Routines pass variables by value by default. Look at the following: +#code +Sub MySub ( a ) + a = 5 +End Sub + +n = 0 + +MySub ( n ) +Print n +#/code + +In the above code the Sub Routine has a variable called A as an argument. It sets A equal to 5. Then we create a variable called N outside of the Sub Routine and set N equal to 0. N is passed as an argument to MYSUB. Then N is output to the console. This will output 0 to the console. That is because only the value of N is passed to MYSUB so MYSUB is not able to change N itself. In order to allow MYSUB to change N we must have MYSUB accept an argument by Reference. To do this we will use the BYREF keyword. +#code +Sub MySub ( ByRef a ) + a = 5 +End Sub + +n = 0 + +MySub ( n ) +Print n +#/code + +The above code is the same as the previous example except that now we use the BYREF keyword to change a to a reference rather than a value. This means the when we pass the variable N to MYSUB, instead of the value stored in N being used as A, whatever we do to A will be done to N directly. This example will output 5 to the console. diff --git a/doc/files/graphics.txt b/doc/files/graphics.txt new file mode 100644 index 0000000..13e35fe --- /dev/null +++ b/doc/files/graphics.txt @@ -0,0 +1,77 @@ +#title RCBasic Graphics [RCBasic Doc] +#header GRAPHICS + +Finally, the reason we are all here. Lets draw pretty pictures on the screen. The first thing we need is a window. To open the graphics window, we need to use OpenWindow(). +#code +fullscreen = false +vsync = true + +OpenWindow("My Graphics Window", 640, 480, fullscreen, vsync) +#/code + +The above code will open a 640 x 480 window with vsync enabled. You can reference OpenWindow() for a little more detail. + +If we tried to run the code we have so far, the window would open and immediately close. So next to keep our window open and ensure its getting updated we need to make our render loop. +#code +While Not Key(K_ESCAPE) + Update() 'This needs to be called every frame to refresh the window and poll events +Wend +#/code + +So now we have our basic render loop but nothing is being drawn. Now is a good time to explain how RCBasic's graphics system works. RCBasic uses virtual render targets called canvases. There are 3 different types of canvases that are used for rendering depending on what you are trying to do. Here is an overview of the different types of canvases: +#list ul +#li 2D Paint Canvas - This is a canvas for rendering drawing commands (ie. DrawImage, Rect, FloodFill, etc.) +#li Sprite Layer - A canvas for rendering sprites. Sprite canvases will only render sprites but they have infinite 2D space to place sprites in. +#li 3D Canvas - This canvas is a 3D viewport. Each 3D canvas has its own camera so having multiple can impact performance since it re-renders the scene for each 3D canvas. +#/list + +For now, lets just use a paint canvas. We use OpenCanvas() to open a paint canvas. Before our render loop, we will open our canvas. +#code + +paint_canvas = OpenCanvas(640, 480, 0, 0, 640, 480, 1) + +Canvas(paint_canvas) 'Sets out canvas as the active canvas. This is unnecessary since we only have one canvas but its a good habit to get into to set your desired canvas active before doing anything on it. + +While Not Key(K_ESCAPE) + ClearCanvas() 'Clears the canvas every frame. If you have an image that never changes you may not want to do this. + Update() +Wend +#/code + +Here we are opening a canvas for drawing and storing the handle for that canvas in a variable called paint_canvas. Anytime we want to reference that canvas we will use the paint_canvas variable. You can reference OpenCanvas() for more details on how it works. After we opened our canvas, we set it as the active canvas using Canvas(). This was not necessary right now since RCBasic sets the first canvas created as the default canvas but its still a good habit to set a canvas active before doing anything with it to ensure you are targeting the right canvas. + +Ok, we have a window and a canvas but we still haven't drawn anything. So lets do that. Inside our render loop, we are going to set our draw color to red and draw a box. + +#code +While Not Key(K_ESCAPE) + ClearCanvas() + + SetColor( RGB(200, 0, 0) ) 'Sets the drawing color to red + RectFill(20, 20, 50, 50) 'Draws a filled rectangle with the current draw color + + Update() +Wend +#/code + +So now our finished program looks like this: +#code +fullscreen = false +vsync = true + +OpenWindow("My Graphics Window", 640, 480, fullscreen, vsync) + +paint_canvas = OpenCanvas(640, 480, 0, 0, 640, 480, 1) + +Canvas(paint_canvas) + +While Not Key(K_ESCAPE) + ClearCanvas() + + SetColor( RGB(200, 0, 0) ) 'Sets the drawing color to red + RectFill(20, 20, 50, 50) 'Draws a filled rectangle with the current draw color + + Update() +Wend +#/code + +RCBasic allows you to create as many canvases as you want and you can have multiple different types of canvases at once. This is just a brief overview of how graphics work but I highly encourage you to check out all the included examples to see more of what is possible. diff --git a/doc/files/hello_world.txt b/doc/files/hello_world.txt new file mode 100644 index 0000000..37ea09b --- /dev/null +++ b/doc/files/hello_world.txt @@ -0,0 +1,440 @@ +#title RCBasic First Program [RCBasic Doc] +#header YOUR FIRST PROGRAM + + +This tutorial is designed to introduce complete newbies to the world of computer programming and specifically programming using RC Basic. This tutorial will not assume any previous programming knowledge and really won't even assume you know much about how a computer works. A basic understanding of 6th Grade Algebra will come in handy but is not necessary. Now that I got that out of the way, lets take our first steps in our journey to becoming computer programmers. + +First lets go over the requirements you will need to follow this tutorial. You will need a computer (obviously), RC Basic (yet again obvious, but I had to say it), and the will to learn (not essential but it will definitely help). Ok lets begin. + +

What Is A Computer Program?

+It seems like a stupid question but it is important to understand what a program is before we go any further. A computer program is simply a list of detailed instructions telling a computer how to perform a task. And when I say detailed I mean DETAILED. A computer can perform several complex equations a second but still does not know more than you do. If you don't know any complex equations neither does the computer. To give the computer our list of instructions on what we want it to do we use a computer language. There are probably as many computer languages as there are spoken languages and maybe even more. A computer programmer chooses a language based on the task they need to perform, how complex the task is, the time it takes to write the program, and personal choice. For this tutorial we will be using RC Basic. RC Basic is based on the BASIC programming language, which was designed to be easy to learn and use. RC Basic adds the advantage of modern multimedia features and the ability to write our program once and run it on multiple operating systems. + +

Our First Program

+Lets start off with a simple computer program. We are going to make a program that writes the words "Hello World" to the screen. To tell the computer to write some text to the screen we will use the Print command. Type the following into the RC Basic Editor and click the Run button (the triangle button or you could go into the build menu and click Run). + +#code +Print "Hello World" +#/code + +You should see "Hello World" in your console window. Congratulations, you just wrote your first computer program. So lets break this program down into its individual parts. First is the Print command. This is telling the computer to write something to the console (I will be referring to the DOS screen as the console for the rest of this tutorial). And then we have "Hello World". First of all, why is it in quotation marks? The short answer is because it is not a number. We will go over this more in depth later but for now that is all we need to know for right now? Before we move on, use the Print command to write some other stuff to the screen. + +

Data Types

+We are finally going to learn why "Hello World" has quotations around it. So lets talk about data types. A data type is simply the type of data you are working with. RC Basic has 2 data types: Numbers and Strings. Numbers are exactly what you think they are. So what are strings? Well to answer this we have to understand what a character is. A character is a number which is generally represented by some kind of symbol. I know that doesn't make since right now so just think of a character as any key on your keyboard. The A Key, B Key, and even the SPACE Key are only numbers to the computer. When the computer reads a character it is actually reading a number and then it outputs a symbol (like letters, digits, parenthesis, space, etc.). So what then is a string? Well a string is a group of characters strung together (which is why it is called a string). RC Basic uses quotation marks to group characters together into a string. So in the string "Hello World", H is a character, e is a character, and so on. If you want to use a single character you would still use quotation marks but you would only have one character between the quotation marks. + +Look at the following examples. + +#code +"42" +42 +#/code + +The first line is a string and the second line is a number. Are you confused yet? The first line has the character "4" and the character "2" in a string and the second line is the number 42. Yes they look the same but the way you perform operations on a string is different than the way you perform operations on numbers. It will make more since with the examples below. + +This will add the string "53" to the end of the string "42" and output 4253 to the console. Try it. + +#code +Print "42" + "53" +#/code + +This will will add the number 42 to the number 53 and output 95 to the console. Try it. + +#code +Print 42 + 53 +#/code + +The differences between numbers and strings should be starting to clear up a little by now. If you are still a little confused at this point don't worry. This is only an Introduction to programming. If you are able to write some text on the screen and do some simple math by the end of this tutorial you will be ready to continue into the next lesson. + +Now we are going to get into operators. I know I said at the beginning of the tutorial I did not expect you to know much but I am assuming you know how to add, subtract, multiply, and divide. We got a brief introduction to the "+" operator in the last example. It is important to note that the "+" operator is the only operator that works on both numbers and strings. + +Here is a list of the main string operators. +"+": Adds one string to the end of another. This example will output "batman" to the console. + +#code +Print "bat" + "man" +#/code + +Before we continue, lets break down the PRINT statement. It is the simplest way to get text on the screen. PRINT also allows us to output multiple items of different types by separating them with a “;”. + +#code +Print “Text”; 5+4; “ More Text”; + +‘Ending Print with a “;” keeps the cursor on the same line in the console. +#/code + +Here is a list of the main number operators. +"+": Adds two numbers together. This example will output 8 to the console. +#code +Print 6 + 2 +#/code +"-": Subtracts one number from another. This example will output 4 to the console. +#code +Print 6 - 2 +#/code +"*": Multiplies two numbers (Note: Multiplication uses an * instead of an x). This example will output 12 to the console. +#code +Print 6 * 2 +#/code +"/": Divides one number by another. This example will output 3 to the console. +#code +Print 6 / 2 +#/code +"^": Raises a number to a power. This example will output 36 (6 to the second power) to the console. +#code +Print 6 ^ 2 +#/code + +Both string operators perform the same operation. They will place the characters in the second string at the end of the first string. The number operators perform the same operations they do on a calculator. One more important thing to mention is that the number operators follow the Order of Operations. Take a look at the example below. +#code +Print 4+3*2 +#/code +In the example above the, following the order of operations PEMDAS (Parenthesis, Exponents, Multiplication, Division, Addition, and Subtraction); 3 is multiplied by 2 which is 6, and then 4 is added to it which is 10. So math is not necessarily done from left to right but it is determined by the order of operations. There is more to the order of operations but we are not going to cover that right now. We covered all of the main operators so before we move on lets look at one more example that uses parenthesis. +#code +Print (4+3)*2 +#/code +This is almost the same problem as the example before it, but now it groups 4 plus 3 together using parenthesis which means 4 and 3 are added first which will be 7. Then that 7 is multiplied by 2 which is 14. If you do the same problems on a calculator you will get the same answers. Try out a few math problems on your own. + +Interacting With The User +Up to this point, we have been writing output to the screen. We have been the user as well as the programmer so there was no reason to need to accept input from the screen. But when you write programs that are meant to be used by people other than yourself you will want to get input from the user and process that input to perform some task. So lets dive into some code. For this example we are using the function Input to ask the user "What is your name? " and read what the user types into the console (which should be there name but they can type whatever they want). +#code +Input$("What is your name? ") +#/code +You should have seen "What is your name?" and then been able to type something in. You have just received input from the user for the first time. So lets break this line down. First we have the function name Input$. Input$ is a built-in function that prompts the user with something and it returns what the user typed. This is the first time I used the word returns so let me clarify. In the example above lets say you type in Bob for your name. The whole Input$() function call is replaced with "Bob". Take a look at this example. + +This line does not prompt anything and just waits for you to type something. We are going to type Bob. +#code +Input$("") +#/code +After you enter "Bob" the line above will be replaced with "Bob" and the line will finish processing your commands. +#code +"Bob" +#/code +You are probably thinking that is useless. What can we do with a line that just has a string on it. And the answer is you really can't do anything with a line that just has Bob on it. But if we store the string "Bob" we can use it to do other stuff with. + +To store "Bob" (or whatever you call yourself) we use something called a variable. You might have seen variables used in math class in school. A variable is just a symbol that holds data. By symbol I don't mean a logo or anything. Just take a look at this example. +#code +a = 2 +b$ = "Bob" +batman = 4.5 +superman$ = "this is just random text" +#/code +This example makes four variables: a, b$, batman, superman$ and stores some data in them. Lets do a break down. + +We will start with the variables a and batman. The variables are just storing numbers. We can use variables that store numbers when we have programs that are going to be handling values that change over time. For now lets just do some simple math. Type the variables from the previous example and add the following code and run it. +#code +Print a + batman +#/code +This example just adds the values in the variables together and outputs the values to the screen. You can change the value of a variable at any time. This is better explained with another example. +#code +a = 5 +Print a +a = 6 +Print a +a = 5 + 6 +Print a +#/code +What we are doing in the example above is changing the value of a and doing math and storing the value in a. We can also store the value of one variable inside another. Lets Look at another example. +#code +a = batman +Print a +a = a + batman +Print a +#/code +The example above will first store the value of batman in the variable a. It will write a to the screen. Then it will add a and batman and store the result in a and write that value to the screen. + +Now we are going to take a look at the other two variables we created: the variable b$ and the variable superman$. Did you notice that both of the variables end in a $. There is a reason for that. The $ at the end of the variable name lets the compiler know that these variables are strings. Since these two variables are strings the rules about strings apply to these variables. Look at the following examples. +#code +Print b$ +Print superman$ +Print b$ + superman$ +#/code +The above example writes the value stored in b$ to the screen. Then it writes the value stored in superman$ to the screen. Finally it adds the contents of the superman$ variable to the end of the contents for the b$ variable and writes that to the screen. + +Now that we have covered variables, how do we use them with the users input. Well lets look at the Input$() function again. Notice that the function ends in a $. input$() returns a string so it can be used anywhere a string can. Look at this example. + +This line does the same thing as the last time we used the Input$() function. The main Difference is now we are storing the value the user enters into the variable name. +#code +name$ = Input$("What is your name?") +#/code +This code will store "Bob" or what ever you typed in into the variable name$. Now we can use the name$ as many times as we want anywhere in our program. So now lets make a program that Uses Input$() along with Print. We are going to ask the User for there name and then welcome the User to RC Basic. +#code +name$ = Input$("What is your name? ") +Print "Hello " + name$ + ". Welcome to RC Basic." +#/code +Lets do our break down again. In the first$ line we create a variable called name$ and call Input$() in it. This will write "What is your name? " to the screen. When the User Enters something, whatever the User types in will replace Input$(). So name$ will be whatever the User types in. On the next line we use Print to write a message to the screen. The only thing different this time is we are adding a variable to our string in Input$(). But remember that our variable is a string and can do anything a string can, so all you are doing is saying "Hello " + the User's name + ". Welcome to RC Basic.". + +We have covered a lot in these first few sections so I am going to take this time to challenge you. Write a program that ask the User to type there favorite color in and then tell them what there favorite color is on the next line. + + +Flow Control +Flow control sounds like some really complicated topic. But it will probably make sense almost immediately. So what is flow control? Simply put, flow control is controlling what your program does based on what conditions are met. To control the flow in our programs we will use the If statement. The If statement will allow us to execute a block of code depending on what conditions are met. Let look at the last example from the last segment. +#code +name$ = Input$("What is your name? ") +Print "Hello " + name$ + ". Welcome to RC Basic." +#/code +To give an idea of how to use the IF statement we are going to extend this program. So lets make the program give a special greeting if Bob is typed in for the name. Look at the following example. +#code +name$ = Input$("What is your name? ") +Print "Hello " + name$ + ". Welcome to RC Basic." + +If name$ = "Bob" Then +Print "We have been expecting you" +End If +#/code +This program will do the same thing it did in the last segment but it adds the use of the IF statement. So lets do a quick break down. + +This line is saying if name$ has "Bob" stored in it, then run the following code. Each IF statement must end with the THEN statement. +#code +If name$ = "Bob" Then +#/code +This line is writing "We have been expecting you" to the screen. +#code +Print "We have been expecting you" +#/code +This line is ending the block of code that the IF statement wanted the program to execute and continues the rest of your program. + +The block of code started by the IF statement can also be given different conditions to check for and execute a different block of code for each different condition. We are going to take a break from strings and use numbers for our next few examples. We are also going to introduce a few new operators. So lets start by making some number variables. +#code +a = 1 +b = 3 +c = 5 +#/code +Now that we have some variables we are going to make a program that ask the User to enter a number and check if the number is equal to each variable and outputs something different for each one. First I need to cover one very important topic. The Input$() function only takes in a string. So even number that are typed in by the User are treated as strings. So we need to convert the Users input to a number to be able to compare it to another number or do any kind of math with it. To do this we will use the Val() function. The Val() function converts a string to a number. Look at the following example real quick. + +This example will convert the string "12" to the number 12. +#code +x = Val("12") +#/code +The more programs you write, the more you will get use to converting numbers to strings and strings to numbers. So how do we use Val() with Input$(). Well remember that Input$() can be used anywhere a string can. So instead of putting "12" in Val() like we did in the last example we will simply put Input$() inside Val(). Make sure your program has the variables a, b, and c we created earlier and add this. +#code +d = Val( Input$("Enter a number: ") ) +#/code +The code above is creating a variable called d. Then it uses the Val() function to convert the string returned by Input$() into a number. The string returned by Input$() is what ever the User types in. Now that we have gotten a number from the User lets compare that number to the variables we made earlier. +#code +If d = a Then +Print "You typed the A value" + +ElseIf d = b Then +Print "That is B" + +ElseIf d = c Then +Print "That would be C" + +Else +Print "You did not type any of the numbers" + +End If +#/code +Lets do a break down. This is starting a multi-layered If statement block. It should be fairly simple to understand. We are going to go through each line and examine what is happening step by step. + +This line is starting your If block by comparing d(which is what the User typed in) to the variable a. If the two variables are equal then it will output "You typed the A value" to the console. +#code +If d = a Then +Print "You typed the A value" +#/code +This line will compare d and b if d wasn't equal to a. If the value stored in d is equal to the value stored in b then it will output "That is B" to the console. +#code +ElseIf d = b Then +Print "That is B" +#/code +This line will compare d and c if d wasn't equal to a or b. If d is equal to c then "That would be C" is output to the console. +#code +ElseIf d = c Then +Print "That would be C" +#/code +This line will output "You did not type any of the numbers" if none of the previous conditions were met. +#code +Else +Print "You did not type any of the numbers" +#/code +And finally this line will end the If block and finish running the rest of the program. +#code +End If +#/code +Now we are going to play with a few other operators for numbers only. In addition to being able to compare if two numbers are equal we can also compare if one number is greater than another, less than another, not equal to another, greater than or equal to another, etc. Here is a list of comparisons we can do with numbers. + +Given we have two number stored in variables a and b. + + + + •.a = b : Test if a is equal to b + + •.a < b : Test if a is less than b + + •.a > b : Test if a is greater than b + + •.a <= b : Test if a is less than or equal to b + + •.a >= b : Test if a is greater than or equal to b + + •.a <> b : Test if a is not equal to b + + + +Here is a few examples of doing some of these comparisons with a IF statement. +#code +If a = b Then +'Code to execute +End If + +If a < b Then +'Code to execute +End If + +If a <> b Then +'Code to execute +End If +#/code +These other comparisons are pretty straight forward. To try these out we are going to make a program that ask the User to enter a number. If the number is less than or equal to 10 then "Low" will be output to the console. If the number is greater than 10 then we will check if the number is greater than 20. If it is then then "High" will be output to the console. If neither of these conditions are true then "Mid" will be output to the console. First we need to get a number from the User. Remember we need to use the Val() function to convert the User's input from a string to a number. + +Here is where we take the User's input and convert it to a number. The Input$() function will get replaced with what the User types in so we simply use the Val() function to convert Input$() to a number. +#code +user_num = Val( Input$("Enter a number: ") ) +#/code +We start our If block by comparing user_num (Our input from the User in the previous line) to the number 10. If the user_num variable is less than or equal to 10 then we use the Print statement to write "Low" to the console. +#code +If user_num <= 10 Then +Print "Low" +#/code +If the previous comparison is false then we compare the user_num variable to 20. If user_num is greater than 20 then we will write "High" to the console. +#code +ElseIf user_num > 20 Then +Print "High" +#/code +Finally, if none of the previous conditions are true we will write "Mid" to the console. +#code +Else +Print "Mid" + +End If +#/code +Our complete program looks like this. +#code +user_num = Val( Input$("Enter a number: ") ) + +If user_num <= 10 Then +Print "Low" + +ElseIf user_num > 20 Then +Print "High" + +Else +Print "Mid" + +End If +#/code +The last thing we will cover on flow control is the keywords AND, OR, XOR, and NOT. These 4 keywords are actually operators that can be used for more specific comparisons. We will start with the AND operator. The AND operator will compare the conditions to its left and its right. If both conditions are true the AND operator sets the whole expression as true. I already know you didn't understand that explanation so it will probably be easier to show you. Just look at this example. + +This code will write "This is true" to the console because 1 is equal to 1 and 4 is greater than 2. Yes it is that simple. +#code +If 1=1 AND 4>2 Then +Print "This is true" +End If +#/code +The OR statement will set the whole expression it is being used in if at least one of the conditions is true. Here is an example of OR. + +This code will write "This is true" to the console because although 1 is not equal to 2, 5 is less than or equal to 6. +#code +If 1=2 AND 5<6 Then +Print "This is true" +End If +#/code +The XOR statement is like the OR statement with one major difference. With XOR, one of the conditions in the expression has to be true and the other has to be false. Here is an example of XOR. + +This code will write "This is true" to the console because 1 is equal to 1 and 2 is equal to 2 ( 2 <> 2 is false because 2=2. Remember <> is the NOT EQUAL operator). Basically one condition in the XOR expression has to be true and the other has to be false otherwise the whole expression is false. If this is slightly confusing don't worry. In my 15+ years of programming experience I have never once used this operator. +#code +If 1=1 XOR 2 <> 2 Then +Print "This is true" +End If +#/code +The last of these special operators we will cover is NOT. This one will be extremely simple to understand. Basically if an expression is true it becomes false and if an expression is false it becomes true. + +This code will write "This is true" to the screen because the expression 1=3 is false. The NOT statement reverses the false and makes it true. +#code +If NOT (1=3) Then +Print "This is true" +End If +#/code +Lets go over one more program before we move on to the next segment. We will ask the User for a number from 1 to 10. If the User enters 3 or 4 then we will write "Good Answer" to the console. If the User enters a number greater than 5 and less than 9 (Basically 6, 7, or 8) then we will write "Choice numbers" to the console. If the User types in any other number then we will write "Maybe next time" to the console. + +Here we are asking the User to enter a number from 1 to 10 using the Input$() function. Input$() returns a string so we have to store it in a string variable. +#code +user_in$ = Input$("Enter a number from 1 to 10: ") +#/code +Then we convert the string the User entered into a string using the Val() function. Note: We are using a string variable inside the Val() function instead of using Input$() inside it this time. I am showing it this way to get you used to the idea that Val() takes a string. It can be a string variable, string function, or just a regular string between quotation marks. +#code +num = Val(user_in$) +#/code +In the first line of this piece of code we are comparing the variable num (which is the number the User entered) to the number 3 and we compare the variable num to the number 4. If the variable num is equal to the number 3 or 4 then we write "Good Answer" to the console. +#code +If num = 3 OR num = 4 Then +Print "Good Answer" +#/code +This block of code compares the variable num to the number 5 and the number 9 if the previous If condition was false. If num is greater than 5 and num is less than 9 then we write "Choice numbers" to the console. +#code +ElseIf num > 5 AND num < 9 Then +Print "Choice numbers" +#/code +Finally this last bit of code will write "Maybe next time" to the console if none of the previous IF conditions were true. It then ends the IF block. +#code +Else +Print "Maybe next time" + +End If +#/code + +

FUNCTION

+This is going to be fairly short. So what is a function? A function is a block of code that is labelled by some kind of name so it can be called at any point in a program. I know you are confused again. But you have been using two functions several times throughout this tutorial. The Input$() function and the Val() function. A function has a return value that is either a number or a string. The Input$() function returns a string so it can be used anywhere in your program a normal string can be used. The Val() function returns a number so it can be used anywhere in your program a number can be used. Yes even inside a math problem. Are these the only two functions available in RC Basic. Not even close. There are over 200 functions available in RC Basic which allows you to do various task. Here is how a function is structured. + +function_name ( argument1, argument2, ..etc ) - A function can have no arguments or several arguments. Arguments in a function can be numbers or strings, it just depends on what function you are using. So lets look at a few different functions to see how other functions are used. + +Abs() returns the Absolute value of a number. +#code +Abs( -4 ) +#/code + +Date$() returns the current date as a string. +#code +Date$() +#/code + +UCase$() returns the argument you give it as an all uppercase string. +#code +UCase$("Hello World") +#/code + +As you can see there are different functions to accomplish different task. You can learn more functions by looking in the RC Basic reference manual located in the Docs folder in the rcbasic directory. + +

LOOPS

+We have finally made it to the last part of this tutorial. We are already fairly familiar with most of the core concepts of programming. We are finishing this lesson with a brief overview of loops. Loops are exactly what you think they are. They are ways of repeating blocks of code in your program as much as you need them to. Why would we need to repeat parts of our program? Well you will often have a program that you will want to continue running until the user is done using it or you will want to make a counter of some kind. + +We are going to cover two types of loops. The first one we are going over is the FOR loop. For loops are used when you want to cycle through a block of code a set number of times. Lets just dive into the code. + +Type this code into your editor and run it. +#code +For i = 1 to 10 +Print i +Next +#/code +The code in the example above writes the numbers 1 to 10 in the console. The FOR loop starts with a variable, which in this case is i. We set it with an initial value of 1 and tell the computer to loop the code between the FOR line and the NEXT line until i is equal to 10. When the NEXT statement is reached, i is increased by 1 and the program goes back to the start of the loop. That is how the FOR loop works in a nutshell. There is some extra control we can take over the For loop with the STEP statement. With the STEP statement we can change the amount the variable in the For line increases by. Look at the following example. + +This code will write the even numbers from 2 to 10 to the console. +#code +For i = 2 to 10 Step 2 +Print i +Next +#/code +The last loop we are covering in this tutorial is the WHILE loop. The WHILE loop will loop through a block of code while a certain condition is true. Look at the following example. +#code +i = 1 +While i <= 10 +Print i +i = i + 1 +Wend +#/code +In the example above we are doing a little bit more than we have been doing up to this point. First we are creating a variable called i. We start a While loop that compares i to the number 10. If i is less than or equal to 10 then we write the value stored in i to the console. Then we get to the line i = i + 1. This line is making i equal to the value stored in i plus 1. Basically we are increasing i by 1. The WEND line goes back to the start of the WHILE block where it compares i to 10 and if it is less than or equal to 10 it repeats the block of code again. + +Now for some challenges. + +1. Write a program that ask the User to enter a number. Then create a loop that outputs every number between 1 and the number the user enters to the console. +2. Write a program that continues to ask the User for there name until they enter "Bob". Then tell the User "Good by Bob". + diff --git a/doc/files/intro.txt b/doc/files/intro.txt new file mode 100644 index 0000000..dde19f4 --- /dev/null +++ b/doc/files/intro.txt @@ -0,0 +1,6 @@ +#title Introduction to RCBasic [RCBasic Doc] +#header INTRODUCTION TO RCBASIC + + First I would like to say thank you for taking an interest in RCBASIC ( I use all caps because I think it looks more retro that way). RCBASIC is a variant of the BASIC programming language. It consist of a compiler, interpreter, and a code editor. This version of BASIC was mostly influenced by sdlBasic and QBasic. My main reason for writing this software was just to have fun and challenge myself. This language is not as full featured as C++ or Java but you can still create some awesome stuff with it. I hope you have as much fun using this software as I had making it. + + Rodney Cunningham (aka. n00b) diff --git a/doc/files/io.txt b/doc/files/io.txt new file mode 100644 index 0000000..cb35c1d --- /dev/null +++ b/doc/files/io.txt @@ -0,0 +1,25 @@ +#title RCBasic I/O [RCBasic Doc] +#header INPUT/OUTPUT + +RC BASIC has two ways of getting output to a text console. The first way is the PRINT keyword shown here: +#code +Print "HELLO WORLD" +Print 5 +#/code + +You can also use a ";" to output multiple values or to prevent PRINT from going to a new-line in its output. +#code +Print "This is line 1. "; +Print "This is still line 1. Value="; 4+5; " This is the end of line 1" +Print "Line 2 start" +#/code + +You can also use the FPrint() sub routine to do the same thing as PRINT. It was added back in RCBasic v1.0 since PRINT was not able to stop new-line after its output back then. This is a legacy hold over and does not really add any new functionality. + + +To get input from the user you would use the INPUT$ function. INPUT$ will display a prompt to the user and then get input from the console. +#code +USER_NAME$ = INPUT$("WHAT IS YOUR NAME? ") +#/code + +The above example will ask the user WHAT IS YOUR NAME? and then store whatever the user types in into the variable USER_NAME$. diff --git a/doc/files/license.txt b/doc/files/license.txt new file mode 100644 index 0000000..41f7588 --- /dev/null +++ b/doc/files/license.txt @@ -0,0 +1,21 @@ +#title RCBasic License [RCBasic Doc] +#header LICENSE + + RCBasic is available under the zlib license : + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not +claim that you wrote the original software. If you use this software +in a product, an acknowledgment in the product documentation would be +appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be +misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. + diff --git a/doc/files/loops.txt b/doc/files/loops.txt new file mode 100644 index 0000000..28f76ec --- /dev/null +++ b/doc/files/loops.txt @@ -0,0 +1,61 @@ +#title RCBasic Loops [RCBasic Doc] +#header LOOPS + +RC BASIC has 3 types of loops: FOR, WHILE, and DO. + +The FOR loop repeats a block of code and increments a counter each time it finishes the block between FOR and NEXT. When the counter reaches a certain value the FOR loop stops. +#code +For I = 1 To 5 + Print I +Next +#/code + +The above code will output the numbers 1 to 5 to the console. Optionally you could use the STEP keyword to set the number that the counter will increase by. Look at the following: +#code +For I = 1 To 5 Step 2 + Print I +Next +#/code + +The above code will output the numbers 1, 3, and 5 to the console. The STEP keyword increases I by 2 each time through the FOR loop. + +WHILE loops will execute a block of code while a certain condition is true. +#code +I = 0 +While I < 5 + Print I + I = I + 1 +Wend +#/code + +The above code will output the numbers 0 to 4. It will not output the number 5 because if ( I < 5 ) is false the loop will not repeat. + +The DO loop is similar to the WHILE loop with an exception. The WHILE loop checks for the loop condition at the start of the loop but the DO loop checks for the loop condition at the end of the loop. What this means is that a WHILE loop will never execute if the condition is false at the start but the DO loop is guaranteed to execute at least once before it checks if the condition was true or not. + +The DO loop is also unique in that it has 3 different forms. Here is the simplest form of the DO loop. +#code +Do + Print "HELLO WORLD" +Loop +#/code + +The code above will continue to output HELLO WORLD to the console infinitely. +#code +I = 0 +Do + Print I + I = I + 1 +Loop While I < 5 +#/code + +The above code will output the numbers 0 to 4 to the console. This form of the DO loop will continue to loop while the loop condition is true. + +#code +I = 0 +Do + Print I + I = I + 1 +Loop Until I = 5 +#/code + +The above code will output the numbers 0 to 4 to the console. This form of the DO loop will continue to loop until the loop condition is true. diff --git a/doc/files/scope.txt b/doc/files/scope.txt new file mode 100644 index 0000000..45f9b63 --- /dev/null +++ b/doc/files/scope.txt @@ -0,0 +1,16 @@ +#title RCBasic Scope [RCBasic Doc] +#header SCOPE + +Scope refers to where you are able to access a variable. Basically variables cannot be accessed from outside the scope they are created in. Look at the following: +#code +A = 5 + +While A < 10 + B = 1 '----- B is created inside this loop and cannot be accessed outside of this loop + A = A + 1 '----- A was created before this loop started so it will be able to be used after this loop ends +Wend + +Print B +#/code + +The above program WILL NOT COMPILE. That is because the variable B was created inside the scope of the WHILE loop and nothing outside the WHILE loop will be able to access it. The variable A was created outside the WHILE loop so the variable A could be used anywhere in this example. So a variable can go into a deeper scope than where it was created but it cannot go to a lesser scope than where it was created. A scope deepens every time a new block is started. Blocks refer to the code within a loop, within a Function, or within a Sub Routine. diff --git a/doc/files/setup.txt b/doc/files/setup.txt new file mode 100644 index 0000000..54c2bff --- /dev/null +++ b/doc/files/setup.txt @@ -0,0 +1,47 @@ +#title RCBasic Setup [RCBasic Doc] + +

SETTING UP RCBASIC

+ +RCBasic comes with 2 command-line tools for creating programs. The first is rcbasic_build which takes your sourcecode in your *.bas file and compiles it into a *.cbc file. The *.cbc file contains intermediate bytecode which can be ran with the rcbasic (rcbasic.exe on windows) application. + +NOTE: On Windows, you need to include all the 32-bit dlls with the 32-bit executable and all the 64-bit dlls with the 64-bit executable. The rcbasic package tool will automatically do all of this for you as well as package for other systems as well. + +

RUN PROGRAMS FROM GEANY

+ +LINUX +In the installer directory there is a folder called geany_files. Inside the folder there is a file named filetypes.rcbasic. You can override the geany *.bas configuration by replacing the freeBasic configuration with this file. Just copy this file to the geany filedefs path, which on most linux distibutions should be (/home/.config/geany/filedefs), and rename the file to filetypes.freebasic. + +Once you have rcbasic set up with geany you just need to create a new file and save it as *.bas. Then you can compile your program by going to Build->Compile. Once your program is compiled you can run it by going to Build->Execute. + +NOTE: If you want to use a different file extension for rcbasic programs you can still use this file and just set it up for a different extension. Refer to the geany documentation on how to set up different file types. + + +WINDOWS +Geany comes preconfigured with rcbasic on windows. Just run the start_editor.bat file and create a new *.bas file. Select the File->New with Template option in the menu to start with a simple template program. Once you have created a new *.bas file goto Build->Compile to compile your program to a *.cbc file. Then goto Build->Execute to run your program. + + +

USING RCBASIC FROM THE COMMAND-LINE

+RCBasic will be added to path on install on linux. On Windows you will need to add the rcbasic folder to your path. Either (rcbasic/rcbasic_32) or (rcbasic/rcbasic_64) depending on your operating system. Once rcbasic is in your path you can simple pass a source file to rcbasic_build to create a *.cbc file. + +#code +rcbasic_build myprogram.bas +#/code + +Once you have a *.cbc file you can pass it to rcbasic to run it. + +#code +rcbasic myprogram.cbc +#/code + +Both tools also except the --version argument which will simply output the version of rcbasic you are using. + +#code +rcbasic_build --version +rcbasic -version +#/code + + + +

PORTING TO OTHER PLATFORMS

+ +From RCBasic Studio, select tools->distribute and then select the platforms you want to distribute to and click the "MAKE APP" button. diff --git a/doc/files/sound.txt b/doc/files/sound.txt new file mode 100644 index 0000000..8fb64bc --- /dev/null +++ b/doc/files/sound.txt @@ -0,0 +1,22 @@ +#title RCBasic Sound [RCBasic Doc] +#header SOUND + +Loading sound and music is fairly straight forward. The big difference between sounds and music is that your program can only have one music track but you could have several sound tracks at once. + +Lets first go over loading and playing sounds. +#code +snd = LoadSound("MySound.wav") 'Load a sound file +PlaySound(snd, 1, 3) 'Play the sound loaded in snd on channel 1 for 3 loops +#/code + +There is a lot you can do with sounds when playing them including simulating 3D positional audio. I highly encourage you to play around with the audio to find the right mix for your project. + + +There is only 1 music track that can be loaded at one time. Loading and playing music is pretty straight forward. + +#code +LoadMusic ( "MYMUSIC.MP3" ) +PlayMusic ( -1 ) 'Setting the music loop to -1 will have it loop infinitely +#/code + +Music is even simpler than sound. Generally all you will want to do is load a music track and set it to loop infinitely but you have a lot of control over how the music plays as well. diff --git a/doc/files/udt.txt b/doc/files/udt.txt new file mode 100644 index 0000000..6f9ff5f --- /dev/null +++ b/doc/files/udt.txt @@ -0,0 +1,52 @@ +#title RCBasic UDTs [RCBasic Doc] +#header USER DEFINED TYPES (UDTs) + +RCBasic v4 and up introduces the ability to create user defined types. These are basically structures that allow you to store and manage related data. To create a user defined type you need to use the TYPE keyword. Look at the following: +#code +Type player + Dim x, y +End Type +#/code + +In the above code, a type called player is created. The DIM keyword must be used to add attributes to our type. Now we can create a variable with the data type player as follows: +#code +Dim hero As player +#/code + +Notice that in the above code, we are using the DIM keyword we have used in previous sections to create variables and arrays. We now have a variable called hero whose data type is player. + +Since our hero variable is of type player, it has all the attributes of that type. So we can access the attribute's with a "." like so: +#code +hero.x = 23 +Print "Hero x is "; hero.x +#/code + +The attributes of a UDT variable are accessed the same way a normal variable is. You can also create an array of UDT's the same way you would create a normal array. Look at the following: +#code +Dim enemy[20] As player +#/code + +If you read through the section on arrays then this should make sense. We are using the DIM keyword to make an array called enemy and then we use the AS keyword to set the type of enemy to player. + +UDTs can also be used for attributes inside other UDTs. Lets say we wanted each player to have stats like health and power. We could create a UDT for player stats and have an attribute of that stat type inside our player UDT. Here is that example demonstrated: +#code +Type Player_Stats + Dim health + Dim power +End Type + +Type Player + Dim x, y + Dim stats As Player_Stats +End Type + +Dim hero As Player +#/code + +In the above example, hero now has an attribute called stats that is of type Player_Stats. So now we can access the stats attributes like so: +#code +hero.stats.health = 100 +Print "Hero Health = "; hero.stats.health +#/code + +If used effectively, you can drastically increase the readability and maintainability of your code. Especially in large projects. diff --git a/doc/files/var_data.txt b/doc/files/var_data.txt new file mode 100644 index 0000000..ffd06db --- /dev/null +++ b/doc/files/var_data.txt @@ -0,0 +1,39 @@ +#title RCBasic Variables [RCBasic Doc] +#header VARIABLES AND DATA TYPES + +RC Basic supports two basic types of data: Numbers and Strings. These data types can be used to represent any type of data used in a program. + +Numbers can be either integers or floating point. To designate an integer value you simply write out the number where you need to use it. Floating point numbers are similiar except that you would write a decimal point to denote the start of the floating point value. Look at the following: + +#code +5 'Integer Number + +5.5 'Floating Point Number +#/code + + +Strings are used to store and manipulate data other than numbers. They can be used to refer to single characters, words, sentences, paragraphs, etc. Look at the Following: + +#code +"HELLO WORLD" 'String +#/code + +Notice that the string "HELLO WORLD" is surrounded by quotation marks. When setting a strings value manually you must use quotation marks. + +In order to be able to use string or number data to do anything useful we have to be able to store and retrieve the data. This is what variables are used for. Look at the following: +#code +A = 5 + +B$ = "HELLO WORLD" +#/code +The above example creates two variables. The variable A stores the number 5 and the variable B$ stores the string HELLO WORLD. Note that the variable B ends with a $. The $ has to be used when creating a string variable to let RC BASIC know its a string and to not treat it as a number. You only have to use the $ when you first create the variable. + +If you don't want to set the value of a variable when you create it you can create the variable with the DIM keyword like this: +#code +Dim A + +Dim B$ +#/code +You can also declare multiple variables with DIM. + +Dim A, B$, C