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 » Scripting Helpers
Home Search
 

Re: Looping function on accident?

Previous Thread :: Next Thread 
brickbuilder74 is not online. brickbuilder74
Joined: 23 Jun 2008
Total Posts: 8810
08 Feb 2012 06:28 PM
This function loops for some reason and I don't know why?

function waitStart()
players = game.Players:GetPlayers()
curPly = {}
for _,v in pairs (players) do
if (v.AFK.Value == false) then
table.insert(curPly,v)
else
for i = #players, 1, -1 do -- I think it's because of this line
table.remove(players,i)
end
v.PlayerGui.Main.Extras.AFKText.Visible = true
end
pcall(function()
v.PlayerGui.Main.Alert.AT.Text = "Starting new game"
v.PlayerGui.Main.Alert.AT2.Text = "Starting new game"
end)
end
wait(2)
if #players >= 3 then
chooseA()
else
script.Disabled = true
end
end
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
08 Feb 2012 06:30 PM
for _,v in pairs (players) do
for i = #players, 1, -1 do -- I think it's because of this line

Are both loops.

† KMXD †
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
08 Feb 2012 06:31 PM
 1. (v.AFK.Value == false) Take a look at ( http://wiki.roblox.com/index.php/Bool ) because that's poor coding practice.

 2. Check for if `waitStart()` is called inside `chooseA()`
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
08 Feb 2012 06:33 PM
@SD

So just "if v.AFK.Value not false"

?

† KMXD †
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
08 Feb 2012 06:35 PM
if not v.AFK.Value then
Report Abuse
brickbuilder74 is not online. brickbuilder74
Joined: 23 Jun 2008
Total Posts: 8810
08 Feb 2012 06:37 PM
@SDuke - It doesn't really matter. They both work fine. I just need to know how to re-arrange this function so it works? I know what the problem is now... it's because I have a loop inside a loop, but I don't know how to fix that.
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
08 Feb 2012 06:37 PM
Oh, I didn't know not applied to booleans too. :S

And is == true acceptable?

† KMXD †
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
08 Feb 2012 06:38 PM
Erm,

function waitStart()
players = game.Players:GetPlayers()
curPly = {}
for _,v in pairs (players) do
if (not v.AFK.Value) then
table.insert(curPly,v)
end
else
for i = #players, 1, -1 do -- I think it's because of this line
table.remove(players,i)
end
v.PlayerGui.Main.Extras.AFKText.Visible = true
end
pcall(function()
v.PlayerGui.Main.Alert.AT.Text = "Starting new game"
v.PlayerGui.Main.Alert.AT2.Text = "Starting new game"
end)
end
wait(2)
if #players ​>= 3 then
chooseA()
else
script.Disabled = true
end

???

† KMXD †
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
08 Feb 2012 06:39 PM
Just get rid of the second one completely. You don't need it.
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
08 Feb 2012 06:41 PM
@knight

booleans are all that `not` works for. Just like it says on the page,

> In Lua, when something is converted to a boolean, if the value is false or nil then it will be false, otherwise it is true.

When you say

    not workspace.Part

That's turning it into a boolean.
Report Abuse
brickbuilder74 is not online. brickbuilder74
Joined: 23 Jun 2008
Total Posts: 8810
08 Feb 2012 06:41 PM
@SDuke - Uhhh, yeah I do? You don't know that the player needs to be removed from the table if he/she is in AFK mode. If they're not removed from the table, the whole script doesn't work.
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
08 Feb 2012 06:42 PM
@brick
You're inserting them into the `curPly` so just use that table.
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
08 Feb 2012 06:42 PM
@SD

I see. So again, is == true acceptable?

† KMXD †
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
08 Feb 2012 06:44 PM
    local bool=true;
    
    if bool then
        print("No ==true isn't good practice either.");
    end

Output :
> No ==true isn't good practice either.
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
08 Feb 2012 07:01 PM
What if you already have a bool value that is true, outside the script, already defined?

Would you still do if stuff.Value then?

† KMXD †
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
08 Feb 2012 07:04 PM
of course, Value will be equivalent of true so it's the same exact thing.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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