Hongxing Ding
Hongxing Ding

Reputation: 11

How to fix netlogo 6.1.1 nothing named ? has been defined

I just started to learn Netlogo. I followed the code written by Lynne Hamill and Nigel Gilbert when I finished, it reminded me that "nothing named ? has been defined".

foreach xs [
    create-traders 1 [ 
      set shape "house"
      setxy ? 0
      set color red
      ; give each trader some knids of produce to sell
      set stock n-of n-items-stocked fruit-and-veg
    ]
  ]

Any ideas?

Upvotes: 1

Views: 302

Answers (1)

JenB
JenB

Reputation: 17678

As Jasper notes in the comments, the ? is outdated syntax. Something like this should work - instead of an implicit ?, you iterate with an explicit variable (named this-x in the example below) and use that variable name wherever relevant.

foreach xs [ this-x ->    ; name the variable here and add the arrow
    create-traders 1 [ 
      set shape "house"
      setxy this-x 0    ; use that variable name
      set color red
      ; give each trader some knids of produce to sell
      set stock n-of n-items-stocked fruit-and-veg
    ]
  ]

You can think about it as equivalent to the conceptual loop "for each item in the list, call it 'this-x' and do something (everything after ->), replacing the 'this-x' in the code with whatever item is in the list at the moment".

Upvotes: 2

Related Questions