Jump to content

For loop freaking out?


todamach

Recommended Posts

	public void walkMine() throws InterruptedException {

		for (int i = 0; i < minePos.length; i++) {

			logger.debug(i);
			logger.debug("Walk.");
			map.walk(minePos[i]);
			logger.debug("Walking.");

			while (myPlayer().isMoving())
				sleep(250);

			boolean ar = true;

			Entity oreVein = objects.closest(DIRT_NAME);
			logger.debug("Found closest: " + oreVein.getPosition().toString());

			while (ar) {
				if (mineArea[i].contains(oreVein) && map.canReach(oreVein)) {
					if (!myPlayer().isAnimating() && !myPlayer().isMoving()) {

						if (myPlayer().isAnimating()) {
							sleep(random(150, 250));
						} else {
							camera.toEntity(oreVein, true);
							logger.debug("Mining.");
							oreVein.interact("Mine");
							
							while (oreVein.exists())
								sleep(random(150, 250));

						}

					}

					if (!oreVein.exists()) {
						logger.debug("Neegzistuoja oreVein");
						ar = false;
					}

				} else if (mineArea[i].contains(oreVein)
						&& !map.canReach(oreVein)) {
					logger.debug("In area, but can't reach.");
					mineRock();
				}

				else {
					logger.debug("Entity not in area.");

					ar = false;
				}
			}
		}
	}
ERROR][Bot #1][06/22 02:56:12 AM]: Error in bot executor!
java.lang.Error: Interrupted attempt to aquire write lock
	at javax.swing.text.AbstractDocument.writeLock(Unknown Source)
	at javax.swing.text.AbstractDocument.insertString(Unknown Source)
	at javax.swing.text.PlainDocument.insertString(Unknown Source)
	at javax.swing.JTextArea.append(Unknown Source)
	at org.osbot.utility.Logger.IIiiIIiiiI(v:73)
	at org.osbot.utility.Logger.IIiiIIiiiI(v:196)
	at org.osbot.utility.Logger.log(v:96)
	at org.osbot.utility.Logger.log(v:169)
	at org.osbot.utility.Logger.log(v:5)
	at org.osbot.utility.Logger.debug(v:60)
	at GameMiner.walkMine(GameMiner.java:122)
	at GameMiner.onLoop(GameMiner.java:161)
	at org.osbot.rs07.event.ScriptExecutor$InternalExecutor.run(ScriptExecutor.java:99)
	at java.lang.Thread.run(Unknown Source)

[DEBUG][Bot #1][06/22 02:56:06 AM]: 0
[DEBUG][Bot #1][06/22 02:56:06 AM]: Walk.
[DEBUG][Bot #1][06/22 02:56:06 AM]: Walking.
[DEBUG][Bot #1][06/22 02:56:06 AM]: Found closest: [x=3767, y=5657, z=0]
[DEBUG][Bot #1][06/22 02:56:06 AM]: Mining.
[DEBUG][Bot #1][06/22 02:56:06 AM]: 0
[DEBUG][Bot #1][06/22 02:56:06 AM]: Walk.
[DEBUG][Bot #1][06/22 02:56:06 AM]: Walking.
[DEBUG][Bot #1][06/22 02:56:06 AM]: Found closest: [x=3767, y=5657, z=0]
[DEBUG][Bot #1][06/22 02:56:06 AM]: Mining.
[DEBUG][Bot #1][06/22 02:56:06 AM]: 0
[DEBUG][Bot #1][06/22 02:56:06 AM]: Walk.
[DEBUG][Bot #1][06/22 02:56:07 AM]: Walking.
[DEBUG][Bot #1][06/22 02:56:07 AM]: Found closest: [x=3767, y=5657, z=0]
[DEBUG][Bot #1][06/22 02:56:07 AM]: Mining.
[DEBUG][Bot #1][06/22 02:56:07 AM]: 0
[DEBUG][Bot #1][06/22 02:56:07 AM]: Walk.
[DEBUG][Bot #1][06/22 02:56:07 AM]: Walking.
[DEBUG][Bot #1][06/22 02:56:07 AM]: 0
[DEBUG][Bot #1][06/22 02:56:07 AM]: Walk.
[DEBUG][Bot #1][06/22 02:56:07 AM]: Walking.
[DEBUG][Bot #1][06/22 02:56:07 AM]: 0
[DEBUG][Bot #1][06/22 02:56:07 AM]: Walk.
[DEBUG][Bot #1][06/22 02:56:07 AM]: Walking.
[DEBUG][Bot #1][06/22 02:56:07 AM]: 0
[DEBUG][Bot #1][06/22 02:56:07 AM]: Walk.
[DEBUG][Bot #1][06/22 02:56:07 AM]: Walking.
[DEBUG][Bot #1][06/22 02:56:07 AM]: 0
[DEBUG][Bot #1][06/22 02:56:07 AM]: Walk.
[DEBUG][Bot #1][06/22 02:56:07 AM]: Walking.
[DEBUG][Bot #1][06/22 02:56:07 AM]: 0
[DEBUG][Bot #1][06/22 02:56:07 AM]: Walk.
[DEBUG][Bot #1][06/22 02:56:08 AM]: Walking.
[DEBUG][Bot #1][06/22 02:56:08 AM]: 0
[DEBUG][Bot #1][06/22 02:56:08 AM]: Walk.
[DEBUG][Bot #1][06/22 02:56:08 AM]: Walking.
[DEBUG][Bot #1][06/22 02:56:08 AM]: 0
[DEBUG][Bot #1][06/22 02:56:08 AM]: Walk.
[DEBUG][Bot #1][06/22 02:56:08 AM]: Walking.
[DEBUG][Bot #1][06/22 02:56:08 AM]: 0
[DEBUG][Bot #1][06/22 02:56:08 AM]: Walk.
[DEBUG][Bot #1][06/22 02:56:08 AM]: Walking.
[DEBUG][Bot #1][06/22 02:56:08 AM]: 0
[DEBUG][Bot #1][06/22 02:56:08 AM]: Walk.
[DEBUG][Bot #1][06/22 02:56:08 AM]: Walking.
[DEBUG][Bot #1][06/22 02:56:09 AM]: 0
[DEBUG][Bot #1][06/22 02:56:09 AM]: Walk.
[DEBUG][Bot #1][06/22 02:56:09 AM]: Walking.
[DEBUG][Bot #1][06/22 02:56:09 AM]: 0
[DEBUG][Bot #1][06/22 02:56:09 AM]: Walk.
[DEBUG][Bot #1][06/22 02:56:09 AM]: Walking.
[DEBUG][Bot #1][06/22 02:56:09 AM]: 0
[DEBUG][Bot #1][06/22 02:56:09 AM]: Walk.
[DEBUG][Bot #1][06/22 02:56:09 AM]: Walking.
[DEBUG][Bot #1][06/22 02:56:09 AM]: 0
[DEBUG][Bot #1][06/22 02:56:09 AM]: Walk.
[DEBUG][Bot #1][06/22 02:56:09 AM]: Walking.
[DEBUG][Bot #1][06/22 02:56:09 AM]: 0
[DEBUG][Bot #1][06/22 02:56:09 AM]: Walk.
[DEBUG][Bot #1][06/22 02:56:09 AM]: Walking.
[DEBUG][Bot #1][06/22 02:56:09 AM]: Found closest: [x=3767, y=5657, z=0]
[DEBUG][Bot #1][06/22 02:56:10 AM]: Mining.
[DEBUG][Bot #1][06/22 02:56:10 AM]: 0
[DEBUG][Bot #1][06/22 02:56:10 AM]: Walk.
[DEBUG][Bot #1][06/22 02:56:10 AM]: Walking.
[DEBUG][Bot #1][06/22 02:56:10 AM]: Found closest: [x=3767, y=5657, z=0]
[DEBUG][Bot #1][06/22 02:56:10 AM]: Mining.
[DEBUG][Bot #1][06/22 02:56:10 AM]: 0
[DEBUG][Bot #1][06/22 02:56:10 AM]: Walk.
[DEBUG][Bot #1][06/22 02:56:10 AM]: Walking.
[DEBUG][Bot #1][06/22 02:56:10 AM]: Found closest: [x=3767, y=5657, z=0]
[DEBUG][Bot #1][06/22 02:56:10 AM]: Mining.
[DEBUG][Bot #1][06/22 02:56:10 AM]: 0
[DEBUG][Bot #1][06/22 02:56:10 AM]: Walk.
[DEBUG][Bot #1][06/22 02:56:11 AM]: Walking.
[DEBUG][Bot #1][06/22 02:56:11 AM]: Found closest: [x=3767, y=5657, z=0]
[DEBUG][Bot #1][06/22 02:56:11 AM]: Mining.
[DEBUG][Bot #1][06/22 02:56:11 AM]: 0
[DEBUG][Bot #1][06/22 02:56:11 AM]: Walk.
[DEBUG][Bot #1][06/22 02:56:11 AM]: Walking.
[DEBUG][Bot #1][06/22 02:56:11 AM]: Found closest: [x=3767, y=5657, z=0]
[DEBUG][Bot #1][06/22 02:56:11 AM]: Mining.
[DEBUG][Bot #1][06/22 02:56:11 AM]: 0
[DEBUG][Bot #1][06/22 02:56:11 AM]: Walk.
[DEBUG][Bot #1][06/22 02:56:11 AM]: Walking.
[DEBUG][Bot #1][06/22 02:56:11 AM]: Found closest: [x=3767, y=5657, z=0]
[DEBUG][Bot #1][06/22 02:56:11 AM]: Mining.
[DEBUG][Bot #1][06/22 02:56:11 AM]: 0
[DEBUG][Bot #1][06/22 02:56:11 AM]: Walk.
[DEBUG][Bot #1][06/22 02:56:11 AM]: Walking.
[DEBUG][Bot #1][06/22 02:56:11 AM]: Found closest: [x=3767, y=5657, z=0]
[DEBUG][Bot #1][06/22 02:56:11 AM]: Mining.
[DEBUG][Bot #1][06/22 02:56:11 AM]: 0
[DEBUG][Bot #1][06/22 02:56:11 AM]: Walk.
[DEBUG][Bot #1][06/22 02:56:12 AM]: Walking.
[DEBUG][Bot #1][06/22 02:56:12 AM]: Found closest: [x=3767, y=5657, z=0]
[DEBUG][Bot #1][06/22 02:56:12 AM]: Mining.
[DEBUG][Bot #1][06/22 02:56:12 AM]: 0
[DEBUG][Bot #1][06/22 02:56:12 AM]: Walk.
[DEBUG][Bot #1][06/22 02:56:12 AM]: Walking.
[DEBUG][Bot #1][06/22 02:56:12 AM]: Found closest: [x=3767, y=5657, z=0]
[DEBUG][Bot #1][06/22 02:56:12 AM]: Mining.
[DEBUG][Bot #1][06/22 02:56:12 AM]: 0
[DEBUG][Bot #1][06/22 02:56:12 AM]: Walk.
[DEBUG][Bot #1][06/22 02:56:12 AM]: Walking.
[DEBUG][Bot #1][06/22 02:56:12 AM]: Found closest: [x=3767, y=5657, z=0]

Why loop resets to 0? Why it doesn't execute rest of the code, and why it doesn't increase (i++)?

Link to comment
Share on other sites

1) You have wayy too many loops in loops. You are setting yourself up to be hit by errors. Try removing all of your while loops and using if statements. It is bad practice to use while loops in scripting. If you stop a script, its possible that the while loop can get stuck and keep executing even after stopping.

2) Where exactly does the error occur?

3) What is it supposed to do that it isnt doing properly?

 

Always give as many details as you can when asking for help so we can try and assist you better. ^_^

Link to comment
Share on other sites

1. I can't change my while loops to ifs. Main one (while(ar)) is used because I need loop there - I need that part of the code to run multiple times. I can't change that to if, because in that case it will run only one time. And same applies to other 2 while loops - I need bot to sleep while something is happening, not to sleep once.

 

3. It is supposed to go to the Position, take closest object, interact with it, when it's done, if there's no another object in the area - go to next area, take closest object, etc....

 

2. I start script, it goes to first Position (0),   clicks on object couple of times and crashes.


Ok, so I rewrote whole method, it works, but I have a problem with this part of code:

while (oreVein.exists()){
sleep(250);
logger.debug("Sleep while ore exists");
}




if (!oreVein.exists()) {
logger.debug("oreVein doesn't exist");
ar = false;
}

What I get:

[DEBUG][Bot #1][06/22 04:35:04 AM]: Sleep while ore exists
[DEBUG][Bot #1][06/22 04:35:04 AM]: oreVein doesn't exist

Even though oreVein exists. 

 

I just want to make bot sleep while oreVein exists. In other words, while there's ore, don't do anything and wait until it's mined.

Edited by todamach
Link to comment
Share on other sites

You should try to avoid using booleans, try to check 

 

Also NEVER EVER try to use while loops in scripts.(Except when using some Timer to prevent while loops geting stuck)

While loops are doomed to mess your script, instead use for loops or make better use of the onLoop method.

 

You can always add me on skype and i'll take a look at your script on how to solve your issue.

 

Skype is in my sigg

Edited by Khaleesi
Link to comment
Share on other sites

You should try to avoid using booleans, try to check 

 

Also NEVER EVER try to use while loops in scripts.(Except when using some Timer to prevent while loops geting stuck)

While loops are doomed to mess your script, instead use for loops or make better use of the onLoop method.

 

You can always add me on skype and i'll take a look at your script on how to solve your issue.

 

Skype is in my sigg

 

Don't give him false info, using while loops is totally fine if you know what to do with them

Link to comment
Share on other sites

You should try to avoid using booleans, try to check 

 

Also NEVER EVER try to use while loops in scripts.(Except when using some Timer to prevent while loops geting stuck)

While loops are doomed to mess your script, instead use for loops or make better use of the onLoop method.

 

You can always add me on skype and i'll take a look at your script on how to solve your issue.

 

Skype is in my sigg

 

Wuts wrong with while loops?

 

2014-06-23_16-31-46.png

 

Anyways @OT Yo code is really weird, can't really say much, but one thing

jtj30FG.png

 

It doesnt really make sense because your mine pos is len = 1, so you will never have i > 0 so you can search only for one area(0) i think you messed up everything lol

1. I can't change my while loops to ifs. Main one (while(ar)) is used because I need loop there - I need that part of the code to run multiple times. I can't change that to if, because in that case it will run only one time. And same applies to other 2 while loops - I need bot to sleep while something is happening, not to sleep once.

 

3. It is supposed to go to the Position, take closest object, interact with it, when it's done, if there's no another object in the area - go to next area, take closest object, etc....

 

2. I start script, it goes to first Position (0),   clicks on object couple of times and crashes.

Ok, so I rewrote whole method, it works, but I have a problem with this part of code:

while (oreVein.exists()){
sleep(250);
logger.debug("Sleep while ore exists");
}




if (!oreVein.exists()) {
logger.debug("oreVein doesn't exist");
ar = false;
}

What I get:

[DEBUG][Bot #1][06/22 04:35:04 AM]: Sleep while ore exists
[DEBUG][Bot #1][06/22 04:35:04 AM]: oreVein doesn't exist

Even though oreVein exists. 

 

I just want to make bot sleep while oreVein exists. In other words, while there's ore, don't do anything and wait until it's mined.

 

Here you probably have race condition. Maybe osbot store objects in cache and update them each tick aka 600ms ? I had this situations too.

 

  • Like 1
Link to comment
Share on other sites

Who says you can use while loos in a script, you just need to learn how to use it. You need to use the "break;" which helps exit a loop

 

nobody said you can't use biggrin.png

I just said you should try to avoid them because then can mess a script ahrd if you do it wrong.

 

Instead use the onLoop better wink.png

In the last 15 scripts I made I never used 1 while loop xD no fan of them at all =D

 

Guess that is everyone else thought and the way of programming I guess ^^

Programming is like a signature of someone, they will all be different.

Edited by Khaleesi
Link to comment
Share on other sites

nobody said you can't use biggrin.png

I just said you should try to avoid them because then can mess a script ahrd if you do it wrong.

 

Instead use the onLoop better wink.png

In the last 15 scripts I made I never used 1 while loop xD no fan of them at all =D

 

Guess that is everyone else thought and the way of programming I guess ^^

Programming is like a signature of someone, they will all be different.

 

But the point is

 

b = true; 
 for (; b;) {
            System.out.println(b = false);
        }

Its same as

 

   boolean b = true;
        while (b) {
            System.out.println(b = false);
        }

This is only matter of clean readable code. Generally we use for's when we know number of iteractions, we use while when we doesnt.

Anyways I'd rather use while(true) vs for(;;) etc.

So they will never mess up cuz u can do same thing with them

Link to comment
Share on other sites

 

Anyways @OT Yo code is really weird, can't really say much, but one thing

jtj30FG.png

 

It doesnt really make sense because your mine pos is len = 1, so you will never have i > 0 so you can search only for one area(0) i think you messed up everything lol

 

 

 

 

Yeah, I agree, my algorithm is very weird and not efficient. I created mineArea's with areas that cointains ores. Now, if i = 0, it goes to Area[0], mine all ores there, then goes to Area[1] and etc. Also, I changed this part of the code, after posting here. 

Entity oreVein = objects.closest(DIRT_NAME);

is now insade that while lopp.

 

 

 

Here you probably have race condition. Maybe osbot store objects in cache and update them each tick aka 600ms ? I had this situations too.

 

People in the other thread pointed out to me, that ores I was trying to mine were dynamic. It changes state even if it still exists. That's why this happened. 

BTW, really appreciate your help, and discussions wub.png

Link to comment
Share on other sites

Entity oreVein = objects.closest(DIRT_NAME);
 

should be 

RS2Object oreVein = objects.closest(DIRT_NAME);
 

Also, dont put that inside the while loop, put it inside a method. within the method create a while loop. Inside of your while loop add a condition. And use a break statement to end the while loop is the condition isnt what you want

 

example:

	public void method()	{
		RS2Object oreVein = objects.closest(DIRT_NAME);

		while (condition)	{
			if (orevein is still mine-able)	{
				sleep;
			}else{
				break;
			}
		}		
	}
Edited by josedpay
Link to comment
Share on other sites

But the point is

 

b = true; 
 for (; b;) {
            System.out.println(b = false);
        }

Its same as

 

   boolean b = true;
        while (b) {
            System.out.println(b = false);
        }

This is only matter of clean readable code. Generally we use for's when we know number of iteractions, we use while when we doesnt.

Anyways I'd rather use while(true) vs for(;wink.png etc.

So they will never mess up cuz u can do same thing with them

 

Ya I see :D

 

Just meant something else but can't really explain what -_- haha

but you are right! ^^

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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