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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|