question-circle Selecting last row in list?

  • Rocket
  • Rocket's Avatar Topic Author
  • Offline
  • Beginner Marbler
  • Beginner Marbler
  • Posts: 33
  • Thank you received: 2
27 Jun 2014 17:41 #1
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:
Code:
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
  • Lead Developer
  • Lead Developer
  • PQ Developer Emeritus
  • Posts: 1334
  • Thank you received: 605
27 Jun 2014 20:38 - 27 Jun 2014 20:39 #2
Row indices start at 0, so the index of the last row would be (rowCount - 1).
So you'd want something like:
Code:
... if (%id > 0) List.setSelectedById(%id--); else List.setSelectedById(%maxinlist - 1); //Also changed to setSelectedById ...

Let me know if you have any problems.

This signature is real code
Code:
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
  • Elite Marbler
  • Elite Marbler
  • PlatinumQuest Programmer
  • Posts: 1680
  • Thank you received: 205
27 Jun 2014 20:41 #3
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
  • Posts: 33
  • Thank you received: 2
27 Jun 2014 20:45 #4

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: Doomblah
Time to create page: 1.714 seconds