Home > Software engineering >  Error using "n-of" command with a breed in Netlogo
Error using "n-of" command with a breed in Netlogo

Time:10-26

I'm running into trouble with using the "ask n-of # " command.. got an "expected number here, rather than a list or block" error message.

Added the main chunks of code that pertain to this error. Wondering if anyone can help?

Goal: Looking to have solar power charge only 6 of squad1 at a time (squad1 is my breed of 10 turtles). Annotated below...

    breed [squad1 squad1s]

    turtles-own
    [individual-power
    solar-delay
    power-count1
    count-recharge1]

Setup

    to setup 
    clear-all
    setup-patches
    setup-turtles
    reset-ticks
    end

    to setup-turtles
    create-squad1 10
    ask squad1
    [
    set color blue
    set shape "person"
    set size 1.7
    set individual-power 100
    set heading 90
    set solar-delay 0
    setxy random-xcor random-ycor
    ]
    end

To Go

    to go
    ask squad1 [
    if individual-power >= 15
    [forward 1
    set label individual-power
    set individual-power individual-power - 1
    set solar-delay solar-delay   1]

    if recharge-options1 = "external-solar1" [solar-battery1]
    ]
    tick
    end

Solar-Battery1 Code

**This is chunk of code I need help with. I get an "expected number here, rather than a list or block" message where Netlogo highlights everything right after "ask n-of 6 squad1s ["

    to solar-battery1
    ask n-of 6 squad1s [ 
    if solar-delay >= 85
    [set individual-power 15]
    if solar-delay >= 91 ; increase in 6 ticks..
    [set individual-power 100
    set individual-power individual-power - 1
    set solar-delay 0]
    ]
    end

CodePudding user response:

I think you just have your breed declaration backwards- it should be plural then singular forms. Try this toy model:

breed [squad1s squad1]

to setup
  ca
  create-squad1s 10 
  reset-ticks
end

to go
  ask n-of 6 squad1s [
    fd 1
  ]
end

You should see only 6 turtles moving per call to go. Note that if you change to this more common structure, you will need to update your other related calls from ask squad1 [ ... to ask squad1s.

If, however, you intended squad1 to be the plural, then your call to n-of should read as ask n-of 6 squad1 [....

  • Related