3

I have a stock agent which is created in the end of my production line. My products are characterized by their model. I'm trying to create a logic to take out the products from this stock agent when they are to be delivered to the client. This delivery is controlled by an excel sheet and I'm taking the information through a SQL code. However, I was not able to find the right code to take out the products which are to be delivered. My agent population is called ProdutoStock and it's located in my main screen.

I have tried: Main.remove_ProdutoStock() but i couldn't figure out the arguments that i need for this function, since i have to take out of the agent a specific number of agents and also of a specific model.

So, I decided to create a wait block and use the free function to free the specific agents i wanted main.waiting_delivery.free() but i also can't figure out the necessary arguments for this function.

Would someone have any idea how I can take out of my agent/line the products that I need to deliver for my client (considering quality and also model)? This code is not being typed into my main screen.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

1

the argument of the free method is the agent itself.

So you have to do main.waiting_delivery.free(yourAgent);

If you want to free the last agent that entered the wait block:

if(main.waiting_delivery.size()>0)
    main.waiting_delivery.free(main.waiting_delivery.get(0));

If you want to free agents following a certain condition

List <YourAgent> theAgents=findAll(main.yourAgentPopulation,a->a.condition==true);
for(YourAgent a : theAgents){
    main.waiting_delivery.free(a);
}
Felipe
  • 8,311
  • 2
  • 15
  • 31
  • 1
    Thank you for the reply! My code is now formulated as: `List theAgents = findAll(main.ProdutoStocks, a -> a.TypeOfProduct == ModelType); for(ProdutoStock a: theAgents){ main.waiting_delivery.free(a); }` my question is: how can i free only a specific amount of products in this condition? – Renata mariani Mar 21 '19 at 12:29
  • 2
    make a counter int counter=0; increment it by one after each loop with counter++; and then use the break: if(counter>something) break; the break takes you out of the for loop – Felipe Mar 21 '19 at 21:23