Change value in a Table

edited October 2017 in Questions about Code

I want to update the millis value that is stored togheter with a user string, I dont understand how I should do this, here is the code I currently use, (The table is called User_Id_Ping.

void Update_User_Ping_Register(String User_To_Update) {
  for (TableRow Row_Count : User_Id_Ping.rows()) {
    String Current_User_Id = Row_Count.getString("id");
    if (Current_User_Id.contains(User_To_Update)) {
      User_Id_Ping.setFloat(row, "ID", millis());
      //this is where is should update the value
    }
  }
}

Answers

    • Under Java's conventions, variable & function names shouldn't begin w/ a capital letter! :-@
    • So, rather than Update_User_Ping_Register() & Row_Count, go w/ update_user_ping_register() & row_count.
    • Or even better, use lowerCamelCase for them: updateUserPingRegister() & rowCount. ~O)
    • Now back to your problem... I-)
    • At line #5: userIdPing.setFloat(row, "ID", millis());
    • That variable row isn't defined inside your function. No idea where it might be defined at! :-@
    • According to the logic of your loop, iterator variable rowCount represents the current TableRow, right?
    • So, why don't use use that variable as the 1st argument for setFloat(): #-o
      userIdPing.setFloat(rowCount, "ID", millis());
    • Dunno whether that change fixes your bug, but it is a start. :>
  • Thank you and also my bad, the row value was

    int row = int(row_Count.toString());

    I removed it when cleaning up the code so it would be easier to understand but forgot to change it back.

    The reason I made that variable is.. when I use

    userIdPing.setFloat(rowCount, "ID", millis());

    I get this error

    The function "setFloat()" expects parameters like: "setFloat(int, int, float)"

    so thats why I tried to convert it into an int. but that means that the problem isnt fixed :(

  • Answer ✓

    Rather than use Table::setFloat() method: :-@
    https://Processing.org/reference/Table_setFloat_.html

    How about instead TableRow::setFloat() method: *-:)
    https://Processing.org/reference/TableRow_setFloat_.html

    rowCount.setFloat("ID", millis());

  • @GoToLoop Thank you! I thought I already tried that, but apparently not. :)

Sign In or Register to comment.