Jump to content

Items in bank


Jammer

Recommended Posts

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.

 

Link to comment
Share on other sites

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 by Explv
Link to comment
Share on other sites

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 by Explv
  • Like 1
Link to comment
Share on other sites

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 :feels: 

  • Like 1
Link to comment
Share on other sites

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 by The Undefeated
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :) 

Link to comment
Share on other sites

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? 

 

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...