User:ENET/StepByStep/Variables

From Legacy Roblox Wiki
Revision as of 02:47, 2 February 2012 by >ENET (Created page with "<center><h3><u>Variables</u></h3></center> <b>Description</b>: <i>A variable is a value stored into a identity.</i> <b>Example</b>: <i>Pi(as in the math term) is a variable. ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Variables

Description: A variable is a value stored into a identity.

Example: Pi(as in the math term) is a variable. Pi is actually 3.14(rounded to the hundredths place). Why do we use Pi to describe this value? Because it is a commonly used value and is easier to refer to as Pi rather than saying 3.14

Lets get more in-depth about variables, and there basic layout.

First of all, let me tell you about an operator that you probably(definately) have seen before. That operator is the '=' sign. Which in english translates to equals. We use them in math all the time, but what in coding do they mean? Well if you're in algebra you probably have seen equations such as y = mx+b or x=4. That is pretty much the same layout in scripting!

The layout for declaring a variable is Index = Value. Where (Index) is the name and value is the value.

Rules Of Variable Names 1. The name can't INCLUDE with special characters(%,$,#) with the exception of the '_' sign. 2. The name can't START with numbers. 3. The name can't INCLUDE spaces.

Pascal Case Pascal Case is a style of naming variables. Basically, it says to start the variable with a CAPITAL letter, and any word in the variable should be capitalized. Examples: Dog, MyDogIsACat, IHaveAPet. This is not a required way of naming variables, it is just something do to keep there code similar throughout.

Camel Case This case is rather similar to Pascal Case with one exception. The first word is lowercased. Examples: dog, myDogIsACat, iHaveAPet.

Note: How you label your variables doesn't matter as long as they follow the rules. You can label a variable as x1mBdA_sUb1. However, that is really ugly and may make it hard for you to remember your own variable.

Tips 1. When naming a variable be descriptive, but don't be too descriptive. Make the variable so you can remember what its for, but don't give it a name longer than 10 letters.

Types Of Variables The below content is not important yet! Don't worry about understanding it, unless you want to take the time to learn these three types just for keep sakes. They will be important later.

Local: These variables are only available to the current block they are in, or any block within that block.

Global: These variables are available to any block in your script.

Shared: These variables are available to any script.