Jump to content

Script compiling fine, OSBot not running it.


djric733

Recommended Posts

I've got an issue where whenever I run a script from OSBot, it won't actually run the script. The logger shows everything up to "Started bot #1", then nothing after I hit play on the script.

I've refreshed the scripts interface a bunch of times and restarted OSBot quite a few times now, to no avail.

Here's my code:

https://pastebin.com/16bH6f2d

There are two bits there. the top half is my CombatManager class, the bottom half is the chunk of code in my main file that actually uses that class. I've already been using the omitted code for the bot extensively, so I know the issue is coming from somewhere inside of the combat behavior. Anyone have any idea why it won't work?

Link to comment
Share on other sites

Well, the first thing is you need to be null checking before calling any method on an object like a widget or npc.
If that doesn't fix your issues, then start printing debug statements after every action to get a chain of events to pinpoint what's causing the problem.
Also remove that recursive call in changeAttackStyle() and add a conditional sleep or something after changing tabs.

Edited by Hawk
Link to comment
Share on other sites

6 hours ago, Hawk said:

Well, the first thing is you need to be null checking before calling any method on an object like a widget or npc.
If that doesn't fix your issues, then start printing debug statements after every action to get a chain of events to pinpoint what's causing the problem.
Also remove that recursive call in changeAttackStyle() and add a conditional sleep or something after changing tabs.

Alright, I'll go back through and add that stuff in.

3 hours ago, ez11 said:

 you need this

I've got the Skeleton all defined and running, that much works fine. It's when I swap the bot over to the combat modules (that I put in that pastebin) that it has issues.

Link to comment
Share on other sites

6 hours ago, Czar said:

Show us the main script's code, or just onStart/onLoop so we know everything's fine there. It could be an unhandled exception try wrapping your onStart and onLoops around a [try for] catch and log any issues that arise.

The part in the pastebin inside of

else if (currState == Skill.ATTACK || currState == Skill.DEFENCE || currState == Skill.STRENGTH)

is inside of the onLoop of the main script. When I comment it out everything works fine, but it's when I leave it uncommented that OSBot won't load the script.

Edit to add: How do I wrap onLoop into a try/catch if it's an Override?

Edited by djric733
Link to comment
Share on other sites

private CombatManager cm = new CombatManager(myPlayer(), gearNames, lummyCows, lootables);

this needs to be:

private CombatManage cm;

and then in onLoop, you can do:

if (cm == null && myPlayer() != null) {
	// once player exists, and if cm isn't instantiated, create one.
	cm = new CombatManager(myPlayer(), gearNames, lummyCows, lootables);
}

This can also be done in onStart but the player may either be logged out while the script is running and maybe not everything has been initialised just yet so it's better in onloop. If anyone has any recommendations or anything to contribute let us know xD

So it's generally recommended to only instantiate stuff after the script starts, so that myPlayer() has meaning/context. Before the script runs it's null so you're essentially giving null parameters to the CombatManager class. Variables declared outside methods will execute before everything else, so you need to be wary of that xD If the above code still doesn't work we may need to see some more code to help

Edited by Czar
Link to comment
Share on other sites

17 minutes ago, Czar said:

private CombatManager cm = new CombatManager(myPlayer(), gearNames, lummyCows, lootables);

this needs to be:

private CombatManage cm;

and then in onLoop, you can do:


if (cm == null && myPlayer() != null) {
	// once player exists, and if cm isn't instantiated, create one.
	cm = new CombatManager(myPlayer(), gearNames, lummyCows, lootables);
}

This can also be done in onStart but the player may either be logged out while the script is running and maybe not everything has been initialised just yet so it's better in onloop. If anyone has any recommendations or anything to contribute let us know xD

So it's generally recommended to only instantiate stuff after the script starts, so that myPlayer() has meaning/context. Before the script runs it's null so you're essentially giving null parameters to the CombatManager class. Variables declared outside methods will execute before everything else, so you need to be wary of that xD If the above code still doesn't work we may need to see some more code to help

Ahhhh, that does make sense. I ended up removing the CombatManager call and that did fix it, and I just now re-implemented it with your suggestion and it worked. Thanks a bunch for the help!

  • Like 1
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...