Zirnek Posted April 25, 2023 Share Posted April 25, 2023 I want to call a method from my Main class from a method inside Another class, then have that method from Another class executed back in the Main class's onLoop() method. How can I do this? I've tried extending Main class, but that just crashes the script, and using static references obviously won't work for instanced one. Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted April 25, 2023 Share Posted April 25, 2023 26 minutes ago, Kayle7 said: I want to call a method from my Main class from a method inside Another class, then have that method from Another class executed back in the Main class's onLoop() method. How can I do this? I've tried extending Main class, but that just crashes the script, and using static references obviously won't work for instanced one. What I hear from this is that your design is not correct, scripts made in java just follow the general java conventions. Like when you are programming OOP, there should be 0 reason to call a method from the object to where you instanced the object. Without showing any code it;s kinda hard to see what you are trying to do. so enlighten us and we will see what I can do for you Quote Link to comment Share on other sites More sharing options...
Zirnek Posted April 25, 2023 Author Share Posted April 25, 2023 10 minutes ago, Khaleesi said: What I hear from this is that your design is not correct, scripts made in java just follow the general java conventions. Like when you are programming OOP, there should be 0 reason to call a method from the object to where you instanced the object. Without showing any code it;s kinda hard to see what you are trying to do. so enlighten us and we will see what I can do for you Say I have this in my Main class: private String loggerString =""; public void status(String log) { log(log); loggerString=log; } And I want to execute this in onLoop() as I write a method to do something in another class like safeSpot() in class Safespot. Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted April 25, 2023 Share Posted April 25, 2023 2 hours ago, Kayle7 said: Say I have this in my Main class: private String loggerString =""; public void status(String log) { log(log); loggerString=log; } And I want to execute this in onLoop() as I write a method to do something in another class like safeSpot() in class Safespot. Make it a public static void and then you can call it from your other class with MainClass.status("test") 1 Quote Link to comment Share on other sites More sharing options...
Gunman Posted April 25, 2023 Share Posted April 25, 2023 @Kayle7 Do what Khaleesi said or pass the instance to the class you want to call it from 1 Quote Link to comment Share on other sites More sharing options...
Zirnek Posted April 25, 2023 Author Share Posted April 25, 2023 (edited) 3 hours ago, Khaleesi said: Make it a public static void and then you can call it from your other class with MainClass.status("test") As I already mentioned at the start of my post, you cannot lump in static method with instanced one. public static void status(String log) { log(log); //<---INSTANCED method loggerString=log; } This will not work. 3 hours ago, Gunman said: @Kayle7 Do what Khaleesi said or pass the instance to the class you want to call it from I cannot move it over to every class I want to use it in, that's inefficient and won't work as I need the String "loggerString" to be used for onPaint(g). Edited April 25, 2023 by Kayle7 Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted April 25, 2023 Share Posted April 25, 2023 (edited) 3 hours ago, Kayle7 said: As I already mentioned at the start of my post, you cannot lump in static method with instanced one. public static void status(String log) { log(log); //<---INSTANCED method loggerString=log; } This will not work. I cannot move it over to every class I want to use it in, that's inefficient and won't work as I need the String "loggerString" to be used for onPaint(g). I don't think you understand what you are trying to do yourself at this point. You are trying to fix something thats completely misdesigned, it's like putting boat parts in a car and expecting it to work I also said to post some code, then you post 5 lines of code which could be anything in the world and you expect to get a proper answer -_-OOP I suggest you to learn java OOP properly to begin with Edited April 25, 2023 by Khaleesi Quote Link to comment Share on other sites More sharing options...
Gunman Posted April 25, 2023 Share Posted April 25, 2023 2 hours ago, Kayle7 said: I cannot move it over to every class I want to use it in, that's inefficient and won't work as I need the String "loggerString" to be used for onPaint(g). Static references in general are usually really bad in scripting, and I want to avoid much as possible. Welcome to OOP, it's shit Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted April 25, 2023 Share Posted April 25, 2023 6 minutes ago, Gunman said: Welcome to OOP, it's shit It's great, but can't expect to master it after a few hours of playing around 1 Quote Link to comment Share on other sites More sharing options...
Zirnek Posted April 25, 2023 Author Share Posted April 25, 2023 9 minutes ago, Khaleesi said: You are trying to fix something thats completely misdesigned, it's like putting boat parts in a car and expecting it to work I also said to post some code, then you post 5 lines of code which could be anything in the world and you expect to get a proper answer -_- I suggest you to learn java properly to begin with This is very basic stuff you should know after a few hello worlds apps Yet you can't give me a straight answer to this 'basic' problem. A few lines of code for a simple and straight forward point to be made, there's no reason to paste my whole fucking class in here of redundant code. Just forget it, seems your understanding of Java isn't as great as your ego. Pitiful. 1 Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted April 25, 2023 Share Posted April 25, 2023 (edited) 3 hours ago, Kayle7 said: I cannot move it over to every class I want to use it in, that's inefficient and won't work as I need the String "loggerString" to be used for onPaint(g). Nothing wrong with passing around the Methodprovider object. You can also extend the second class from MethodProvider and then exchange bot context, that way you can use log("") in your other class. public class SecondClass extends MethodProvider { public void execute(){ log("Test"); FirstClass.status = "Test"; } public static String status = ""; private SecondClass secondClass; public void onStart() { secondClass = new SecondClass(); secondClass.exchangeContext(getBot()); } public int onLoop() { secondClass.execute(); } public void onPaint(Graphics2D g) { g.drawString("Status: " + status ,10, 10); } 33 minutes ago, Kayle7 said: Yet you can't give me a straight answer to this 'basic' problem. A few lines of code for a simple and straight forward point to be made, there's no reason to paste my whole fucking class in here of redundant code. Just forget it, seems your understanding of Java isn't as great as your ego. Pitiful. Ofc mister know it all who can't write a "hello world" app in java using OOP Your ego is like the complete opposite from your coding skills at this point, how can you be this cocky while YOU are asking for help in the first place? Be gratefull anyone wants to help in the first place, but no... let's flame them right away. Good way to make friends Edited April 25, 2023 by Khaleesi 3 1 Quote Link to comment Share on other sites More sharing options...
Zirnek Posted April 25, 2023 Author Share Posted April 25, 2023 (edited) 30 minutes ago, Khaleesi said: java using OOP Your ego is like the complete opposite from your coding skills at this point, how can you be this cocky while YOU are asking for help in the first place? Be gratefull anyone wants to help in the first place, but no... let's flame them right away. Good way to make friends I don't want to be friends with anybody here, I don't need help, I realize it was a mistake to engage any conversation here, and you are a fool to assume I have absolutely no skills just because I don't waste my whole fucking life away chatting to nobodies on the internet. Your perception of who I am is worthless and indifferent to me. So long. Edited April 25, 2023 by Kayle7 Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted April 25, 2023 Share Posted April 25, 2023 (edited) 36 minutes ago, Kayle7 said: I don't want to be friends with anybody here, I don't need help, I realize it was a mistake to engage any conversation here, and you are a fool to assume I have absolutely no skills just because I don't waste my whole fucking life away chatting to nobodies on the internet. Your perception of who I am is worthless and indifferent to me. Critisim, learn to deal with it if you ask to fix your code Edited April 25, 2023 by Khaleesi Quote Link to comment Share on other sites More sharing options...
SuperMario Posted April 25, 2023 Share Posted April 25, 2023 5 minutes ago, Khaleesi said: Learn to deal with critisim Keep dreaming, you might find a good one sooner or later ^^ Im not involved in this discussion but could you please give me a free trial of your crafting script, want to try it out. Sorry g 1 Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted April 25, 2023 Share Posted April 25, 2023 Just now, SuperMario said: Im not involved in this discussion but could you please give me a free trial of your crafting script, want to try it out. Sorry g This made me laugh Ofcourse man! Enjoy 1 1 Quote Link to comment Share on other sites More sharing options...