Titan Rs Posted August 18, 2018 Share Posted August 18, 2018 Hi Guys, been at this for a couple hours now. Not sure whats wrong. I have my GUI class and main class. When i try to run script nothing happens - The script doesnt even start Any help would be greatly appreciated. package gui; import javax.swing.*; import javax.swing.border.EmptyBorder; import enums.Food; import org.osbot.J; import java.awt.*; public class GUI { private final JDialog mainDialog; private final JComboBox<Food> foodSelector; private boolean started; public GUI() { //Main Dialog mainDialog = new JDialog(); mainDialog.setTitle("Luke's Progressive SandCrab's"); mainDialog.setModal(true); mainDialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL); //Main Panel - inside Main Dialog JPanel mainPanel = new JPanel(new BorderLayout()); mainDialog.getContentPane().add(mainPanel); //Title Panel - inside Main Panel JPanel titlePanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); titlePanel.setBorder(new EmptyBorder(5, 5, 5, 5)); mainPanel.add(titlePanel, BorderLayout.NORTH); //Title Label - inside Title Panel JLabel titleLabel = new JLabel("Jona's Progressive SandCrab's"); titlePanel.add(titleLabel); //Contents Panel - inside Main Panel JPanel contentsPanel = new JPanel(); contentsPanel.setLayout(new BoxLayout(contentsPanel, BoxLayout.Y_AXIS)); mainPanel.add(contentsPanel, BorderLayout.WEST); //Food Panel - inside Contents Panel JPanel foodPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); foodPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); contentsPanel.add(foodPanel); // foodLabel - inside Food Panel JLabel foodLabel = new JLabel("Whitch Food"); foodLabel.setBorder(new EmptyBorder(0, 0, 0, 2)); foodPanel.add(foodPanel); // foodComboBox - inside Food Panel foodSelector = new JComboBox<>(Food.values()); foodPanel.add(foodSelector); // Start Panel - inside Main Panel JPanel startPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); mainPanel.add(startPanel, BorderLayout.SOUTH); // StartButton - inside Start Panel JButton startButton = new JButton("Start"); startButton.addActionListener(e -> { started = true; close(); }); startPanel.add(startButton); //Packing it all mainDialog.pack(); } // Checking if Start button has been pressed public boolean isStarted(){ return started; } //Open the GUI public void open() { mainDialog.setVisible(true); } //Close GUI public void close() { mainDialog.setVisible(false); mainDialog.dispose(); } //Get the selected food from the user public Food getSelectedFood() { return (Food) foodSelector.getSelectedItem(); } } package script; import enums.Food; import gui.GUI; import org.osbot.rs07.api.map.constants.Banks; import org.osbot.rs07.api.ui.Message; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import javax.swing.*; import java.lang.reflect.InvocationTargetException; @ScriptManifest(name = "ProgressiveCrabKiller", version =1.0 , author = "luke", logo = "", info = "") public class CrabKiller extends Script{ private GUI gui = new GUI(); private Food food; @Override public void onStart() throws InterruptedException { log("in OnStart"); try { SwingUtilities.invokeAndWait(() -> { gui = new GUI(); gui.open(); }); } catch (InterruptedException | InvocationTargetException e) { e.printStackTrace(); stop(); return; } if (!gui.isStarted()) { stop(); return; } food = gui.getSelectedFood(); } @Override public int onLoop() throws InterruptedException { getWalking().webWalk(Banks.EDGEVILLE); return 250; } @Override public void onExit() throws InterruptedException { if (gui != null) { gui.close(); } } } package enums; public enum Food{ TROUT("Trout"), SALMON("Salmon"), TUNA("Tuna"), CAKE("Cake"), LOBSTER("Lobster"), SWORDFISH("Swordfish"), MONKFISH("Monkfish"), SHARK("Shark"); private String name; Food(String name) { this.name = name; } public String getName() { return name; } @Override public String toString() { return name; } } Quote Link to comment Share on other sites More sharing options...
liverare Posted August 19, 2018 Share Posted August 19, 2018 if (!gui.isStarted()) { stop(); return; } This is your problem. The onStart method is executed in its entirety and, before it's even rendered, you're checking whether the GUI has been started. It hasn't. You need to move this part of your code into your onLoop. Additionally, you need to give the user time to click the button. What I suggest is: @Override public int onLoop() { if (!gui.isStarted()) { if (gui.isVisible()) { // Do nothing (or spin camera to avoid auto-logout) } else { // User closed GUI without clicking start button, so stop stop(); } } else { // Normal bot stuff here... } return 500; } 1 Quote Link to comment Share on other sites More sharing options...