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
 

functions inside of a for loop

Previous Thread :: Next Thread 
LuaAtrocities is not online. LuaAtrocities
Joined: 15 Jan 2012
Total Posts: 617
22 Mar 2017 10:59 PM
so previously in the past I've done things where say I want all textbuttons under "swag" to run the same command and i'll write something like

for _,v in pairs(game.StarterGui.swag:getChildren()) do
v.MouseButton1Click:connect(function()
print'yolo'
end)
end

and this would work fine, but I'm working on a chess engine now, and I want the person to be able to play. so what I've done is made a function that analyzes the 2 buttons you click (it records the first one), however the input saying unexpected symbol near ')' on my end) line. here's my script.

for _,v in pairs(script.Parent.Sur:GetChildren()) do
v.MouseButton1Click:connect(function()
if script.ChosenPiece.Value == 'NA' and v.Text ~= '' and getside(v) == 2 and script.Parent.WTM.Value == true then
script.ChosePiece.Value = v.Name
local opts = options(v)
for _,c in pairs(opts) do
local cl = script.Copy:Clone()
cl.Parent = c
end
elseif script.ChosenPiece.Value ~= 'NA' and script.Parent.WTM.Value == true then
local opts = options(script.Parent.Sur[script.ChosenPiece.Value])
local legal = false
for _,c in pairs(opts) do
if v == c then
legal = true
end
end
if legal == true then
v.Text = script.Parent.Sur[script.ChosenPiece.Value].Text
v.TextColor3 = script.Parent.Sur[script.ChosenPiece.Value].TextColor3
script.Parent.WTM.Value = false
script.ChosePiece.Value = 'NA'
for _,d in pairs(script.Parent.Sur:GetChildren()) do
if d['Copy'] then d['Copy']:remove() end
end
moverandom()
else
print'this move is not legal'
script.ChosenPiece.Value = 'NA'
for _,d in pairs(script.Parent.Sur:GetChildren()) do
if d['Copy'] then d['Copy']:remove()
end
end
end
end) -- output's saying the problem is on this line.
end

I cannot find the issue
Report Abuse
LaeMVP is online. LaeMVP
Joined: 24 Jun 2013
Total Posts: 4416
22 Mar 2017 11:00 PM
Keep printing till you find what breaks.
Report Abuse
Dorandir is not online. Dorandir
Joined: 06 Aug 2016
Total Posts: 844
22 Mar 2017 11:01 PM
^
Report Abuse
LuaAtrocities is not online. LuaAtrocities
Joined: 15 Jan 2012
Total Posts: 617
22 Mar 2017 11:02 PM
the first line doesn't execute.
Report Abuse
iJacobness is not online. iJacobness
Joined: 20 Jan 2014
Total Posts: 4944
22 Mar 2017 11:02 PM
dont do what lae said

for _,v in pairs(script.Parent.Sur:GetChildren()) do
v.MouseButton1Click:connect(function()
if script.ChosenPiece.Value == 'NA' and v.Text ~= '' and getside(v) == 2 and script.Parent.WTM.Value == true then
script.ChosePiece.Value = v.Name
local opts = options(v)
for _,c in pairs(opts) do
local cl = script.Copy:Clone()
cl.Parent = c
end
elseif script.ChosenPiece.Value ~= 'NA' and script.Parent.WTM.Value == true then
local opts = options(script.Parent.Sur[script.ChosenPiece.Value])
local legal = false
for _,c in pairs(opts) do
if v == c then
legal = true
end
end
if legal == true then
v.Text = script.Parent.Sur[script.ChosenPiece.Value].Text
v.TextColor3 = script.Parent.Sur[script.ChosenPiece.Value].TextColor3
script.Parent.WTM.Value = false
script.ChosePiece.Value = 'NA'
for _,d in pairs(script.Parent.Sur:GetChildren()) do
if d['Copy'] then d['Copy']:remove() end
end
moverandom()
else
print'this move is not legal'
script.ChosenPiece.Value = 'NA'
for _,d in pairs(script.Parent.Sur:GetChildren()) do
if d['Copy'] then d['Copy']:remove()
end
end
end
end
end)
end


Report Abuse
LaeMVP is online. LaeMVP
Joined: 24 Jun 2013
Total Posts: 4416
22 Mar 2017 11:04 PM
@iJacob Printing till you find an error works 99% of the time, so why not do it?
Report Abuse
LuaAtrocities is not online. LuaAtrocities
Joined: 15 Jan 2012
Total Posts: 617
22 Mar 2017 11:05 PM
thank you <3
Report Abuse
iJacobness is not online. iJacobness
Joined: 20 Jan 2014
Total Posts: 4944
22 Mar 2017 11:05 PM
because with the error that was given it wouldnt have even helped, like he said the error printed right away.


Report Abuse
LaeMVP is online. LaeMVP
Joined: 24 Jun 2013
Total Posts: 4416
22 Mar 2017 11:06 PM
ah then we have hit the 1%
Report Abuse
iJacobness is not online. iJacobness
Joined: 20 Jan 2014
Total Posts: 4944
22 Mar 2017 11:07 PM
lol.


Report Abuse
iJacobness is not online. iJacobness
Joined: 20 Jan 2014
Total Posts: 4944
22 Mar 2017 11:08 PM
it does help when your not getting any underlines though.


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