Jump to content

Do you NEED to call myPlayer every time you want to reference your player?


fixthissite

Recommended Posts

Each call to myPlayer performs some kind of wrap. Why is this wrap needed each call? Could I store the player somewhere to prevent multiple myPlayer calls, or would doing that result in the player not getting updated for some reason? I don't have an account, so I can't really test this out, so if someone could let me know I'd appreciate it

Link to comment
Share on other sites

Each call to myPlayer performs some kind of wrap. Why is this wrap needed each call? Could I store the player somewhere to prevent multiple myPlayer calls, or would doing that result in the player not getting updated for some reason? I don't have an account, so I can't really test this out, so if someone could let me know I'd appreciate it

 

Why exactly would you want to prevent myPlayer calls?

Link to comment
Share on other sites

Why exactly would you want to prevent myPlayer calls?

I'm not trying to prevent it, I just don't want to use it myself. I would expect myPlayer to reference the instance immediately, but instead it wraps it for some reason, which I didn't want to struggle finding out why. I was hoping someone could either give me an explination of why the wrapping occurs, or confirm that it's safe to store the instance in my own variable and use my variable to reference it (to prevent performing the wrap each time, if it's not needed). I guess you can call it premature optimization, but I'm very curious as to why myPlayer requires a wrap rather than immediately reference the player instance

Edited by fixthissite
Link to comment
Share on other sites

It checks to see if the adapter already has a wrapper. If it does then it returns the wrapper; if it doesn't it sets it for future reference. It's pretty efficient. 

I had a feeling it was to lazily initialize something (not completely sure the purpose of a wrapper, but I have no doubts that it's essential), but is there at any point the adapter won't have a wrapper after setting it? Or is it just to prevent creating the wrapper before the user is called for?

 

I understand it's not a HUGE difference, but I actually plan on using quite a bit of resources (CPU time wise in this case), and seeing how myPlayer isn't subject for inlining (on some JVMs), I was wondering if I could safely reference the object using my own variable. Thanks for the confirmation, by the way!

 

EDIT: I understand HotSpot may inline the method if it hasn't been overriden yet, but I'm asking for a general case

Edited by fixthissite
Link to comment
Share on other sites

You're assumption is correct regarding creating the wrapper before the user is called for. I didn't write it but from what it looks like, that's what it is. I closed out of IntelliJ but from what quickly skimmed though, you won't be able to safely reference the object.

 

Edit: Good guesses by the way. What will you be doing that would require that kind of optimization?

  • Like 1
Link to comment
Share on other sites

You're assumption is correct regarding creating the wrapper before the user is called for. I didn't write it but from what it looks like, that's what it is. I closed out of IntelliJ but from what quickly skimmed though, you won't be able to safely reference the object.

 

Edit: Good guesses by the way. What will you be doing that would require that kind of optimization?

A few AI tactics that I think might evolve bots to be more human-like, such as increasing the amount of possible paths taken, multi-tasking and an artificial conscience that lets the bot decide (with guidance from the user) when it should switch to a new skill, quest or market event.

 

I also wanted to attempt a pretty crazy task, which would be logging bot information, sending it to a database to be analyzed by an artificial neural network that I've been thinking of the past week. Within time, I was hoping it would contribute to finding out how Jagex scouts for bots. I just want to make sure the foundation I'm building this on is as optimized as possible (I'm talking micro-optimization), since I know how these subjects can be pretty resource greedy at times, not to mention overhead from the synchronization required to bring all this together together.

 

I'm not even sure if I could fit this all into your client, seeing how I haven't had the chance to profile an average bot, but it's worth a shot. I'm pretty keen when it comes to optimization, so hopefully I could make something of this smile.png Although I'm not building on the actual API (rather than a mock I've slowly been attempting to write; not planning on releasing it once it's finished or anything, the implementation is probably far from true anyways), I want to account for certain aspects one would need to using the real API

 

And just a heads up, I might have quite a few more questions in the future that I'm not sure the community will be able to properly answer. Would you rather me post a topic or message you?

Edited by fixthissite
Link to comment
Share on other sites

The wrapper just wraps the accessor which is used to call the injected methods. This provides the abstraction needed for the average script developer. I'd suggest learning about how OSBot works before attempting any sort of projects tongue.png

That's what I'm doing right now. Not sure what inject methods are in the context of bot scripting, but I'm sure I'll come to realize it in the future when I stumble across them

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...