[Solved]Need Help With A Best Times List

  • I'm wondering why you are converting the values to int? Are Reg.currTime and Reg.bestTimes[] Floats? Std.int is like Math.floor removing the remainder so if < 1 it will be 0.


    if (Reg.bestTimes[Reg.mazeSelect][i] == 0 || Reg.bestTimes[Reg.mazeSelect][i] > Reg.currTime)

    and see what you get

    and maybe it's null? so you can check for that too?

    if (Reg.bestTimes[Reg.mazeSelect][i] == null || Reg.bestTimes[Reg.mazeSelect][i] == 0 || Reg.bestTimes[Reg.mazeSelect][i] > Reg.currTime)

  • The casting thing was just me trying to figure it out. I wasn't casting when this bug first showed up. So my original code looked just as your suggestion does.

    As for null values, I am defaulting the list to zero for each of the 10 elements. I even trace it out and it displays as 0 in the displayed trace.

  • ok.

    I think this

    Reg.bestTimes[Reg.mazeSelect].insert(i, Reg.currTime);

    can be changed to
    Reg.bestTimes[Reg.mazeSelect][i] = Reg.currTime;

  • That wouldn't work because I need to the current element to be shifted down in the list. So if the best time was 100 seconds and the new time is 90 seconds, I need 90 in index 0 and 100 in index 1 in the final array. That is what insert does.

  • Here is my code for my high scores list (high to low) for another game. It works exactly how I expect it to work.

    for (i in 0...Reg.highScores.length)
    	if(Reg.highScores[i] < Reg.score)
    		Reg.highScores.insert(i, Reg.score);

  • I guess this could all be moot if I were to drop the zero stuff and default my best times list to something absurd (like an hour). But I just think that looks tacky.

  • what if you keep them null and test for null instead of zero? nvm, can't do that

  • That actually does work. I just have to change the array type to Dynamic. Not my preferred solution, but it at least works.

  • This worked for me

    for (i in 0...Reg.bestTimes[Reg.mazeSelect].length)
    	if(Reg.currTime < Reg.bestTimes[Reg.mazeSelect][i] || Reg.bestTimes[Reg.mazeSelect][i] == 0)
    		Reg.bestTimes[Reg.mazeSelect].insert(i, Reg.currTime);

  • That did it. Crazy that just switching the direction of that conditional was the solution.

    Thanks a lot. I really appreciate the help.

  • glad it helped :)

  • @ezacharyk

    You should change the conditional to <= in case the values are the same or it will be skipped.

    if(Reg.currTime <= Reg.bestTimes[Reg.mazeSelect][i] || Reg.bestTimes[Reg.mazeSelect][i] == 0)

  • Taking the decimal values of the float into account, the possibility of equality is quite slim. However, if they are equal, it will simply move to the next index and place it there. At least that is what should happen.

    So if index 0 in the best times array is 100 and your current time is 100, it should just move on to index 1. If index 1 is 200, then the code will put the new time there and shift the other times down.

  • @ezacharyk

    but only if you use <= or it gets skipped if they're equal. no?

  • @dean

    Since I am not keeping track of the identity of the player who gets to time, it doesn't really matter if the resulting time is placed before or after a time in the list it is equal to.

    Right now, if the current time and the time in the list are equal, it moves onto the next time in the list.

Log in to reply

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.