|
| 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 |
|
|
|
| 01 Sep 2016 11:02 AM |
if #table < 0.5 then --table is empty end |
|
|
| Report Abuse |
|
|
|
| 01 Sep 2016 11:03 AM |
| Uhm, I don't get it...sorry, can you explain it fully? |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 01 Sep 2016 11:20 AM |
| Nevermind, didn't seem to work... |
|
|
| Report Abuse |
|
|
|
| 01 Sep 2016 11:23 AM |
| How are you handling your tables? |
|
|
| Report Abuse |
|
|
|
| 01 Sep 2016 11:26 AM |
| It's a global table. "_G.survivortable" |
|
|
| Report Abuse |
|
|
|
| 01 Sep 2016 11:26 AM |
| I mean, what is in them? Are you using custom indexes and the like? |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
| |
|
|
| 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 |
|
|
|
| 01 Sep 2016 11:49 AM |
| I see. Hopefully this works. If not it will probably be the detection still. |
|
|
| Report Abuse |
|
|
|
| 01 Sep 2016 11:51 AM |
| The "If" is underlined red and I cant seem to fix that?! |
|
|
| Report Abuse |
|
|
|
| 01 Sep 2016 11:52 AM |
| Nevermind, fixed it, you missed out "do." |
|
|
| Report Abuse |
|
|
|
| 01 Sep 2016 11:52 AM |
for i,v in pairs(Table) do
Forgot the 'do' probably should sleep soon... |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|