tentastic
|
  |
| Joined: 21 Dec 2008 |
| Total Posts: 1417 |
|
|
| 10 May 2013 04:48 PM |
Welcome to the first Scripting Challenge! (By Tentastic) Scripting Challenges are questions and problems in which you have to use your scripting knowledge to solve! Remember, these things are challenging and not everyone does understand what to do! Try your best and put your skills to the test!
Challenge [1]:
Script:
playertable = {}
while true do wait(1) local players = game.Players:GetChildren() for i = 1, #players do table.insert(playertable, players[i]) end end
Question: How do you not add a player onto the table more than once?
|
|
|
| Report Abuse |
|
|
| |
|
tentastic
|
  |
| Joined: 21 Dec 2008 |
| Total Posts: 1417 |
|
|
| 10 May 2013 04:50 PM |
| What do you ADD to the script to make the players not be added more than once? |
|
|
| Report Abuse |
|
|
|
| 10 May 2013 04:51 PM |
playertable = {}
game:GetService'Players'["PlayerAdded:]:connect(function(blah) table.insert(playertable, blah) end) |
|
|
| Report Abuse |
|
|
Flurite
|
  |
| Joined: 03 Apr 2011 |
| Total Posts: 5386 |
|
|
| 10 May 2013 04:51 PM |
Now the ultimate question is... which loop?
The world may never know. |
|
|
| Report Abuse |
|
|
Flurite
|
  |
| Joined: 03 Apr 2011 |
| Total Posts: 5386 |
|
|
| 10 May 2013 04:52 PM |
What would I add?
I would comment everything you have already and then do something like what VirtualUser did. |
|
|
| Report Abuse |
|
|
|
| 10 May 2013 04:53 PM |
Oh... this is one of those stupid questions. Okay
playertable = {}
while true do wait(1) local players = game.Players:GetChildren() for i = 1, #players do if not playertable[player[i]] then table.insert(playertable, players[i]) end end end |
|
|
| Report Abuse |
|
|
|
| 10 May 2013 04:54 PM |
| I don't think this is an actual challenge. I think this is just an attempt by the OP to get his script fixed but not get flamed for it. |
|
|
| Report Abuse |
|
|
Tenal
|
  |
| Joined: 15 May 2011 |
| Total Posts: 18684 |
|
|
| 10 May 2013 04:55 PM |
Add the word 'break'. Done! ;D |
|
|
| Report Abuse |
|
|
|
| 10 May 2013 04:57 PM |
@thedestroyer115
Thank you for pointing out the obvious friend. Much appreciated. What is weird though is that he didn't accept it when I provided him with a more efficient method? Weird. |
|
|
| Report Abuse |
|
|
|
| 10 May 2013 04:58 PM |
@ Tenal
No, because that would defeat the purpose of consistency silly. |
|
|
| Report Abuse |
|
|
Tenal
|
  |
| Joined: 15 May 2011 |
| Total Posts: 18684 |
|
|
| 10 May 2013 05:01 PM |
I'm going to guess that he's not trying to get people to fix something for him but instead extremely undermining the level of this forum.
He specifically added the rule that you need to add lines, not remove. Removing it would be the obvious solution and the very first reply was the answer, ignoring all other rules. |
|
|
| Report Abuse |
|
|
dekkonot
|
  |
| Joined: 22 Dec 2010 |
| Total Posts: 6685 |
|
|
| 10 May 2013 05:26 PM |
You use a for loop to check if the player is already located inside of the table. Enjoy.
~ Linguam latinam est optimum ~ |
|
|
| Report Abuse |
|
|
|
| 10 May 2013 10:50 PM |
You're all doing it wrong, and in a terribly inefficient way.
local Players = Game:GetService('Players') local players = {}
while true do wait(1) for _, player in next, Players:GetPlayers() do players[player] = true end end
_________________________________________________________________________ Twitter: https://twitter.com/MarkOtaris |
|
|
| Report Abuse |
|
|
Riderj
|
  |
| Joined: 15 Aug 2011 |
| Total Posts: 1534 |
|
|
| 10 May 2013 10:55 PM |
@ VirtualUser
playertable = {}
game:GetService'Players'["PlayerAdded:]:connect(function(blah) table.insert(playertable, blah) end)
It would still add the player more than once. |
|
|
| Report Abuse |
|
|
Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
|
| 11 May 2013 05:45 AM |
local Players = Game:GetService('Players') local PlayerList = {} setmetatable(PlayerList, {__mode = "k";})
Players.PlayerAdded:connect(function(Player) PlayerList[Player.Name] = Player; end
Players.PlayerRemoving:connect(function(Player) PlayerList[Player] = nil end
local function PlayerInGame(PlayerName) return PlayerList[PlayerName]; end
http://wiki.roblox.com/index.php/User:Quenty/How_To_Receive_Help_From_Scripters --> Note to self, add "How to create a successful [s]competition[/s] challenge." |
|
|
| Report Abuse |
|
|
Parthax
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 6941 |
|
|
| 11 May 2013 06:35 AM |
| Either trolling or trying to not be flamed from asking for help |
|
|
| Report Abuse |
|
|
|
| 11 May 2013 07:24 AM |
'if not playertable[player[i]] then table.insert(playertable, players[i])'
nope.avi
huh fail |
|
|
| Report Abuse |
|
|
|
| 11 May 2013 08:21 AM |
@ Quenty, ColorfulBody
The purpose was to take the existing script and ADD to it so it runs only once. You can't change everything about it. You have to use his script and add to it to accomplish as he suggested.
@Riderj
It would not add it more than once as long as they didn't leave and come back. I had disregarded the fact that sometimes that happens... lol. Simple fix.
@Pre
Shhhhh... The multiple mistakes in that script were pointed so the user could correct them (him/her)self. As stated before that it was someone looking to get help. |
|
|
| Report Abuse |
|
|
| |
|
cygorx
|
  |
| Joined: 09 Nov 2012 |
| Total Posts: 668 |
|
|
| 11 May 2013 10:53 AM |
a={__a={},__b={},__c={}}; f = (function(x) loadstring(x)() end) q = [==[ repeat for z=0, 999 do for i=999, 0, -1 do for _,v in pairs(a) do for q,w in pairs(a.__a) do for e,r in pairs(a.__b) do for t,y in pairs(a.__c) do do while true do f(q) break end end end end end end end end until (false) ]==] f(q)
what do i win |
|
|
| Report Abuse |
|
|
|
| 11 May 2013 10:54 AM |
| hes obviously just trying to get you all to do his script for him |
|
|
| Report Abuse |
|
|
dekkonot
|
  |
| Joined: 22 Dec 2010 |
| Total Posts: 6685 |
|
|
| 11 May 2013 11:00 AM |
No? REALLY? It's not like that was pointed out almost immediately.
~ Linguam latinam est optimum ~ |
|
|
| Report Abuse |
|
|
SN0X
|
  |
| Joined: 24 Oct 2011 |
| Total Posts: 7277 |
|
|
| 11 May 2013 11:01 AM |
>what do i win
my messy code competition
:(
u won before it started noob
greetings hue man |
|
|
| Report Abuse |
|
|
Looah
|
  |
| Joined: 22 Feb 2013 |
| Total Posts: 922 |
|
|
| 11 May 2013 11:10 AM |
playerlist = {} game.Players.ChildAdded:connect(function(obj) playerlist[obj.Name] = obj end)
--This, perhaps?
'0 is false and 1 is true, right? 1.' |
|
|
| Report Abuse |
|
|