Jump to content

How to sleep while game is loading?


DeEvade

Recommended Posts

I want my script to sleep after hoppings worlds, I'm having problems when my onLoop tries to define objects from the game, before it is properly loaded. Which is causing some issues. It works if i add a static sleep, but something like a conditional sleep would make it a lot more reliable and faster.  I tried using getGameState(), but it's always returning LOGGED_IN. Is there something that I've missed?

	@Override
	public int onLoop() throws InterruptedException {
		String state = getClient().getGameState().toString();
		if(state != "LOADING" && state != "HOPPING") {
			npc = getNpcs().closest(npcName);
	
			if(!getStore().isOpen()) {
				if(hasItems()) {
					if(area(npcName).contains(myPlayer())) {
						if(npc != null) {
							if(npc.exists()) {
								npc.interact("Trade");
								new Sleep(() -> getStore().isOpen(), 2000).sleep();
								buyOrSell();
							}
						} else {
							log("Npc is null");
						}
					} else {
						walkTo(npcName);
					}
	
				} else {
					getItems();
				}
			} else {
				buyOrSell();
			}
		} else {
			log("State: " + state);
		}
		return 10;
	}

 

Link to comment
Share on other sites

The proper way to compare strings is with .equals()

if(!"LOADING".equals(state) && !"HOPPING".equals(state)) {

You could also just compare directly to the enum

Client.GameState state = getClient().getGameState();
if(!Client.GameState.LOADING.equals(state) && !Client.GameState.HOPPING.equals(state)) {

There is a conditional sleep class: https://osbot.org/api/org/osbot/rs07/utility/ConditionalSleep2.html

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...