generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: I don't want the code but the logical thought process

Previous Thread :: Next Thread 
GeoVolcano is not online. GeoVolcano
Joined: 05 Jul 2012
Total Posts: 1433
23 Feb 2015 09:57 PM
You have a gui

You have 14 different variables (values)

From the top to the bottom the variables will appear in order from greatest to least

If the value is 0, then it will not appear

This would change every time a value changed.

How could you logically do this?
Report Abuse
IIIIIIlII is not online. IIIIIIlII
Joined: 06 Jan 2011
Total Posts: 710
23 Feb 2015 10:19 PM
use a table and change the index of the highest value (in the table) to the lowest index then its just a matter of ordering the table

:)
Report Abuse
TooKawaiiForSenpai is not online. TooKawaiiForSenpai
Joined: 03 Mar 2009
Total Posts: 3241
23 Feb 2015 10:25 PM
Tables are defined as so:

local asdf = { "One", "Two", "Three"]

asdf[1] -->One
asdf[2] -->Two

asdf[1] = "Four"
asdf[1] -->Four
Report Abuse
GeoVolcano is not online. GeoVolcano
Joined: 05 Jul 2012
Total Posts: 1433
23 Feb 2015 10:33 PM
I did not understand anything you just said, but I do know how to make a table.
Report Abuse
GeoVolcano is not online. GeoVolcano
Joined: 05 Jul 2012
Total Posts: 1433
23 Feb 2015 10:33 PM
How would you change it to highest to lowest?
Report Abuse
TooKawaiiForSenpai is not online. TooKawaiiForSenpai
Joined: 03 Mar 2009
Total Posts: 3241
23 Feb 2015 10:36 PM
So you could do like

table = {} --"one", "two", etc all the way to "ten"


--to go from "One" to "Ten"
for i = 1, 10 do
print(table[i])
end

--to go from "Ten" to "One"
for i = 10, 1, -1 do
print(table[i])
end
Report Abuse
TooKawaiiForSenpai is not online. TooKawaiiForSenpai
Joined: 03 Mar 2009
Total Posts: 3241
23 Feb 2015 10:37 PM
Forgot to say. To get the length of a table do #TableName

local table = {}
local tableLength = #table
Report Abuse
GeoVolcano is not online. GeoVolcano
Joined: 05 Jul 2012
Total Posts: 1433
23 Feb 2015 10:52 PM
local player = game.Players.LocalPlayer
while true do wait (5)
local Table = {player.Apple.Value,player.Banana.Value}
table.sort(Table)
local Table2 = {"Apple","Banana"}
for i,v in pairs(Table) do
if v >= 1 then
print (Table2[i])
print (v)
end end end

I tried using your method but it ended up producing a peculiar output. So how would I arrange this from greatest to least?
Report Abuse
mew903 is not online. mew903
Joined: 03 Aug 2008
Total Posts: 22071
23 Feb 2015 11:48 PM
Google "bubble sort method"
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
23 Feb 2015 11:55 PM
local Unlisted = {3, 6, 1}

function FindLargest(tab)
local Largest = 0
local Position = 0
for i, v in pairs(tab) do
if v > Largest then
Largest = v
Position = i
end
end
return Position
end

function SortValues(tab)
local SortedTab = {}
local DisposableTab = tab

while #DisposableTab > 0 do
local Position = FindLargest(DisposableTab)
table.insert(SortedTab, DisposableTab[Position])
table.remove(DisposableTab, Position)
end

return SortedTab
end

print(unpack(Unlisted))
print(unpack(SortValues(Unlisted)))

-> 3 6 1
-> 6 3 1


Didn't have time to debug, check to see if it works.

It doesn't organize numbers less than 0, but I don't think you'll have to worry about that if I understand your situation correctly.
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
24 Feb 2015 12:01 AM
Oh, sorry, I didn't realize you didn't want the code.

Basically, the "FindLargest" function finds the largest value in the table.

I used the original table and continually apply this function, taking the largest values out and putting them into a new table. (so they are in order)

I just return the new table, and voila, your organized table.
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
24 Feb 2015 12:02 AM
I'm going to sleep, if there are any problems, reply here, I'll be on tomorrow.
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
24 Feb 2015 02:12 AM
You need to think about your labels

Sort an array of arrays
Iterate through k,v of the array
Iterate n,i through the table of labels (Bananas, Apples)
Find key n of v
Make a gui using n of v
Use n to position it along X and k to position it on Y or something
Done.
Report Abuse
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
24 Feb 2015 04:30 AM
I'm sorry, I think in code.
But this is basically how I would do it.
Feel free to plagiarise:

local values = { } -- Store your Value instances in this
local guis = { }

local function CreateGui(i, value)
local x = Instance.new("TextButton")
x.Text = string.format("%s: %s", value.Name, value.Value)
x.Position = UDim2.new(position_doing_something_with_i)
x.Parent = whatever
return x
end


local function reorder()
table.sort(guis, function(a, b) return a.value.Value > b.value.Value end)
for i = 1, #guis do
local v = guis[i]
v.Position = (position_doing_something_with_i) -- This could also be a TweenPosition.
-- It would make for some pretty cool stuff.
end
end

for i = 1, #values do
local v = values[i]
v.Changed:connect(reorder)
guis[i] = {value = v, gui = CreateGui(i, v)}
end

Report Abuse
TooKawaiiForSenpai is not online. TooKawaiiForSenpai
Joined: 03 Mar 2009
Total Posts: 3241
24 Feb 2015 09:51 PM
Don't you dare use a bubble sort, implementing bubble sort in actual code results in public flogging.
Don't use your own sorting algorithm either that's disgusting and too much work.

Instead, just use table.sort. Unknown to many, it actually has two arguments: the table to sort and a comparator function.
The comparator is a function that takes two arguments and returns a value on how to sort them (which one goes above the other in the list).

Please Please Please Please Please Please Please Please Please Please Please Please Please Do this. It's easiest and by far the most efficient.
Report Abuse
TooKawaiiForSenpai is not online. TooKawaiiForSenpai
Joined: 03 Mar 2009
Total Posts: 3241
24 Feb 2015 09:52 PM
It should be noted that bubble sort is actually one of the worst and most inefficient algorithms out there. It scales terribly and takes forever to sort larger tables. Whoever recommended it needs to do some research :(
Report Abuse
TooKawaiiForSenpai is not online. TooKawaiiForSenpai
Joined: 03 Mar 2009
Total Posts: 3241
24 Feb 2015 09:54 PM
You can find a good example of lua comparators here:
http://stackoverflow.com/questions/2038418/associatively-sorting-a-table-by-value-in-lua

Hopefully this doesn't get modded because it's SO but whatever.
SO is like, one of the most useful learning resources out there.
Report Abuse
mew903 is not online. mew903
Joined: 03 Aug 2008
Total Posts: 22071
24 Feb 2015 10:34 PM
I compared the speeds of a bubble sort function vs table.sort through lua.exe & there wasn't much of a difference. Pretty sure table.sort is generally unstable as far as the algorithm it used goes. Unless op will be running his sort function over and over I wouldn't worry about the amount of memory or time being used up
Report Abuse
TooKawaiiForSenpai is not online. TooKawaiiForSenpai
Joined: 03 Mar 2009
Total Posts: 3241
24 Feb 2015 10:48 PM
Run it on a dataset of 10k maybe 30k records. There will be a difference.
Report Abuse
TooKawaiiForSenpai is not online. TooKawaiiForSenpai
Joined: 03 Mar 2009
Total Posts: 3241
24 Feb 2015 10:49 PM
table.sort uses a Quicksort algorithm which is many times better than bubble.

It's also a nice habit to get in to - best practices and such
Report Abuse
mew903 is not online. mew903
Joined: 03 Aug 2008
Total Posts: 22071
24 Feb 2015 10:50 PM
OP o-only needs it fo-for 14 values.... :-(
Report Abuse
TooKawaiiForSenpai is not online. TooKawaiiForSenpai
Joined: 03 Mar 2009
Total Posts: 3241
24 Feb 2015 10:51 PM
But it's still a good thing to learn. It's still 1 line of code vs 20 AND it's efficient.
Report Abuse
TooKawaiiForSenpai is not online. TooKawaiiForSenpai
Joined: 03 Mar 2009
Total Posts: 3241
24 Feb 2015 10:52 PM
bae pls don't fight me on this :(
Report Abuse
mew903 is not online. mew903
Joined: 03 Aug 2008
Total Posts: 22071
24 Feb 2015 11:02 PM
o-ok senpai
Report Abuse
GeoVolcano is not online. GeoVolcano
Joined: 05 Jul 2012
Total Posts: 1433
25 Feb 2015 02:05 PM
Okay so I have all of the components inside the table. But how would I be able to duplicate a text label n number of times for the length of the table?
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image