|
Submitted By: Xeda112358 Date: October 18, 2011, 11:45:55 am Views: 1066 | |||
Summary: This is a tutorial designed to help Grammer users. I explain key concepts with a few short example codes. | |||
Grammer Tutorial Introduction Grammer is a programming language designed to be powerful, fast, efficient, and safe. However, with all of that said, though it isn't as tough to learn as Assembly, it will probably be a little more difficult than BASIC. One similarity to BASIC is that Grammer is interpreted. This makes it slower than assembly, but it is smaller and more safe. This tutorial will be designed to show Grammer users all the cool features and hacks that Grammer provides, so have fun! Terminology There are ideas and terms in Grammer that would almost never appear in BASIC. So the first thing that neads to be covered is terminology: Pointer Pointers are used often in Grammer as a means of accessing data. This has a few positive side effects as well as a few negative ones. In easy(ish) terms, all data is located in memory. The "location" is given as a number and on the calulator, this number is from 0 to 65535. A pointer, then, points to the data location. So where are pointers used in Grammer? Say, for example, you want to reference a string. In Grammer, you would do "HELLO→A. The location of the string "HELLO" is stored to A. Sprites A sprite is just an image. In Grammer, sprites are a multiple of 8 pixels wide up to 96 and up to 64 pixels tall. Strings Strings can be any form of data. They can be text, sprite data, label names, even code. Pointer Vars Pointer Vars are the letters A through Z and Ɵ as well as their primes. For example, S and S' are two different pointer vars. These are used to store pointers or values. Pointer vars are 16 bits, so only integers from 0 to 65535 are stored to them. Subject 1-Numbers In Grammer, values are integers from 0 to 65535. This is one of the key differences between Grammer and TI-BASIC. While this may make some things difficult, this has a few uses and effects not found in BASIC. So first thing up, what happens when you go beyond 65535? The numbers simply loop back to 0! So what happens when you go below 0? You loop back starting at 65535! This is called modular math, so if you understand this section, you will actually be understanding an important concept in number theory. The uses of this will come later... Subject 2-Math In Grammer, math does not follow Order Of Operations and has some limiting factors (like only working with 16-bit integers). However, there are exploits that can be useful for this. Anyway, math is done from right to left, so as an example, we will look at 3*4+6/4-2: 3*4+6/4-2 3*4+6/2 3*4+3 3*7 21 There are a bunch of math commands at your disposal, too, not just basic math. The tricks, however, come from Ɵ'. There are several operations that modify Ɵ' as a way to return additional information. For example, when adding, if the result exceeds 65535, 1 is stored to Ɵ', otherwise it becomes 0: +: If the result is greater than 65535, Ɵ' is 1, otherwise it is 0. -: If the result is less than 0, Ɵ' is 65535, otherwise it is 0. *: Ɵ' is the upper 16 bits allowing for a 32-bit result. /: Ɵ' is the remainder 2: Same as multiplication See the Math Functions section in the full tutorial for more info on other operations. If you wanted to do If 24=((A*7)+(B*12)), you would do this: :A*7 :+B*12 :If =24 However, if you want to keep it all on one line (because anything in an If or While statement does not modify Ans), you can use a space instead of a newline: :If A*7 +B*12 =24 Subject 3-Logic Logical operators are used to compare values. If the logic is true, the result is 1 and if it is false, the result is 0. As an example, 3>4 is false because 3 is not greater than 4, so this returns a 0. These are useful for conditional statements used in If , While , and Repeat . Subject 4-If Blocks If blocks are often used because they are fairly useful. For example, if you want to do something if a condition is true, you will usually want to use an If statement. For example, if you want to increment A if getKey is 9 (if [ENTER] is pressed): Code: [Select]
As in TI-BASIC, you can also use an If...Then...End statement to handle multiple lines of code. For example: Code: [Select]
Although usually you can get away with putting it all on one line like this to save a few bytes: Code: [Select]
Subject 5-Loops Most games or math algorithms will use loops and Grammer offers three loops that act the same way as in BASIC: Repeat This will repeat the code between Repeat...End until the statement is true. For example, to increment A until A=999: Code: [Select]
Note that this will execute the code first and then check the conditional. While This is a little different from Repeat in that it executes the code in the loop while the condition is true. If the condition is false before it enters the loop, the code inside never gets executed. So for example, to loop so long as A<999: Code: [Select]
For( This will increment a variable from a starting point to an ending point. For example, this will cycle starting with A=3, incrementing A by 1 every cycle until it reaches 9: Code: [Select]
Subject 6-Labels Labels are a neat feature in Grammer that are very much unlike BASIC. In BASIC, you start a label name with Lbl and it can be up to 2 chars long and must be numbers or letters (or a combination). In Grammer, labels start with a "." and can contain any character except a newline. There is also no size limit, but remember that a label of fifty chars will take longer to locate than one of 5 characters. Here is a label example: Code: [Select]
We use Lbl to get the location of the label which is used by Goto. This also lets you store data to a label and get a pointer to it. So as an example: Code: [Select]
|
|||
Rating: This article has not been rated yet. |
|||
|