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 8688 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(). Link to comment Share on other sites More sharing options...
elusivestudio 31 Share Posted February 12, 2021 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 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
Archived
This topic is now archived and is closed to further replies.