Andrey
Andrey

Reputation: 11

Number of resources seized based on individual agent parameter

There are two types of agents - large and small. So, I introduced parameter parIsLarge, which is boolean (true is large, false is small). Large agent requires a combination of two units of resources - resourceA and resourceB. Small agent requires one unit of resource - either resourceA or resourceB.

First, I wanted to use a function but it failed to work. I replaced the function by code in seize block but it still doesn't work. The code to assign the right resources based on agent's parameter. This is the error encountered. Please help to correct the code

Upvotes: 1

Views: 47

Answers (2)

mczandrea
mczandrea

Reputation: 630

Using a separate function is neater, but the code you wrote can be written on a single line by using a ternary operator.

agent.parIsLarge ? new ResourcePool[][]{{resResourceA, resResourceB}} : new ResourcePool[][]{{resResourceA},{resResourceB}}

Upvotes: 0

Benjamin
Benjamin

Reputation: 12640

The Seize block code only allows 1 line of code, not several. Hence, you need to move your code into a separate function, say 'f_GetResourcePools`.

It should take 1 input argument agent of the type flowing through the seize block. And it should return a ResourcePool[][].

In the seize block, you simply call that function now using f_getResourcePools(agent). (not even a ; is needed!)

PS: Start learning about the difference between code boxes that allow as many code lines as you like and those that only allow 1 line. The latter is used where block characteristics are "asking" a question (in this case "which resource pools should be used?").

Upvotes: 1

Related Questions