phoniex
|
  |
| Joined: 03 Feb 2008 |
| Total Posts: 34985 |
|
|
| 27 Sep 2014 06:32 PM |
How do I make a script that will cycle through a list of values, and will work even if the list is modified?
~Rock is dead. Long live paper and scissors!~ |
|
|
| Report Abuse |
|
sparker22
|
  |
| Joined: 11 Mar 2010 |
| Total Posts: 846 |
|
|
| 27 Sep 2014 07:02 PM |
Queue are typically tables holding values. We can do it like this.
local Queue = {"sparker22","ReeseMcBlox","Shedletsky","phoniex"}
This table stores a list of player's usernames. Now the Queue will act as if Queue[1] is the first player, so we can make a function to execute it.
function selectplayerfromqueue() --code here table.remove(Queue,1) end
table.remove is able to remove a value then pushes the other values forward.
The table will now look like
{"ReeseMcBlox","Shedletsky","phoniex"}
Want to add a player to the queue? No problem.
table.insert(Queue,#Queue + 1,"sparker22")
Now the table will look like
{"ReeseMcBlox","Shedletsky","phoniex","sparker22"}
Tadaa! We now have sparker22 back in the queue.
That explains how to add and remove values from Queues. table.remove/insert handles a lot of the table ordering with you when dealing with modifying tables so it should be relatively easy if you want to keep pushing the 1st player in the queue to the back. And of course this will work if you modify the table. |
|
|
| Report Abuse |
|
phoniex
|
  |
| Joined: 03 Feb 2008 |
| Total Posts: 34985 |
|
|
| 28 Sep 2014 04:12 PM |
Okay, now how do I add values to a table that are derived from another table?
~Rock is dead. Long live paper and scissors!~ |
|
|
| Report Abuse |
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 28 Sep 2014 04:15 PM |
It's like polymorphism in C classes all over again (I forgot the actual name for the practice) Just do the same thing, surely? Just modify it to suit |
|
|
| Report Abuse |
|