generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

do

Previous Thread :: Next Thread 
4xw is not online. 4xw
Joined: 01 Dec 2013
Total Posts: 21
21 Jul 2014 09:09 PM
i have seen people use in their scripts
do
--something
end
what does "do" do? isnt it the same as not declaring "do" in the first place?
Report Abuse
Xephyric is not online. Xephyric
Joined: 26 Mar 2009
Total Posts: 2270
21 Jul 2014 09:11 PM
while blah do

for blah do

Do can not be used by itself. It is used for some loops.
Report Abuse
nomer888 is not online. nomer888
Joined: 13 Feb 2010
Total Posts: 551
21 Jul 2014 09:12 PM
"do" can be used to create enclosures for local variables that you may want to protect from the global scope.

do
local var = 5
function getvar()
return var
end
end

print(getvar()) -> 5
print(var) -> nil
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
21 Jul 2014 09:12 PM
@X

although kinda pointless, do can be used by itself, as a scope
Report Abuse
Xephyric is not online. Xephyric
Joined: 26 Mar 2009
Total Posts: 2270
21 Jul 2014 09:13 PM
Oh, really!
Never seen that. Learned something today xD
Report Abuse
4xw is not online. 4xw
Joined: 01 Dec 2013
Total Posts: 21
21 Jul 2014 09:14 PM
thank you everyone for your help
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
21 Jul 2014 09:14 PM
Creating a scope using do can be incredibly useful in controlling variables.
Report Abuse
Casualist is not online. Casualist
Joined: 26 Jun 2014
Total Posts: 4443
21 Jul 2014 09:18 PM
The difference is that
do

-- something
end

Creates a new scope/block. This can be useful for creating local variables that aren't stored in the main scope.

An example would be using temporary values to calculate something but will never use again. Instead of having to nil these values after they are done being useful you can let the language deal with freeing up memory when the block ends.

(function(...)
--something
end)(args)

Does something similar, but you can pass arguments to your new scope/block.
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
21 Jul 2014 09:19 PM
Maybe not the best use but I sometimes use it to group things together, so I can click the arrow thing to collapses it to get it out of my way, I usually remove them when the script is finished though
Report Abuse
HuntHello is not online. HuntHello
Joined: 19 Jan 2011
Total Posts: 577
21 Jul 2014 09:21 PM
@128 just don't declare local variables in it if it will be treated as a global one in "do".
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
21 Jul 2014 09:38 PM
@Hunt
I made variables local whenever they can be
I just comment out the do's before testing then take them out completely when the script is dkne
Report Abuse
HuntHello is not online. HuntHello
Joined: 19 Jan 2011
Total Posts: 577
21 Jul 2014 09:39 PM
i see
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image