Hello there,
How do i get the order according to the top 1 number in the global? I have assigned a global for storing numbers (for example score1 <- 0;) but how do i get the order of it? I'm having 3 globals for testing and i need to know how to find which global is having the highest number in it.
Here is an idea how you can do it :)
score_one <- 10;
score_two <- 20;
score_three <- 30;
function Top3Scores()
{
local p_Count = 0;
local s_arr = [ score_one, score_two, score_three ];
s_arr.sort(); // Now the array 's_array' will have the values sorted from lowest to highest.
s_arr.reverse(); // Reverse the values, first = last, last = first.
print( "Top scores: " );
for( local i_Sort = 1; p_Count < s_arr.len(); p_Count++ ) { print( format( "%i. %i", i_Sort, s_arr[ p_Count ] ) ); i_Sort++; }
}
Result of the above code:
[SCRIPT] Top scores:
[SCRIPT] 1. 30
[SCRIPT] 2. 20
[SCRIPT] 3. 10
Have fun :D
Im doing this just to see how you shoot your self in the foot :D
score1 <- 1;
score2 <- 2;
score3 <- 3;
local x = 1;
print( getroottable().rawget( "score" + x ) );
x = 2;
print( getroottable().rawget( "score" + x ) );
x = 3;
print( getroottable().rawget( "score" + x ) );
local num = 0, val = 0, var = null;
for (local i = 0; i <= 3; ++i)
{
val = getroottable().rawget("score" + i);
if (val > num)
{
var = i;
num = val;
}
}
if (var != null) print( getroottable().rawget( "score" + var ) );
I was on tablet so check for mistakes!
local num = 0 val = 0
You forgot a comma
Quote from: NE.CrystalBlue on Sep 03, 2015, 01:23 PMlocal num = 0 val = 0
You forgot a comma
I hope you noticed that
Quote from: S.L.C on Sep 02, 2015, 06:49 PM...
I was on tablet so check for mistakes!
Yea, we noticed it
"so check for mistakes"
I wouldn't have even found it out if I hadn't read it.
After reading, I checked for some mistakes
I was actually expecting to be errors in that code. It's annoying as f* to type code on android :D