|
| 20 Jan 2016 08:53 PM |
I'm looking at a tycoon script, and the first part states:
for i, v in pairs(main.Body:GetChildren()) do if string.sub(v.Name, 1, 6) ~= "Button" then if v:findFirstChild("Number") then table.insert(objects, v) v.Parent = nil end I've been trying to learn scripting in Studio but I can never understand what things like "for i, v in pairs()" does or "string.sub()"
If anyone could help me out with figuring this out, I would greatly appreciate it :)
|
|
|
| Report Abuse |
|
|
| |
|
|
| 20 Jan 2016 09:18 PM |
the for in pairs loop is a loop that looks though a table. Table = main.Body:GetChildren() -- GetChildren returns a table of all the children of body for index,object in pairs(Table) do print(object.Name) end
string.sub basically takes a section of a string (a string is "hello world") and returns what it is for example startingCharacter = 1 endingCharacter = 5 print(string.sub("Hello World",startingCharacter,endingCharacter)) -- Hello
startingCharacter = 7 endingCharacter = 11 print(string.sub("Hello World",startingCharacter,endingCharacter)) -- World
what he was doing was checking if the first 6 characters were "Button" and if so it would check if it had a numbervalue in it and if so it will add the button to a table for later use
|
|
|
| Report Abuse |
|
|
|
| 20 Jan 2016 09:22 PM |
How do you know when to use something like this? I don't think I will ever understand the in-depth statements haha.
|
|
|
| Report Abuse |
|
|