dragontitties 0 Share Posted February 12, 2021 Maybe I'm not understanding Java correct... Looking through the API for DreamBot I see that the method "getLocalPlayer()" belongs to the class MethodProvider Everything I've ever learned about Java tells me that an instance method requires you to instantiate the object before you can call methods belonging to it.. Can someone please explain why Player player = getLocalPlayer(); Works just fine? No errors when running. Shouldn't it have to be this? which also doesn't give an error which I would expect MethodProvider mp = new MethodProvider(); Player player = mp.getLocalPlayer(); Thanks Link to comment Share on other sites More sharing options...
Hashtag 8356 Share Posted February 12, 2021 5 hours ago, dragontitties said: Can someone please explain why Player player = getLocalPlayer(); Works just fine? This is because your main class extends AbstractScript, which derives from MethodProvider. Therefore your main script class is an instance of MethodProvider and you have access to its instance methods. If you were to access the localplayer from another class, you wouldn't want to create a new instance of MethodProvider, though. With the static api there's plenty of ways for you to access the localplayer, such as Client.getLocalPlayer() or Players.localPlayer(). elusivestudio 1 Link to comment Share on other sites More sharing options...
elusivestudio 31 Share Posted February 12, 2021 (edited) 7 hours ago, Hashtag said: This is because your main class extends AbstractScript, which derives from MethodProvider. Therefore your main script class is an instance of MethodProvider and you have access to its instance methods. If you were to access the localplayer from another class, you wouldn't want to create a new instance of MethodProvider, though. With the static api there's plenty of ways for you to access the localplayer, such as Client.getLocalPlayer() or Players.localPlayer(). Very cool, I want to get into creating some scripts as well in the future Edited February 12, 2021 by elusivestudio Link to comment Share on other sites More sharing options...
dragontitties 0 Author Share Posted February 12, 2021 Thanks! This makes total sense... I gotta study the API more Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now