5

I have small issue with a NetLogo tutorial. I have the following situation:

to-report get-best-action

   let x xcor

   let y ycor

   let dir heading

   let best-action 0

   let best-utility -100000

   foreach actions[

      set heading dir

      run ?

      let utility-of-action get-utility xcor ycor heading

      if (utility-of-action > best-utility) [
          set best-action ?
          set best-utility utility-of-action
      ] 
      setxy x y
      set heading dir
  ]
  report (list best-action best-utility)

end

AND...

ask patches [

foreach headings [

    let x pxcor

    let y pycor

    let dir ?

.......

In any of the presented case, the identifier '?' is considered not defined. It should work because the identifier is used the same way even in the examples of foreach. Check https://ccl.northwestern.edu/netlogo/docs/programming.html .

Did I do something wrong? Does anybody know another solution, because I tried to use an item i and the behavior of the project has been modified. (Check the project: https://www.youtube.com/watch?v=dBDVkPjyYF4 )

I would appreciate your help. Thank you!

Isa
  • 51
  • 2
  • 2
    Are you using NetLogo 6? If so, you must know that the syntax for commands like `foreach` has changed significantly, and the tutorial you are using may be out of date. See: https://ccl.northwestern.edu/netlogo/docs/transition.html#v60. (Let us know: if you're using NetLogo 6, we can help you with the new syntax...) – Nicolas Payette Dec 28 '16 at 18:12
  • I am observing now that I am using the 6.0 version. – Isa Dec 29 '16 at 11:12
  • 1
    I have changed the specific lines to : foreach actions [[a] -> run a ] and it works. No more errors for now, but the behavior of the project is still not according to the tutorial. I am concerned about all the modification for NetLogo 6. Debugging continues. Thank you!! – Isa Dec 29 '16 at 11:14
  • Glad you figured it out! As far as I know, only the syntax has changed, not the behavior. Feel free to open a different question if you are running into a specific issue... – Nicolas Payette Dec 29 '16 at 13:43
  • Thought it was time this actually had an answer. It's a good question. – TurtleZero Nov 01 '21 at 21:46

1 Answers1

1

In NetLogo before version 6, the symbols ? ?1 ?1 and so on were used as placeholders in some primitives, especially those that processed list items.

In version 6 a new syntax was introduced using "anonymous" procedures. You can make your old code using ? or ?1, etc work with few changes by adding the new syntax elements to the statement block.

Title Code
Single ? placeholder Extra space added to emphasize changes
Old syntax foreach [ 1 2 3 4 ] [ show ? ]
New syntax foreach [ 1 2 3 4 ] [ ? -> show ? ]
Multiple ?1 ?1 placeholders Extra space added to emphasize changes
Old syntax (foreach [1 2] ["a" "b"][ show (word ?1 ?2)]
New syntax (foreach [1 2] ["a" "b"][ [?1 ?2] -> show (word ?1 ?2)]
TurtleZero
  • 1,013
  • 7
  • 15