Computer Science Canada Basics of Turing (very basic) |
Author: | kevin314 [ Thu May 21, 2009 6:22 pm ] |
Post subject: | Basics of Turing (very basic) |
This is my first tutorial, suggest improvements if you see fit. Ok, lets start by telling the computer to show us a sentence in the run window by simple putting: put "This is N.A." Then press F1 to run your program. The put command is what you use to have text or number's appear in the run window and the text inside the quotations is what will appear in the run window. In Turing main commands show up in black and with bold lettering. Other commands just show up as normal black text. Anything that you put inside quotation marks shows up in red to show that they will appear on screen and comments show up in green. What if I want the text to appear in a different spot on the screen?, you may ask. Well then we use another command called locate: locate (5,12) put "This is N.A." Now press F1 to see the results of this command. The locate (Row,Column) is used with the put command and allows you to place the text at the row and column that you want, But you are limited to about 25 to 30 rows and 80 or less column's. So if you want your text location to be even more precise then you can also use this command: locatexy (300, 250) put "This is N.A." The locatexy (x,y) command lets you have the freedom of putting your text anywhere you like on the run screen giving you alot more precision when placing your text because your only limit then is whether or not you can see the text on the screen. The way you tell where your putting the text with this command is by knowing that the x location is the horizontal location, the left side of the screen being 0, and the y location is the vertical location, the bottom of the screen being 0. Ok, so now let me tell you about comments, they are very useful, so that you can keep track of what parts of your scripts do what. To put a comment in you script you have to do one of two things. 1. Use the percent sign: % This is a comment You use this command if you are only going to have one line for your comment. or 2. Use the backslash and then a star : /* This is also a comment command*/ This command is used when your comment takes up more than one line. But don't forget to use a star and then the backslash at the end of your comment to stop the comment. This command is also very useful if you are trying to fix bugs in a program because Turing ignores anything that is considered a comment (Anything that is written in green text). So don't forget to use comments they are very useful. Back to business, In almost every program you need variables. A variable is an element of the program that can be constant, or it can depend on the person that is running the program. Variables that are constant never change (Font type, maximum health,etc.). Variables that depend on the program's user change depending on what the user does (current health, score, Time, etc.). Oh I forgot to mention this before but anything that you declare or that isn't recognized by Turing shows up in blue text. Any way's, you declare a variable by simply putting: % This is my Variables Example!! var N.A. := 0 This example shows you that N.A. was declared as a variable and it is currently set as 0. You can set your variable up as other things as well, such as words, and letters. You can declare many different types of variables. The example above is a type boolean variable, but we'll get in to boolean variables later. The Examples of the other types of variables you could declare N.A. as are: % More Examples var N.A. :int var N.A. :real var N.A. :string var N.A. :boolean You declare a variable as int only if what your declaring is a number without a decimal. eg: 5. You declare a variable as real only if what your declaring is a number that does have a decimal. eg: 5.6. You declare a variable as a string only if what your declaring is a word or letter. eg. Hello, w,. You declare a variable as boolean only if what your declaring should be true or false. eg. check for boolean tutorial. Thats all for now but keep checking I should have another one up soon, or check my website. (its in my profile) |