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
 

Re: If a Table is empty? - Need help!

Previous Thread :: Next Thread 
MythsReaper is not online. MythsReaper
Joined: 06 Jul 2016
Total Posts: 97
01 Sep 2016 11:01 AM
Hi I'm MythsReaper. I'm scripting a very complicated game I've been working on for some time. The bit i'm working on at the moment is the random person who was selected winning. Basically, there is a table and when the round starts all the survivors are inserted into it. When they die, they're removed. Near the end of the script I've put the detection for the table being empty for the random player (badguy) winning. I can't figure it out to detect if the table is empty. Help?
Report Abuse
AggressiveCatch is not online. AggressiveCatch
Joined: 17 Jul 2011
Total Posts: 5840
01 Sep 2016 11:02 AM
if #table < 0.5 then
--table is empty
end
Report Abuse
MythsReaper is not online. MythsReaper
Joined: 06 Jul 2016
Total Posts: 97
01 Sep 2016 11:03 AM
Uhm, I don't get it...sorry, can you explain it fully?
Report Abuse
lampwnage121 is not online. lampwnage121
Joined: 20 Oct 2012
Total Posts: 4285
01 Sep 2016 11:06 AM
#Table returns the amount of objects in a table for numerical indexes(Table being a variable for the table)
Report Abuse
MythsReaper is not online. MythsReaper
Joined: 06 Jul 2016
Total Posts: 97
01 Sep 2016 11:07 AM
So how would I use it? (Fully please).

Also sorry I'm a little bad at understanding.
Report Abuse
lampwnage121 is not online. lampwnage121
Joined: 20 Oct 2012
Total Posts: 4285
01 Sep 2016 11:10 AM
Table = {"hi","u","ok","nvm"}

print(#Table)

if #Table == 0 then
print("Empty")
else
print("Not Empty")
end

>4
>Not Empty
Report Abuse
MythsReaper is not online. MythsReaper
Joined: 06 Jul 2016
Total Posts: 97
01 Sep 2016 11:10 AM
So, my guess is like this?


while true do
wait(0.1)
if #_G.survivortable > 1 then
info.Value = 'The GCP won!'
dundun:Stop()
wait(2)
break
end
Report Abuse
MythsReaper is not online. MythsReaper
Joined: 06 Jul 2016
Total Posts: 97
01 Sep 2016 11:19 AM
If it is, then thank you both so much!

I'll also try to remember you for when the game is in a playable state I can offer you to play it, if you want.
Report Abuse
MythsReaper is not online. MythsReaper
Joined: 06 Jul 2016
Total Posts: 97
01 Sep 2016 11:20 AM
Nevermind, didn't seem to work...
Report Abuse
lampwnage121 is not online. lampwnage121
Joined: 20 Oct 2012
Total Posts: 4285
01 Sep 2016 11:23 AM
How are you handling your tables?
Report Abuse
MythsReaper is not online. MythsReaper
Joined: 06 Jul 2016
Total Posts: 97
01 Sep 2016 11:26 AM
It's a global table. "_G.survivortable"
Report Abuse
lampwnage121 is not online. lampwnage121
Joined: 20 Oct 2012
Total Posts: 4285
01 Sep 2016 11:26 AM
I mean, what is in them? Are you using custom indexes and the like?
Report Abuse
MythsReaper is not online. MythsReaper
Joined: 06 Jul 2016
Total Posts: 97
01 Sep 2016 11:28 AM
I'm inserting there name (player.Name) into the table. They get removed when they die. (Humanoid.Died).
Report Abuse
MythsReaper is not online. MythsReaper
Joined: 06 Jul 2016
Total Posts: 97
01 Sep 2016 11:33 AM
This is the code.



while true do
wait(0.1)
if #_G.survivortable == 0 then
info.Value = 'The GCP won!'
dundun:Stop()
wait(2)
break
end
Report Abuse
MythsReaper is not online. MythsReaper
Joined: 06 Jul 2016
Total Posts: 97
01 Sep 2016 11:34 AM
Code of the removing when died.



local player = game.Players.LocalPlayer

player.Character:FindFirstChild('Humanoid').Died:connect(function()
if script.Parent.Parent.Survivor.Value == true then
print(player.Name..' Has Died!')
table.remove{_G.survivortable, player.Name}
wait(0.01)
end
end)
Report Abuse
lampwnage121 is not online. lampwnage121
Joined: 20 Oct 2012
Total Posts: 4285
01 Sep 2016 11:35 AM
The index refers to the location in the table the object is stored.

If you're not using numerical indexes the # operator will not work right.

See if this works.

count = 0
for i,v in pairs(Table) do
count = count + 1
end

print(count)
Report Abuse
MythsReaper is not online. MythsReaper
Joined: 06 Jul 2016
Total Posts: 97
01 Sep 2016 11:37 AM
Okay. But is there anyway of using anything but the "for" loop, it makes the code below the detection bad.

I'll try that though!
Report Abuse
lampwnage121 is not online. lampwnage121
Joined: 20 Oct 2012
Total Posts: 4285
01 Sep 2016 11:38 AM
That's not how you use table.remove.

It accepts a numerical index as the second argument and uses parenthesis to enclose them.
Report Abuse
MythsReaper is not online. MythsReaper
Joined: 06 Jul 2016
Total Posts: 97
01 Sep 2016 11:40 AM
Oh, so can you show how?
Report Abuse
lampwnage121 is not online. lampwnage121
Joined: 20 Oct 2012
Total Posts: 4285
01 Sep 2016 11:48 AM
The only way to remove the player from the table with indexes like that is to use figure out which one is them then remove it.

for i,v in pairs(Table)
if v = Player then
Table[i] = nil -- or table.remove(Table,i)
end
end
Report Abuse
MythsReaper is not online. MythsReaper
Joined: 06 Jul 2016
Total Posts: 97
01 Sep 2016 11:49 AM
I see. Hopefully this works. If not it will probably be the detection still.
Report Abuse
MythsReaper is not online. MythsReaper
Joined: 06 Jul 2016
Total Posts: 97
01 Sep 2016 11:51 AM
The "If" is underlined red and I cant seem to fix that?!
Report Abuse
MythsReaper is not online. MythsReaper
Joined: 06 Jul 2016
Total Posts: 97
01 Sep 2016 11:52 AM
Nevermind, fixed it, you missed out "do."
Report Abuse
lampwnage121 is not online. lampwnage121
Joined: 20 Oct 2012
Total Posts: 4285
01 Sep 2016 11:52 AM
for i,v in pairs(Table) do


Forgot the 'do' probably should sleep soon...
Report Abuse
MythsReaper is not online. MythsReaper
Joined: 06 Jul 2016
Total Posts: 97
01 Sep 2016 11:54 AM
Don't go yet, please..

If this doesn't work and you go i'll be lost and I need to get this finished today.

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