Resolved getMessages returning incorrect values over time

Discussion in 'Developer Support' started by Furor, Oct 21, 2015.

  1. As you can see the timestamps don't line up:
    [​IMG]
    I'm using the following code:
    Code (Text):
    1. System.out.println(Chatbox.getMessages().get(Chatbox.getMessages().size() - 1).getMessage().toString());
    to get the latest message in the chatbox.

    Steps to reproduce:
    Get the latest message and print out the contents

    Problem: It only works for a while, then it stops working, only solution is to relog.
    Proof that it works at first using the same code:
    [​IMG]

    It seems to happen when a 'News' message is displayed, where it stops working thereafter, though this could just be a coincidence, it could be due to the messages reaching the end of the chat, I don't know.

    [​IMG]
    --- Double Post Merged, Oct 21, 2015, Original Post Date: Oct 21, 2015 ---
    @Cloud

    Edit: Same behavior regardless of if timestamps are enabled or not

     
    #1 Furor, Oct 21, 2015
    Last edited: Oct 21, 2015
  2. Best Answer:
    Post #6 by Cloud, Oct 22, 2015
  3. Did you try ChatBoxListener? Works fine for me.

    Code (Text):
    1. @Override
    2. public void onMessageReceived(MessageEvent e) {
    3.     System.out.println(e.getMessage());
    4. }
    Code (Text):
    1. (05:12:34) You can access Treasure Hunter from the side panel, and you can show the button again by logging out and back in.
    2. (05:13:00) A tasty fish.<br>GE guide price: 364 gp each
    3. (05:13:10) An enchanted ring.<br>GE guide price: 1,835 gp each
     
  4. I'm using that but I need to delay until another message is sent and hence need getMessages to work.
     
  5. You could use a boolean as a switch?
     
  6. I ended up doing that and it should work, but getMessages is still broken.
     
  7. getMessages isn't broken. It does not guarantee any order.
     
  8. Could we get a way to sort them easily, or was this restriction put in place so people used ChatboxListener instead?
     
  9. It would be annoying to try and force the original order because the data comes in multiple "streams" that we then merge into a single list.
     
  10. Just make a concurrent list and and every time a message is received, add it to the list.
     
  11. Should be done in a bot specific context as this would be wasted usage for 99% of bots. May have been what you were suggesting, but just clarifying.
     
  12. It was a suggestion for @Furor
     

Share This Page

Loading...