of     1   

Aespect
#140687577Friday, July 18, 2014 1:17 AM GMT

Hi, I've tried and tried to make a table where it takes the player's positions and orders them from one to four. Everything works, except that it put the first place player in every slot. Here's the main script: for _,v in pairs (Workspace:GetChildren()) do if v:FindFirstChild("Athlete",true) then v.Athlete.WalkSpeed = 25 --game.Players:FindFirstChild(v.Name).Speed.Value end end startTime=tick() repeat wait(0.001) MainG.Value = "100m Sprint ["..timer(tick()-startTime).."]" for _,v in pairs(game.Players:GetChildren()) do if v.Going.Value then pcall(function() table.insert(temp,{--inserts into table ['player']=v;--racer ['pos']= math.abs(v.Character.Torso.Position.X);--distance }); end); end end selection_sort(temp); _G.lineup=temp; until Racing==0
Aespect
#140691739Friday, July 18, 2014 1:57 AM GMT

Apparently, I need cnt or island or another genius for this one... :/
swimguy777
#140693724Friday, July 18, 2014 2:16 AM GMT

Why not set up your table like this: { player1 = position, player2 = position, etc... } And then just cycle through each player occasionally to update and sort their positions. -[::ƧѡÎḾḠΰῩ::]-[::Helper of Scripting and Writer of Wikis::]
Aespect
#140732175Friday, July 18, 2014 12:54 PM GMT

1
C_Sharper
#140739641Friday, July 18, 2014 2:56 PM GMT

Might be harder but you can definitely make it work. Use magnitude and do a simpler set up with loops.
Notunknown99
#140740159Friday, July 18, 2014 3:04 PM GMT

table.sort(tab, function(a, b) return a.pos < b.pos end)
Aespect
#140772934Friday, July 18, 2014 9:04 PM GMT

Here's the sorting part. Might be something in here?? function selection_sort(tab) for i = 1, #tab do local minimum = i for t = i + 1, #tab do if tab[t].pos < tab[minimum].pos then minimum = t end end tab[i], tab[minimum] = tab[minimum], tab[i] end end
Notunknown99
#140773189Friday, July 18, 2014 9:06 PM GMT

Use table.sort
Aespect
#140773650Friday, July 18, 2014 9:11 PM GMT

Erm, I'm not quite sure how to do that.... :/
Notunknown99
#140773704Friday, July 18, 2014 9:11 PM GMT

Read my previous post.
Aespect
#140776518Friday, July 18, 2014 9:36 PM GMT

I can't figure it out..... I'm sorry.... :/
sparker22
#140776888Friday, July 18, 2014 9:40 PM GMT

Aespect
#140776999Friday, July 18, 2014 9:41 PM GMT

I tried doing that. For some reason, I can't seem to tie it in with my current sorting script...
C_Sharper
#140778046Friday, July 18, 2014 9:50 PM GMT

How about this, you put positions (numbers) into tables, and do something like this: if pos[1] > pos[2] then --stuff end
Aespect
#140783042Friday, July 18, 2014 10:39 PM GMT

I'm sorry, but if you could try to tie this into the sorting script, I'd be much appreciative! c:
Aespect
#140799500Saturday, July 19, 2014 1:20 AM GMT

Bump
C_Sharper
#140802752Saturday, July 19, 2014 1:53 AM GMT

I'd say using magnitude is easier. local mag = (game.Workspace.Athlete1.Torso.Position - game.Workspace.Athlete2.Torso.Position).magnitude print(mag) Magnitude is the distance between the two.
Aespect
#140802857Saturday, July 19, 2014 1:54 AM GMT

Ok, but the current problem is in the sorting.
Aespect
#140845124Saturday, July 19, 2014 2:35 PM GMT

...
C_Sharper
#140848762Saturday, July 19, 2014 3:38 PM GMT

I know. Sometimes SH is greatly inactive. Like my post. Sorry, but I failed you :(
C_Sharper
#140848838Saturday, July 19, 2014 3:39 PM GMT

Have you heard of 'table.sort' If you input positions in the table, it can sort them. May be something to check into.
Notunknown99
#140848853Saturday, July 19, 2014 3:39 PM GMT

table.sort(table, function(a, b) return a.pos < b.pos end) Something like that.
Aespect
#140942093Sunday, July 20, 2014 11:35 AM GMT

Is there anything wrong with this?? This is what does the sorting: function selection_sort(tab) --Go through every position in the table for i = 1, #tab do --start minimum at current position local minimum = i --Go through the remaining elements that need to be sorted for t = i + 1, #tab do --compare current element to minimum if tab[t].pos < tab[minimum].pos then --t is the new minimum minimum = t end end --switch minimum with current position tab[i], tab[minimum] = tab[minimum], tab[i] end end
Notunknown99
#140945709Sunday, July 20, 2014 1:18 PM GMT

table.sort is far better. You should use it.

    of     1