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 » Scripters
Home Search
 

Re: Purpose of "do [code] end"

Previous Thread :: Next Thread 
BogyMac is not online. BogyMac
Joined: 04 Nov 2011
Total Posts: 823
10 Apr 2016 05:15 PM
I've seen here and there scripts that put code between "do end". What is the significance of this?
Report Abuse
Revisional is not online. Revisional
Joined: 02 Aug 2014
Total Posts: 318
10 Apr 2016 05:17 PM
There is a reason for this.

An example would be "while (condition) do (code) wait (number) end"

This is to perform a specific task a number of times while a condition is met.
Report Abuse
DeaIWithMeDarIing is not online. DeaIWithMeDarIing
Joined: 05 Apr 2016
Total Posts: 29
10 Apr 2016 05:19 PM
Would you mind posting an example of where you have seen this.

If you simply mean

do
[code]
end

then I have no idea why.
Report Abuse
BogyMac is not online. BogyMac
Joined: 04 Nov 2011
Total Posts: 823
10 Apr 2016 05:21 PM
Revisional, I know what all the different loops do and what they are for, I use them all the time. However, it seems to be possible to instead go "do script.Parent.Parent = workspace end"

I'm interested to know the different between something like that or just omitting the "do end" altogether.
Report Abuse
RoflBread is not online. RoflBread
Joined: 18 Jun 2009
Total Posts: 3803
10 Apr 2016 05:22 PM
You can make closures (I think that's the word?) with them, and make private variables, sorta. I'm no expert.

You can 'add' to the Vector3 library for instance by making it so the old table is only accessible by the new one

do
local oldVector3 = Vector3
Vector3 = setmetatable({},{__index=oldVector3})
function Vector3.memes()
print("lmao xd haha")
end
end

print(Vector3.new())
print(Vector3.memes())
Report Abuse
DeaIWithMeDarIing is not online. DeaIWithMeDarIing
Joined: 05 Apr 2016
Total Posts: 29
10 Apr 2016 05:22 PM
Well adding do and end in that example makes no difference at all as far as I am concerned, aside from additional lines of code.
Report Abuse
BogyMac is not online. BogyMac
Joined: 04 Nov 2011
Total Posts: 823
10 Apr 2016 05:23 PM
I figured the same thing, I just wanted to make sure. The question now is, why does it even exist in the first place?
Report Abuse
RoflBread is not online. RoflBread
Joined: 18 Jun 2009
Total Posts: 3803
10 Apr 2016 05:29 PM
It is useful, but yeah you would barely use it. You use it for separating variables from the rest of your script, essentially.
Report Abuse
RoflBread is not online. RoflBread
Joined: 18 Jun 2009
Total Posts: 3803
10 Apr 2016 05:30 PM
That is, the 'do end' creates its own area for local variables. A scope, or whatever.
Report Abuse
DeaIWithMeDarIing is not online. DeaIWithMeDarIing
Joined: 05 Apr 2016
Total Posts: 29
10 Apr 2016 05:32 PM
I am unsure if this is what you mean.

do
local a = true
local b = false
end
--script

but if so, it is exactly the same as

local a = true
local b = false
--script
Report Abuse
VerifiedName is not online. VerifiedName
Joined: 26 Jul 2009
Total Posts: 4534
10 Apr 2016 05:35 PM
do
local a = "hello"
end

print(a)

>>nil



do end does create its own scope, other than this i cant see any other reason to use it.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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