| |
|
IoIiderp
|
  |
| Joined: 05 Feb 2012 |
| Total Posts: 8613 |
|
|
| 01 Aug 2015 11:21 AM |
Its a block. You can use local variables in there. |
|
|
| Report Abuse |
|
|
|
| 01 Aug 2015 11:22 AM |
A do end is like creating a new scope. If you want to do something in a difference scope, but don't need the statements let's say, use do end.
local x = 10;
do x = 100 print(x) end
print(x)
> 100 > 10
Enjoying your stay at the Scripters Forum? Join this! http://www.roblox.com/My/Groups.aspx?gid=2582784 |
|
|
| Report Abuse |
|
|
|
| 01 Aug 2015 11:24 AM |
do local iSpecializinq = "noob" end
print(iSpecializinq)
>> nil
?? |
|
|
| Report Abuse |
|
|
IoIiderp
|
  |
| Joined: 05 Feb 2012 |
| Total Posts: 8613 |
|
|
| 01 Aug 2015 11:26 AM |
@power You didn't declare it was local? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 01 Aug 2015 11:46 AM |
| iSpec it printed nil because local variables only exist in the block they were created in. |
|
|
| Report Abuse |
|
|
|
| 01 Aug 2015 11:48 AM |
@cnt
I know that, i was confirming 'do' acted as a block. |
|
|
| Report Abuse |
|
|
|
| 01 Aug 2015 11:53 AM |
| I use it so that I can collapse large portions of code so that I don't have to look at it. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 01 Aug 2015 11:55 AM |
Same, also when I want to wrap something and it needs access to the old one, ie:
do local _table = table; table = setmetatable({}, {__index = _table;}); table.clear = function(tbl) for key in next, tbl do tbl[key] = nil; end end |
|
|
| Report Abuse |
|
|