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.

Stopping/starting threads - help needed

Featured Replies

Hey everyone and happy new year!

This might be simple, but i can't get my head around how i'm to stop/pause a thread, and start it again after calling a method. I have been trying the following example, and it's working to some point, but breaks eventually and the threads will fail to run. I have also been reading about wait() and notifyAll(), but haven't been able to get that to work. Does anyone have some insight on this topic, that might be willing so share a snippet or give some tips?

AttackThread.interrupt();
MoveToRevenantsThread.interrupt();

teleport.run();

AttackThread = new Thread(attack);
MoveToRevenantsThread = new Thread(moveToRevenants);

Edited by OmegaJeppe
shorter title

  • OmegaJeppe changed the title to Stopping/starting threads - help needed
22 minutes ago, OmegaJeppe said:

Hey everyone and happy new year!

This might be simple, but i can't get my head around how i'm to stop/pause a thread, and start it again after calling a method. I have been trying the following example, and it's working to some point, but breaks eventually and the threads will fail to run. I have also been reading about wait() and notifyAll(), but haven't been able to get that to work. Does anyone have some insight on this topic, that might be willing so share a snippet or give some tips?

AttackThread.interrupt();
MoveToRevenantsThread.interrupt();

teleport.run();

AttackThread = new Thread(attack);
MoveToRevenantsThread = new Thread(moveToRevenants);

Why are you making a new thread for what looks to be each task?

  • Author
5 minutes ago, Gunman said:

Why are you making a new thread for what looks to be each task?

It's not every task, my main functionality is to always check for nearby enemies, and in that case teleport away. When enemies are nearby i have to control my other tasks/threads, and stop them so they dont take control over my mouse, which could cause problems to the teleporting part.

7 minutes ago, OmegaJeppe said:

It's not every task, my main functionality is to always check for nearby enemies, and in that case teleport away. When enemies are nearby i have to control my other tasks/threads, and stop them so they dont take control over my mouse, which could cause problems to the teleporting part.

Why don't you reverse it and make a thread that constantly scans for nearby enemies and then "pause" the main loop if one is so you can get away? That way you're only creating one new thread and you don't really need to do anything besides kill it on script exit

  • Author
3 minutes ago, Gunman said:

Why don't you reverse it and make a thread that constantly scans for nearby enemies and then "pause" the main loop if one is so you can get away? That way you're only creating one new thread and you don't really need to do anything besides kill it on script exit

I was trying that for a while, but i couldn't seem to find a way of taking control of the main main loop from the nearby enemies thread, and stopping it in the exact second a nearby enemy was approaching. The only thing i was able to do was to loop through the main script, and when it eventually finished what it was doing, it then received the request to stop - but then i was already dead.

If you know how to do it the other way around, that would also be perfect.

1 minute ago, OmegaJeppe said:

I was trying that for a while, but i couldn't seem to find a way of taking control of the main main loop from the nearby enemies thread, and stopping it in the exact second a nearby enemy was approaching. The only thing i was able to do was to loop through the main script, and when it eventually finished what it was doing, it then received the request to stop - but then i was already dead.

If you know how to do it the other way around, that would also be perfect.

Sounds like you're doing more than 1 interaction per cycle of the loop, probably why. And you could always call the script executor and pause it, forcing it to stop what it's doing, then resume after you're done. https://osbot.org/api/org/osbot/rs07/event/ScriptExecutor.html

  • Author
9 minutes ago, Gunman said:

Sounds like you're doing more than 1 interaction per cycle of the loop, probably why. And you could always call the script executor and pause it, forcing it to stop what it's doing, then resume after you're done. https://osbot.org/api/org/osbot/rs07/event/ScriptExecutor.html

Ahh interesting. So i would be able to call the script executor from the nearby enemies thread, pausing the main loop untill teleport is complete and then resuming it again?

9 minutes ago, OmegaJeppe said:

Ahh interesting. So i would be able to call the script executor from the nearby enemies thread, pausing the main loop untill teleport is complete and then resuming it again?

Not the cleanest of solutions, but yes, this will work.

  • Author
6 minutes ago, Gunman said:

Not the cleanest of solutions, but yes, this will work.

Alright, thanks a lot man, really been struggling with this one for quite some time - great to get some other eyes on the issue, so i can move on.

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.