AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 05 Jun 2015 01:48 PM |
I'm having a bit of a problem, don't know why it's doing this.
-- game inserts Player names into this table local Players = {Player1} for i,Player in pairs (game.Players:GetPlayers()) do if Players[Player.Name] then -- Does not go past this point
end end
I printed both the table and Player.Name, they both print Player1. Why doesn't it go past the if statement? |
|
|
| Report Abuse |
|
|
amanda
|
  |
| Joined: 21 Nov 2006 |
| Total Posts: 5925 |
|
|
| 05 Jun 2015 01:50 PM |
Table[index]
not
Table[value] |
|
|
| Report Abuse |
|
|
Qivr
|
  |
| Joined: 22 Aug 2014 |
| Total Posts: 5407 |
|
|
| 05 Jun 2015 01:50 PM |
local Players = {Player1}
>>>
local Players = {"Player1"} |
|
|
| Report Abuse |
|
|
MrNicNac
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 26567 |
|
|
| 05 Jun 2015 01:52 PM |
Because that key doesn't exists. You are storing the player names as values, apparently. You need to store them as keys to do that:
local Players = {['Player1'] = true};
if Players['Player1'] then -- works end
Or make a function to search the table for the value.
function Search(Table, Value) for i,v in pairs(Table) do if v == Value then return true end end end
if Search(Players, Player.Name) then |
|
|
| Report Abuse |
|
|
amanda
|
  |
| Joined: 21 Nov 2006 |
| Total Posts: 5925 |
|
| |
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 05 Jun 2015 01:53 PM |
local Players = {"Player1","Player"} wait(2) for i,v in pairs (Players) do for i,x in pairs(game.Players:GetChildren()) do if x.Name == v then print("hello player") end end end |
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 05 Jun 2015 05:32 PM |
Is there a way to save the players as strings?
for i,v in pairs (Game.Players:GetChildren()) do table.insert(Players, Player.Name) --stringify! end |
|
|
| Report Abuse |
|
|
amanda
|
  |
| Joined: 21 Nov 2006 |
| Total Posts: 5925 |
|
| |
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 05 Jun 2015 06:19 PM |
I already had it like that with Player.Name, so it should be string
Forgot to mention that |
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 05 Jun 2015 07:12 PM |
So the real table is probably
local Players = {"Player1"} if Players[Player.Name] then
They should be the exact same |
|
|
| Report Abuse |
|
|
|
| 05 Jun 2015 07:15 PM |
as an appropriate answer to the title,
rawget(tab,i) |
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 06 Jun 2015 07:34 AM |
I was just trying to do
Table["String"] because that works too |
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 06 Jun 2015 07:43 AM |
-- Sets all players to table table.insert(Players, Player.Name)
-- Sees if player is in table if Players[Player.Name] then
Both should be string values. |
|
|
| Report Abuse |
|
|
|
| 06 Jun 2015 07:46 AM |
Well then, instead of: table.insert(Players, Player.Name) Do this: Players[Player.Name] = true |
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 06 Jun 2015 07:47 AM |
Figured out doing this works:
for i,v in pairs (Players) do if v == Player.Name then
But why doesn't players[PLayer.Name] work? It's way easier to use |
|
|
| Report Abuse |
|
|
|
| 06 Jun 2015 07:48 AM |
Maybe you should understand tables first.
http://wiki.roblox.com/index.php?title=Table |
|
|
| Report Abuse |
|
|
|
| 06 Jun 2015 08:00 AM |
local table = require(199207348)
local Players = {"Player1"} for i, Player in pairs(game.Players:GetPlayers()) do if table.find(Players, Player.Name) then
end end |
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 06 Jun 2015 08:43 AM |
How would you remove dictionary indexes? table ={["Player1"] = true}
for i,v in pairs (Players) do if i == Player.Name then table.remove(Players, v) -- Doesn't work, can't use i or v? end end |
|
|
| Report Abuse |
|
|
WishNite
|
  |
| Joined: 11 Feb 2009 |
| Total Posts: 15828 |
|
| |
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 06 Jun 2015 09:43 AM |
| Are you able to do #Players with dictionaries |
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 06 Jun 2015 10:45 AM |
local table = require(199207348)
print(table.length(dictionary)) |
|
|
| Report Abuse |
|
|