1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Question Event Listeners

Discussion in 'Developer Support' started by VonJoss, Aug 24, 2023.

  1. VonJoss

    Joined:
    Feb 23, 2021
    Messages:
    4
    Likes Received:
    0
    Hi,

    For the life of me I cant get the EventListeners to work.

    I found this post which I think steered me in right direction, but still I cant log out anything in the event methods and my debugger wont stick inside those methods either. But it did not seem to help me.
    Resolved - Event listener not firing?

    Any suggestions or examples on this matter?


    This is my EventListener

    Code (Text):
    1. @NoArgsConstructor
    2. public class PrayerFlick implements EngineListener {
    3.  
    4.     @Override
    5.     public void onCycleStart() {
    6.         Environment.getBot().getLogger().info("Experience gained 1");
    7.     }
    8.  
    9.     @Override
    10.     public void onTickStart() {
    11.         Environment.getBot().getLogger().info("Experience gained 2");
    12.     }
    13.  
    14.     @Override
    15.     public void onEngineStateChanged(EngineStateEvent event) {
    16.         Environment.getBot().getLogger().info("Experience gained 3" + event.toString());
    17.     }
    18. }
    And this is my Main bot
    Code (Text):
    1. public class RunBot extends TreeBot {
    2.  
    3.     public PrayerFlick prayerFlick = new PrayerFlick();
    4.     public EmptyRoot emptyRoot = new EmptyRoot();
    5.  
    6.     public void onStart(String... arguments) {
    7.         this.getEventDispatcher().addListener(prayerFlick);
    8.         Environment.getBot().getLogger().info("Done");
    9.     }
    10.  
    11.     @Override
    12.     public LeafTask createRootTask() {
    13.         return emptyRoot;
    14.     }
    15. }
     
    #1 VonJoss, Aug 24, 2023
    Last edited: Aug 24, 2023
  2. Swych

    Joined:
    Dec 9, 2016
    Messages:
    3,183
    Likes Received:
    1,034
    Are you certain you're compiling and running the most recent version of the code? This all looks fine to me.
     
  3. VonJoss

    Joined:
    Feb 23, 2021
    Messages:
    4
    Likes Received:
    0
    I am quite certain, because I see the onStart() method log with a message "Done" and now when I added a log saying "Started" at the beginning, I can also see that new log line after running the bot.

    But maybe there is more definitive way to tell?
     
  4. Bing Bong

    Bing Bong Bot Author

    Joined:
    Jan 29, 2016
    Messages:
    1,083
    Likes Received:
    103
    Firstly, you're using deprecated code so if you're looking to eventually publish this onto the bot store, it will automatically get rejected.

    "But maybe there is more definitive way to tell?"

    Yes. You could use a .getListeners and see if it was ever added.
     
  5. VonJoss

    Joined:
    Feb 23, 2021
    Messages:
    4
    Likes Received:
    0
    I checked .getlisteners right away and it gets added.

    Where do I get the "non" deprecated code? Or do you mean only the .getLogger is deprecated? If so, Its just there for debugging purposes.
     
  6. Bing Bong

    Bing Bong Bot Author

    Joined:
    Jan 29, 2016
    Messages:
    1,083
    Likes Received:
    103
    Even for debugging purposes, you should really be using Log4j2, easily implemented. -> Saves you time writing all that bs code out too when you could just easily write log.debug(msg)
     
  7. VonJoss

    Joined:
    Feb 23, 2021
    Messages:
    4
    Likes Received:
    0
    Yeah, you are absolutely right. Was just doing it for me at the moment not for the store, still trying to figure out the API. Never wrote a bot for a runescape with a API, wrote one with image recognizion in python about 10 years ago.

    Coming back to the initial topic, any ideas on the Events not firing? Anything else I can try?
    I am just out of ideas.
     

Share This Page

Loading...