A Roblox Community
You must log in to view most of the sites content. If you do not already have an account click Register below...

A Roblox Community

A community of Robloxians who want to learn to script and build on Roblox Studio.
 
HomePortalFAQRegisterLog in
If you're a experienced coder make some tutorials! It would really help the site grow.
Make sure you read the rules(Which can be found by clicking here)
If you're a beginner at coding, try some tutorials.
We have many Moderators/Admins watching this site. Contact them with Questions.
Let us know what your favorite sport is. By clicking here to vote (Click here)
This site is becoming inactive. Lets make it active.
Log in
Username:
Password:
Log on automatically: 
:: I forgot my password
Top posters
blueymaddog
 
naknak
 
Supernapalm
 
slayer9365
 
myrco919
 
m27frogy
 
ninga95
 
CloneTrooper787
 
raboy117
 
trappingnoobs
 
Top posting users this month
m27frogy
 
myrco919
 
blueymaddog
 
ninga95
 
naknak
 
Latest topics
» Keylogging/getting the mouse unnoticed
May 16th 2012, 8:43 pm by naknak

» Nederlands
May 16th 2012, 11:52 am by m27frogy

» みなさん、こんにちは!
May 16th 2012, 10:32 am by myrco919

» Try out the panel!
May 16th 2012, 10:30 am by myrco919

» The Local Script: A Robloxian's Worst Nightmare
May 16th 2012, 10:26 am by myrco919

» You're lost.
May 14th 2012, 4:36 am by m27frogy

» Good news, well sorta!
May 9th 2012, 8:29 pm by ninga95

» AIR, Artificial Intelligence Revised
May 5th 2012, 6:35 am by m27frogy

» local script help:
April 7th 2012, 8:22 am by Lukasm

» How to loop regen creations.
April 7th 2012, 6:34 am by MrNicNac

» Refering to functions as objects?
March 28th 2012, 8:29 am by Sethalonian

» Help new people find their way around the website
March 22nd 2012, 11:43 pm by blueymaddog

» I wanna see if anyone can
March 19th 2012, 1:46 am by blueymaddog

» Dispute Rules
March 14th 2012, 1:22 am by blueymaddog

» Explaining the Basics of a Script with Example
March 11th 2012, 6:37 pm by blueymaddog

» Java or C?
March 10th 2012, 8:48 pm by blueymaddog

» Talk about your favourite hobbies!
March 10th 2012, 8:45 pm by blueymaddog

» Metatables Tutorial
March 10th 2012, 8:43 pm by blueymaddog

» Rules of this forum. Please read!
March 9th 2012, 1:35 pm by blueymaddog

» Epic Ice King Staff
March 9th 2012, 1:34 pm by blueymaddog


Share | 
 

 Variables

View previous topic View next topic Go down 
AuthorMessage
Prodigy
Administrator
Administrator


Posts: 58
Join date: 2010-07-28

PostSubject: Variables   August 2nd 2010, 5:15 pm

Variables and functions are used to help you shorten your code and create easy shortcuts to executing scripts.

Variables: A variable is a name, given by a programmer, to represent a piece of data. This name is then used to refer to that piece of data at any time in the script.

Example
Bob wants to change the color of a brick multiple times. His code is as follows.
Code:
game.Workspace.Bluebrick.BrickColor = BrickColor.new("Cyan")
wait(5)
game.Workspace.Bluebrick.BrickColor = BrickColor.new("Really Red")
wait(5)
game.Workspace.Bluebrick.BrickColor = BrickColor.new("Black")
wait(5)
game.Workspace.Bluebrick.BrickColor = BrickColor.new("White")

Bob is tired of writing "game.Workspace.Bluebrick.BrickColor" over and over. He wants a way to shorten the code.

Bob could assign a variable to "game.Workspace.Bluebrick.BrickColor" so that he doesn't need to write that part of the code again and again.

Bob's code shortened by a variable would look like the following
Code:

Myfirstvar = game.Workspace.Bluebrick
Myfirstvar.BrickColor = BrickColor.new("Cyan")
wait(5)
Myfirstvar.BrickColor = BrickColor.new("Really Red")
wait(5)
Myfirstvar.BrickColor = BrickColor.new("Black")
wait(5)
Myfirstvar.BrickColor = BrickColor.new("White")


The "Myfirstvar = game.Workspace.Bluebrick" part of the code sets the variable. The Variables are CASE SENSATIVE, meaning, if your variable was "Hello" you could not write "hello" or "HELLO".
Back to top Go down
http://roblox.youneed.us
Filthynate
Intermediate Scripter
Intermediate Scripter


Posts: 11
Join date: 2010-08-02

PostSubject: Re: Variables   August 2nd 2010, 5:28 pm

So yuo can also make it x = game.Workspace.Bluebrick...right?
Back to top Go down
Prodigy
Administrator
Administrator


Posts: 58
Join date: 2010-07-28

PostSubject: Re: Variables   August 2nd 2010, 5:32 pm

Filthynate wrote:
So yuo can also make it x = game.Workspace.Bluebrick...right?

Yes. You can put anything you want there.
Back to top Go down
http://roblox.youneed.us
Filthynate
Intermediate Scripter
Intermediate Scripter


Posts: 11
Join date: 2010-08-02

PostSubject: Re: Variables   August 2nd 2010, 5:44 pm

ok cool
Back to top Go down
slayer9365
Administrator
Administrator


Posts: 233
Join date: 2010-07-31
Age: 17

PostSubject: Re: Variables   August 3rd 2010, 11:23 am

Please note that if you save a Value, when reading the Value, it will come up with the original value that was there when you created the variable.
Back to top Go down
Bobbyfishstick5
Administrator
Administrator


Posts: 15
Join date: 2010-07-30
Age: 16

PostSubject: Re: Variables   August 3rd 2010, 11:45 am

You can set mutiple variables in a single line also. Like this

local (a, b, c = c, b a)
print(a, b, c)
Back to top Go down
Prodigy
Administrator
Administrator


Posts: 58
Join date: 2010-07-28

PostSubject: Re: Variables   August 3rd 2010, 2:59 pm

Bobbyfishstick5 wrote:
You can set mutiple variables in a single line also. Like this

local (a, b, c = c, b a)
print(a, b, c)

That's more advanced though. This is just a beginner tutorial.
Back to top Go down
http://roblox.youneed.us
blueymaddog
Administrator
Administrator


Posts: 1108
Join date: 2010-12-09
Age: 13

PostSubject: Re: Variables   January 18th 2011, 4:20 am

Nice, simple tutorial! Good job.

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
Back to top Go down
 

Variables

View previous topic View next topic Back to top 
Page 1 of 1

 Similar topics

-
» [HELP] DCRS, External Variables, External Texts [HELP]
» Forumotion Variables
» A Guide To Variables
» Roblox Tutorial - Integer Variables (Local and Global)
» Tutorial de Variables

Permissions in this forum:You cannot reply to topics in this forum
A Roblox Community :: Tutorials and Resources :: Scripting Tutorials :: Beginner-