djric733 Posted October 26, 2020 Share Posted October 26, 2020 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? Quote Link to comment Share on other sites More sharing options...
Gunman Posted October 26, 2020 Share Posted October 26, 2020 Try isolating sections of code off until it works and narrow the problem down Quote Link to comment Share on other sites More sharing options...
Czar Posted October 26, 2020 Share Posted October 26, 2020 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. 1 Quote Link to comment Share on other sites More sharing options...
Hawk Posted October 26, 2020 Share Posted October 26, 2020 (edited) 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 October 26, 2020 by Hawk Quote Link to comment Share on other sites More sharing options...
ez11 Posted October 26, 2020 Share Posted October 26, 2020 you need this Quote Link to comment Share on other sites More sharing options...
djric733 Posted October 26, 2020 Author Share Posted October 26, 2020 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. Quote Link to comment Share on other sites More sharing options...
djric733 Posted October 26, 2020 Author Share Posted October 26, 2020 (edited) 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 October 26, 2020 by djric733 Quote Link to comment Share on other sites More sharing options...
Czar Posted October 26, 2020 Share Posted October 26, 2020 (edited) 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 October 26, 2020 by Czar Quote Link to comment Share on other sites More sharing options...
djric733 Posted October 26, 2020 Author Share Posted October 26, 2020 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! 1 Quote Link to comment Share on other sites More sharing options...