Jammer Posted November 25, 2017 Author Share Posted November 25, 2017 I'm not sure if I understand the whole concept of the task system. (not specific to the buy gear problem) @Explv So for example in my on start method I have these tasks. public void onStart() { ManTasks.add(new Eat(this)); ManTasks.add(new BuyStuff(this)); ManTasks.add(new BankTask(this)); ManTasks.add(new WalkToNpc(this)); ManTasks.add(new FightNpc(this)); } So if I understand this correctly it will go through the list and see if any of the "can process" or booleans methods in each task is true. If it is true it will go through the "process method" in the task and execute the methods that can be exectued. After that it will continute down the task list and this goes on. In my buyStuff boolean i check if (!current weapon is in inventory or bank or equiped) so let's say I'm at GE and I don't have the required weapon nor cash in my inventory so It opens the bank. Here's what confuses me tho. Now it will go down and check if BankTask is true, which is true since I don't have any Items on me or any food and if I would have food on me WalkToNpc would execute. To combat this I would need to add a lot of extra checks in every boolean method under BuyStuff. So if I had a task called mule I would need to add a heck ton of checks to the other methods. As far as I know this isn't necessary if you use states or just simple if else statements in an onloop like this: if(shouldbuy){ all the code for buying } else if(shouldbank){ all the code for banking } else if(shouldWalkToNpc{ } Here the shouldbank will never execute as long as shouldbuy is true right? Here it seems like we have a priority but not with the task system. So basically it feels like I need to add tons of checks in canprocess method in every task since it doesn't "start over" from the top once a task has been executed. Sorry if the question is unclear. Quote Link to comment Share on other sites More sharing options...
Explv Posted November 25, 2017 Share Posted November 25, 2017 (edited) 14 minutes ago, Jammer said: So basically it feels like I need to add tons of checks in canprocess method in every task since it doesn't "start over" from the top once a task has been executed. Sorry if the question is unclear. When you loop through the tasks, you could always break the loop once you process a task so that it starts over from the top. Edited November 25, 2017 by Explv Quote Link to comment Share on other sites More sharing options...
The Legman Posted November 25, 2017 Share Posted November 25, 2017 4 minutes ago, Explv said: When you loop through the tasks, you could always break the loop once you process a task so that it starts over from the top. How do you get it to break out of the loop, like half way through? WOuld it be to put if something else break Quote Link to comment Share on other sites More sharing options...
Jammer Posted November 25, 2017 Author Share Posted November 25, 2017 2 minutes ago, Explv said: Yes, that is why the so called "Task" pattern is terrible Now I understand why you discourage people from using it. Thanks Quote Link to comment Share on other sites More sharing options...
Explv Posted November 25, 2017 Share Posted November 25, 2017 (edited) 3 minutes ago, The Legman said: How do you get it to break out of the loop, like half way through? for (final Task task : tasks) { if (task.canProcess()) { task.process(); break; } } 1 minute ago, Jammer said: Now I understand why you discourage people from using it. Thanks Please see my edited comment, I did not fully read yours. Edited November 25, 2017 by Explv 1 Quote Link to comment Share on other sites More sharing options...
Jammer Posted November 25, 2017 Author Share Posted November 25, 2017 5 minutes ago, Explv said: for (final Task task : tasks) { if (task.canProcess()) { task.process(); break; } } Please see my edited comment, I did not fully read yours. This was exactly what I was looking for. I wonder why I haven't seen anyone using this before? Quote Link to comment Share on other sites More sharing options...
HeyImJamie Posted November 25, 2017 Share Posted November 25, 2017 54 minutes ago, Jammer said: This was exactly what I was looking for. I wonder why I haven't seen anyone using this before? Idk why you'd use a task system or where you even got a task system that doesn't break after processing a task Quote Link to comment Share on other sites More sharing options...
Jammer Posted November 26, 2017 Author Share Posted November 26, 2017 18 minutes ago, HeyImJamie said: Idk why you'd use a task system or where you even got a task system that doesn't break after processing a task I looked at a tutorial and some guy's script. It was a smaller script so I guess thats why it worked for him. Glad I found this out tho. Quote Link to comment Share on other sites More sharing options...
HeyImJamie Posted November 26, 2017 Share Posted November 26, 2017 21 minutes ago, Jammer said: I looked at a tutorial and some guy's script. It was a smaller script so I guess thats why it worked for him. Glad I found this out tho. Ah fair. I can't imagine writing anything without the break feature considering I store everything in 'relative' sections 1 Quote Link to comment Share on other sites More sharing options...
The Undefeated Posted November 27, 2017 Share Posted November 27, 2017 (edited) On 26-11-2017 at 1:15 AM, Jammer said: I looked at a tutorial and some guy's script. It was a smaller script so I guess thats why it worked for him. Glad I found this out tho. Vilius his tutorial about tasks sucks a bit. Just because he doesn't note anything about breaking the loop after running 1 tasks which makes the order of the tasks useless. You would have to add checks for every task to make sure it doesn't run after a certain task. Edited November 27, 2017 by The Undefeated Quote Link to comment Share on other sites More sharing options...
Jammer Posted November 27, 2017 Author Share Posted November 27, 2017 3 hours ago, The Undefeated said: Vilius his tutorial about tasks sucks a bit. Just because he doesn't note anything about breaking the loop after running 1 tasks which makes the order of the tasks useless. You would have to add checks for every task to make sure it doesn't run after a certain task. Right, that’s what fucked everything up when the script got more complex. Quote Link to comment Share on other sites More sharing options...
Viston Posted November 27, 2017 Share Posted November 27, 2017 5 hours ago, Jammer said: Right, that’s what fucked everything up when the script got more complex. I don't use the task pattern much. But I did use it before, and to eliminate your problem, I used to have a global Boolean, which I just use as a toggle on/off button to activate certain tasks when condition is met. E.g. If X items are not in bank > Toggle buyItems boolean to true if the buyItems boolean is true, it'll buy the items, once the items have been bought > Toggle buyItems boolean to false It's not a good way to do that I would assume. But yeah, as Explv have said, try to avoid the task pattern if you can, maybe stick to onLoop etc Quote Link to comment Share on other sites More sharing options...
Jammer Posted November 27, 2017 Author Share Posted November 27, 2017 34 minutes ago, Viston said: I don't use the task pattern much. But I did use it before, and to eliminate your problem, I used to have a global Boolean, which I just use as a toggle on/off button to activate certain tasks when condition is met. E.g. If X items are not in bank > Toggle buyItems boolean to true if the buyItems boolean is true, it'll buy the items, once the items have been bought > Toggle buyItems boolean to false It's not a good way to do that I would assume. But yeah, as Explv have said, try to avoid the task pattern if you can, maybe stick to onLoop etc I solved it by storing all the items in an arraylist that updates everytime I use the bank. I'll try to use explv's approach for my next script. Quote Link to comment Share on other sites More sharing options...
HeyImJamie Posted November 27, 2017 Share Posted November 27, 2017 1 hour ago, Jammer said: I solved it by storing all the items in an arraylist that updates everytime I use the bank. I'll try to use explv's approach for my next script. Having a method to handle bank items is much more useful than just re-arranging your task setup as this way your method can be used for anything. IMO anyway I'd still recommend putting it into a hashmap instead of an arraylist though as you can grab the name/amount this way. Let me know if you want any help with it Quote Link to comment Share on other sites More sharing options...
Jammer Posted November 27, 2017 Author Share Posted November 27, 2017 2 hours ago, HeyImJamie said: Having a method to handle bank items is much more useful than just re-arranging your task setup as this way your method can be used for anything. IMO anyway I'd still recommend putting it into a hashmap instead of an arraylist though as you can grab the name/amount this way. Let me know if you want any help with it I think I was unclear. I meant that I store all the items in the bank in an arraylist and then I check if the best gear I can have is there. If it isn't I check if I have enough cash and if so, I buy it. Or maybe you meant something else? I'll try to change it into a hashmap since I'm gonna need it for stuff like food anyway. And btw, do you know of a smart way of assigning a price to every item in the hashmap? Quote Link to comment Share on other sites More sharing options...