A Roblox Community

A community of Robloxians who want to learn to script and build on Roblox Studio.
 
HomeFAQRegisterLog 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 in automatically: 
:: I forgot my password
Top posters
blueymaddog
 
naknak
 
Supernapalm
 
m27frogy
 
slayer9365
 
myrco919
 
branefreez
 
ninga95
 
CloneTrooper787
 
raboy117
 
Top posting users this month
Latest topics
» Send me an Email
January 8th 2016, 10:14 am by naknak

» [v1.6.0.0] Lua Script Obfuscator [No Bytecode]
July 6th 2015, 7:38 pm by m27frogy

» New Site Possibly
July 6th 2015, 4:16 pm by m27frogy

» Ambassador!
April 15th 2015, 11:40 pm by naknak

» Boop - Tag
April 13th 2015, 9:46 pm by naknak

» Vip Class Script
April 13th 2015, 4:54 pm by naknak

» Who's active?!
April 13th 2015, 4:52 pm by naknak

» Where to go from here.
April 13th 2015, 4:51 pm by naknak

» Genesis Point
July 17th 2014, 7:04 pm by branefreez

» Reward System
July 17th 2014, 5:41 am by m27frogy

» Script Request
July 10th 2014, 11:43 am by naknak

» local scripts?
July 10th 2014, 11:39 am by naknak

» Project: Reconstruction [Died]
July 10th 2014, 11:36 am by naknak

» Hi. I am new here
April 26th 2014, 4:01 pm by altshiftkey

» What's your favorite sport?
January 1st 2014, 2:13 pm by m27frogy

» FlashLight Script
January 1st 2014, 2:11 pm by m27frogy

» Gun Making! [READ DESC]
January 1st 2014, 2:10 pm by m27frogy

» Hi, I am new here!
November 26th 2013, 3:33 pm by Keanu73

» Improve Coding
October 26th 2013, 1:12 pm by pook03

» Simple Button
September 1st 2013, 6:19 pm by branefreez


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, 8: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
Guest
Guest



PostSubject: Re: Variables   August 2nd 2010, 8: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, 8: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
Guest
Guest



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

ok cool
Back to top Go down
slayer9365
Expert Scripter
Expert Scripter
avatar

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

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

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
Expert Scripter
Expert Scripter
avatar

Posts : 13
Join date : 2010-07-30
Age : 21

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

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, 5: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
avatar

Posts : 1081
Join date : 2010-12-09
Age : 18

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

Nice, simple tutorial! Good job.

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




PostSubject: Re: Variables   

Back to top Go down
 
Variables
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» How Auto-Evo Will Work
» BBCode Forum Variables

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