1

I'll give you a brief description of my model:

turtles can be red or green, omnivores and vegetarian respectively

two markets (blue squares): meat and substitutes (products that can be consumed instead of meat) market

When I run the model I would like that turtles start to buy meat or substitutes (only when they are in one of the two markets and based on the market they are in), if they are vegetarian and buy meat turn red while if they stop buying meat and buy only substitutes turn them green (after a certain amount of ticks, which I did not decide yet, they can be considered vegetarian).

to go
  move-turtles
  market
  tick
end

to market
  ask turtles
  [ ifelse pcolor = blue
    [buy]
    [right random 360 forward 1]
  ]
end

to buy
    if market-patches [set money money - Meat-Price]
    if market-patches1  [set money money - Substitutes-Price]  
    if money = 0 [stop]
end

I do not understand why when I try to run the model it gives me this error back, and I'm sure the error is contained in the last 3 ifs statements:

IF expected input to be a TRUE/FALSE but got the patch (patch 12 11) instead.

Also if you can help me to structure the go procedure I will be eternally grateful.

This is the overview of the model: model

TripleG
  • 21
  • 3
  • It looks like you solved the question you asked previously, labeling your blocks of patches. It's okay on StackOverflow to answer your own question, so I encourage you to add that info: https://stackoverflow.com/questions/67072718/netlogo-giving-a-name-to-a-block-of-patches – Jasper Apr 14 '21 at 13:00
  • I added a comment under my old post. – TripleG Apr 14 '21 at 13:09

1 Answers1

2

Okay, these are your key procedures:

to go
  move-turtles
  market
  tick
end

to market
  ask turtles
  [ ifelse pcolor = blue
    [buy]
    [right random 360 forward 1]
  ]
end

to buy
    if market-patches [set money money - Meat-Price]
    if market-patches1  [set money money - Substitutes-Price]  
    if money = 0 [stop]
end

The logic of your go procedure is that it calls the market procedure and that market procedure gets each turtle to look at the colour of the patch it is standing on - if the colour is blue then the turtle jumps to the buy procedure. What happens in the buy procedure? The turtle has to check whether if market-patches. What is the check that you actually want the turtle to make here? I think you mean 'if I am standing on a patch that is in the patchset named market-patches'. But NetLogo error message is telling you that you have not properly defined what you want the turtle to check.

So, to ask whether this patch that the turtle is standing on is in the market-patches patchset, you need the member? keyword. And a turtle can identify the patch it is standing on with patch-here. This is not tested, but I think it should fix your problem:

to buy
    if member? patch-here market-patches [set money money - Meat-Price]
    if member? patch-here market-patches1  [set money money - Substitutes-Price]  
    if money = 0 [stop]
end
JenB
  • 17,620
  • 2
  • 17
  • 45
  • Thanks, I edited my post. Your thinking is correct, however when I substituted my old "to buy" procedure with the new one that you suggested, it gave me this error: 'MEMBER? expected input to be a string or list or agentset but got the patch (patch 12 11) instead.' – TripleG Apr 14 '21 at 11:04
  • 1
    It's probably the way you set up the global variable market-patches (and market-patches1). Are they actually patchsets? – JenB Apr 14 '21 at 12:52
  • No, they aren't. How can I do that? I looked on netlogo dictionary but without success. I defined them as global variables. – TripleG Apr 14 '21 at 13:13
  • yes, but global variables of a patchset or of something else: `set market-patches patches with [...]` – JenB Apr 15 '21 at 14:15