question-circle Selecting last row in list?

  • Rocket
  • Rocket's Avatar Topic Author
  • Offline
  • Beginner Marbler
  • Beginner Marbler
More
27 Jun 2014 17:41 #1 by Rocket
Selecting last row in list? was created by Rocket
First off, I have (almost?) no coding knowledge at all.
I'm using buttons to select a previous/ the next row, and am trying to loop the selection when it reaches either end of the list. The next button is working for me; it loops back to the beginning when the selection reaches the last row, but the previous button does not loop at all. How do I select the last row in the list?

Here is my function:
function prevMarble() {
   %id = List.getSelectedId();
   %maxinlist = List.rowCount();  //isn't working
   if (%id > 0)
       List.setSelectedById(%id--);
   else
       List.setSelectedRow(%maxinlist);
   updatemarbleobj();
}

Please Log in or Create an account to join the conversation.

  • HiGuy
  • HiGuy's Avatar
  • Offline
  • Administrator
  • Administrator
  • At college, may not be around
More
27 Jun 2014 20:38 - 27 Jun 2014 20:39 #2 by HiGuy
Replied by HiGuy on topic Selecting last row in list?
Row indices start at 0, so the index of the last row would be (rowCount - 1).
So you'd want something like:
...
   if (%id > 0)
       List.setSelectedById(%id--);
   else
       List.setSelectedById(%maxinlist - 1); //Also changed to setSelectedById
...

Let me know if you have any problems.

PQ in a nutshell
function clientcmd12dothepq() {
    commandToClient(LocalClientConnection, '34onthedancefloor');
}
Last edit: 27 Jun 2014 20:39 by HiGuy.

Please Log in or Create an account to join the conversation.

  • Jeff
  • Jeff's Avatar
  • Offline
  • Developer
  • Developer
  • PlatinumQuest Programmer
More
27 Jun 2014 20:41 #3 by Jeff
Replied by Jeff on topic Selecting last row in list?
Just wanted to chime in and say use .setSelectedById() method for both the if and the else clause. It might have worked the way you did it, but keep consistency. :)

I am a programmer. Most here know me for being one of the major contributors to Marble Blast Platinum and PlatinumQuest.

Please Log in or Create an account to join the conversation.

  • Rocket
  • Rocket's Avatar Topic Author
  • Offline
  • Beginner Marbler
  • Beginner Marbler
More
27 Jun 2014 20:45 #4 by Rocket
Replied by Rocket on topic Selecting last row in list?

HiGuy wrote:
Row indices start at 0, so the index of the last row would be (rowCount - 1).

Jeff wrote:
Just wanted to chime in and say use .setSelectedById() method for both the if and the else clause. It might have worked the way you did it, but keep consistency. :)

Thanks, it finally works!

Please Log in or Create an account to join the conversation.

Moderators: AayrlKalle29Regislian