I've populated the list by adding new lines of global values as strings but I can't get the numbers to display in the list from lowest to highest. I've checked off the 'sort' checkbox in the list object settings properties. Any suggestions?
I've populated the list by adding new lines of global values as strings but I can't get the numbers to display in the list from lowest to highest. I've checked off the 'sort' checkbox in the list object settings properties. Any suggestions?
Lines are sorted by alphabetical order, not numerical order.
If your values are all integers (whole numbers), you can just add a few zeroes on the front, so that "5" becomes "005"; "50 becomes "050" etc.
eg. Add line: Right$("000"+Str$(Global Value A), 4)
Sorting floats is more problematic...
Why you don't use List of numbers to do that?
http://community.clickteam.com/showthread.php?t=69861
I would have tried list of numbers but it's not iOS compatible. MuddyMole's suggestion works for me. Thanks for the help.
As a side note
I use an invisible high score object as a self sorting list of numbers sometimes.
Feed in a bunch of "scores" and it will sort them for me and I can pull them back out to display them elsewhere.
The thing with the high score object is a good hint, unfortunately not working right now as the object seems not to take up scores I try to insert (either by action or by previous setting).
Any idea how a list of dates, followed by (literally) events referring to each date could be sorted? I know I could use the string operators like "left two characters" but that doesn't quite help me sorting a list. Any hint appreciated![]()
The Right$("000", 4) operator is a nice expression, but I have a bit of a different problem with sorting. I can work around the fact that the list sorts lowest to highest, since I can just go backwards (need highest to lowest). The issue I have is for values below 1000. When I use the Right$("000", 4) operator in front of the value of a counter expression, I end up with fixed leading zeros in front of the value.
example:
0003 (which is fine)
00044 (which is not fine)
How do I fix that without having to create separate events for each set of values?
Like (I'm trying to avoid):
if value[counter] > 1000 then set counter to Right$("000", 4)+value[counter]
if value[counter] > 100 then set counter to Right$("00", 3)+value[counter]
if value[counter] > 10 then set counter to Right$("0", 2)+value[counter]
@FFomega: the correct expression should be Right$("000" + str$(value[counter]), 4). The whole purpose with the Right$ function is to control the number of leading 0's.
@TheChiller: You can sort a list manually using nested fastloops. Loop through a list as many times as there are lines in it, and on each loop, scan the list for the highest value.
You need two list objects for this. The original list and an empty list which we name SortedList.
* Start of frame // Or whenever the list needs to be sorted
- Start loop "SortList" Number of Lines in List times
* OnLoop "SortList"
- Set CounterHighestFound to 0
- Start loop "ScanList" Number of Lines in List times
* OnLoop "ScanList"
+ Val(List, loopindex("ScanList")) > CounterHighestFound
- CounterHighestFound: Set current value to Val(List, loopindex("ScanList"))
- CounterLineNumber: Set current value to loopindex("ScanList")
* OnLoop "SortList"
- SortedList: Add Line str$(CounterHighestFound)
- List: Delete Line CounterLineNumber
I didn't test this in Fusion so there might be mistakes, but I have done it earlier so I know it will work.
Make sure that both List objects are set to be 0-base indexed as that makes it easier to work with fastloops, or else you need to add +1 to the loopindex.