31
Modification Help / Sorting an array numerically - silly me
« on: February 19, 2017, 07:37:18 PM »
To sort an array numerically, I've tried using array objects. Guess what? Blockland doesn't have the required commands to sort them anyways.
So I resorted to a manual sort.
Now I'm pretty certain this should work but for some reason, it doesn't. I've been like 30 minutes trying to figure out why it doesn't work. Any help?
So I resorted to a manual sort.
Code: [Select]
function updateLeaderboard() {
%leaderboard[0] = 0;
%temp = 1;
%i = 0;
%leaderboard[1] = 2;
%leaderboard[2] = 1;
%leaderboard[3] = 7;
%leaderboard[4] = 4;
%leaderboard[5] = 9;
%leaderboard[6] = 3;
echo(%leaderboard[1] SPC %leaderboard[2] SPC %leaderboard[3] SPC %leaderboard[4] SPC %leaderboard[5] SPC %leaderboard[6]);
for(%i = 1; %i < %leaderboard[0]; %i = %i + 1) {
for(%j = 1; %j < %leaderboard[0]; %j = %j + 1) {
if(%leaderboard[%i] > %leaderboard[%j]) {
%temp = %leaderboard[%j];
%leaderboard[%j] = %leaderboard[%i];
%leaderboard[%i] = %temp;
}
}
}
echo(%leaderboard[1] SPC %leaderboard[2] SPC %leaderboard[3] SPC %leaderboard[4] SPC %leaderboard[5] SPC %leaderboard[6]);
}
Now I'm pretty certain this should work but for some reason, it doesn't. I've been like 30 minutes trying to figure out why it doesn't work. Any help?