Deathimminent Posted June 25, 2017 Share Posted June 25, 2017 I am trying to retrieve my player's name and print it to the screen. Why doesn't this work? I try to start the script and nothing happens. import java.awt.Graphics2D; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; @ScriptManifest(author = "Death", info = "", logo = "", name = "GetPlayerName", version = 0) public class GetPlayerName extends Script { String myName = myPlayer().getName(); @Override public int onLoop() throws InterruptedException { return random(400,800); } @Override public void onPaint(Graphics2D g) { g.drawString("My Name: " + myName, 11, 280); } } Quote Link to comment Share on other sites More sharing options...
Deathimminent Posted June 25, 2017 Author Share Posted June 25, 2017 Figured it out. myPlayer() can only be called from one of the overriden methods. Assuming that's the case for all methods inherited from MethodProvider? When do the objects from MethodProvider get created? During onStart()? Quote Link to comment Share on other sites More sharing options...
Team Cape Posted June 25, 2017 Share Posted June 25, 2017 (edited) 46 minutes ago, Deathiminent said: Figured it out. myPlayer() can only be called from one of the overriden methods. Assuming that's the case for all methods inherited from MethodProvider? When do the objects from MethodProvider get created? During onStart()? Any calls to MethodProvider need to happen in or after onStart(). Also, your player will need to be logged in to retrieve myPlayer() if I'm not mistaken. Edit: This thread belongs in Script Help. Please make it there next time Edited June 25, 2017 by Imateamcape Quote Link to comment Share on other sites More sharing options...
Alek Posted June 25, 2017 Share Posted June 25, 2017 You seemed to find out the random method pretty quickly. 1 Quote Link to comment Share on other sites More sharing options...
Tom Posted June 25, 2017 Share Posted June 25, 2017 10 hours ago, Alek said: You seemed to find out the random method pretty quickly. Well duh, he would get banned in 10 seconds without it! Quote Link to comment Share on other sites More sharing options...
Doflamingo Posted June 28, 2017 Share Posted June 28, 2017 (edited) I'm going to spoon feed you, but teach you. g.drawString("My Name: " + myName, 11, 280); // This is your code g.drawString("My Name: " + myPlayer().getName(), 11, 280); // This is my code myPlayer() is a call to a method that returns an object of the Player type. It's method signature looks like public Player myPlayer() { return thisObject; } You now have a reference to your player object, which contains methods and variables. Using dot notation, you call a method defined in the Player class. getName() is a call to a String returning method in the Player class.. public String getName() { return nameVariable; } To experiment with the methods, go to the osbot api, and find the Player class, and check out the methods you can use. You can then call those methods like this -> myPlayer().methodName() ** Note methods may or may not require parameters. Anyways this was more than enough help, please give me a thanks if you found this helpful! - Doflamingo Edited June 28, 2017 by Doflamingo Quote Link to comment Share on other sites More sharing options...
Explv Posted June 28, 2017 Share Posted June 28, 2017 55 minutes ago, Doflamingo said: I'm going to spoon feed you, but teach you. g.drawString("My Name: " + myName, 11, 280); // This is your code g.drawString("My Name: " + myPlayer().getName(), 11, 280); // This is my code myPlayer() is a call to a method that returns an object of the Player type. It's method signature looks like public Player myPlayer() { return thisObject; } You now have a reference to your player object, which contains methods and variables. Using dot notation, you call a method defined in the Player class. getName() is a call to a String returning method in the Player class.. public String getName() { return nameVariable; } To experiment with the methods, go to the osbot api, and find the Player class, and check out the methods you can use. You can then call those methods like this -> myPlayer().methodName() ** Note methods may or may not require parameters. Anyways this was more than enough help, please give me a thanks if you found this helpful! - Doflamingo I don't see how any of that was relevant to OP's original question, and his question was already answered correctly 3 days ago. 3 Quote Link to comment Share on other sites More sharing options...