Add a new agent to a population and assign 2 variables

18 views Asked by At

I have a cyclic event in which 4 times a day, if the inventory is greater than 1 pallet, I want to create a new agent and add it to the population pop_palletsLine1 AND assign the pallet variable v_toLineFrom = "Silo" and the pallet variable v_movementNbr = 6. I know to assign one variable I could do

if (v_inventorySiloMalt >= p_lbPerPallet) {
    add_pop_palletsLine1().v_toLineFrom = "Silo";
}

But to assign 2 variables I can't do

if (v_inventorySiloMalt >= p_lbPerPallet) {
    add_pop_palletsLine1().v_toLineFrom = "Silo";
    add_pop_palletsLine1().v_movementNbr= 6;
}

because that adds 2 agents to my population, each with 1 of the variables assigned. Any suggestions? Thank you!

1

There are 1 answers

0
Benjamin On

Fair question. The add_xxx function actually returns the agent it just created. So you can store it temporarily and do with it what you like:

if (v_inventorySiloMalt >= p_lbPerPallet) {
    MyPalletLine newPalletLine = add_pop_palletsLine1();
    newPalletLine.v_toLineFrom = "Silo";
    newPalletLine.v_movementNbr= 6;
}

This assumes your agent type is called MyPalletLine