Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Starting the script with a "start" button

Featured Replies

I've been working on my first GUI but I have NO idea on how to start my script.

I'm a little mind-kcuf'd right now since I'm working with two classes, the GUI and the Main where everything happens.

I know I should be using a listener for my button "start" but then I have no idea what should be inside the action-listener body. Should I call the onLoop() method? If so, how?

I have searched a lot of GUI tutorials on this forums & google in general but cant seem to find anything. 

Would love to get any help possible.

 

Edited by Ragboys is back

Have a global boolean called started that you set to be true inside the action-listener body. Then have an if (started) check in your onLoop.

private void openGUI(){
    GUI gui = new GUI(this);
    try{
        while(gui.isGuiActive()){ //1
            sleep(500);
        }
    }
    catch (InterruptedException e){
        log(e.toString());
    }
}
confirmButton.addActionListener(e -> {
        guiActive = false; //2
        frame.dispose();
    }
});

One implementation is under onStart() you could put some code like above. 

1. In your GUI class a boolean value (that is retrieved via gui.isGuiActive()) denotes whether the user is finished with the gui (pressed start). Until then, wait. 

2. you denote that a user is finished with the Gui by flipping said boolean value to false when your start button is pressed (in your listener for your start button). 

Basically you are delaying the conclusion of onStart() until the user is finished with the GUI. Then you proceed to onLoop() afterwards. 

11 minutes ago, PayPalMeRSGP said:

private void openGUI(){
    GUI gui = new GUI(this);
    try{
        while(gui.isGuiActive()){ //1
            sleep(500);
        }
    }
    catch (InterruptedException e){
        log(e.toString());
    }
}

confirmButton.addActionListener(e -> {
        guiActive = false; //2
        frame.dispose();
    }
});

One implementation is under onStart() you could put some code like above. 

1. In your GUI class a boolean value (that is retrieved via gui.isGuiActive()) denotes whether the user is finished with the gui (pressed start). Until then, wait. 

2. you denote that a user is finished with the Gui by flipping said boolean value to false when your start button is pressed (in your listener for your start button). 

Basically you are delaying the conclusion of onStart() until the user is finished with the GUI. Then you proceed to onLoop() afterwards. 

Small, but important addition:

Your button should also set the GUI to not be visible. This is done by frame.setVisible(false) in the context of the code that @PayPalMeRSGP wrote

5 hours ago, d0zza said:

Have a global boolean called started that you set to be true inside the action-listener body. Then have an if (started) check in your onLoop.

I recommend you not using this. If the script list is not refreshed, the static fields will keep their values. So as soon as someone stops the script and starts it again without refreshing the list, it will start instantly and probably crash.

35 minutes ago, Canidae said:

I recommend you not using this. If the script list is not refreshed, the static fields will keep their values. So as soon as someone stops the script and starts it again without refreshing the list, it will start instantly and probably crash.

I never said it should be static?

8 hours ago, d0zza said:

I never said it should be static?

Java doesn't really have global variables. So as soon as someone refers to a "global variable" in Java, people will interpret it as a static variable because they share some of their properties.

Edited by Canidae

7 hours ago, Canidae said:

Java doesn't really have global variables. So as soon as someone refers to a "global variable" in Java, people will interpret it as a static variable because they share some of their properties.

Yes but scripting for osbot does have global variables.

Edited by d0zza

6 hours ago, d0zza said:

Yes but scripting for osbot does have global variables.

I don't get what you mean?

2 minutes ago, Canidae said:

I don't get what you mean?

You can have global variables in a script

3 minutes ago, d0zza said:

You can have global variables in a script

What do you mean with global variables then? They don't exist in Java and you also said your meaning of global variables aren't (public) static variables. What is it then? The only thing you can do in Java is having public classes with a public static variable in it to make it look like it's some sort of global variable.

 

Edited by Canidae

3 minutes ago, Canidae said:

What do you mean with global variables then? They don't exist in Java and you also said your meaning of global variables aren't (public) static variables. What is it then? The only thing you can do in Java is having public classes with a public static variable in it to make it look like it's some sort of global variable.

 

Open up any script you've written, then go inside the script manifest but not inside any method, type int foo = 1; and there's your global variable.

11 minutes ago, d0zza said:

Open up any script you've written, then go inside the script manifest but not inside any method, type int foo = 1; and there's your global variable.

I have no clue what you mean.

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.