Liz Lamperouge
Liz Lamperouge

Reputation: 681

Netlogo get nobody when trying to set players

I want to set the ball-owner, but It doesn't work and I have a nobody instead. Here my code:

to setup
  clear-all
  reset-ticks
  setup-players-red
  setup-players-blue
  setup-ball 
  print BALL-OWNER
end


to setup-ball
  create-balls 1 [
    setxy 5 -1
    set shape "ball basketball"
    set size 2.5
    set the-ball self
    set BALL-OWNER one-of players with [distance the-ball = 0]
    set owner BALL-OWNER
  ]
end

to setup-players-red
  create-players 1[
    set color red
    set shape "person"
    set size 5
    setxy (5)
    setxy (-1)
    set team "red"
  ]

end

to setup-players-blue 
create-players 1[
    set color blue
    set shape "person"
    set size 5
    setxy (-5)
    setxy (1)
    set team "blue" 
  ]
end

So why I have an "nodoby" print instead players 1/2? What am I doing wrong? I also try to put the

" set BALL-OWNER one-of players with [distance the-ball = 0]"

in the setup statement but I have the same result.

Upvotes: 0

Views: 119

Answers (1)

Luke C
Luke C

Reputation: 10291

If possible, try to submit code as a Minimum, Complete, and Verifiable Example so that users can just copy and paste your code into a blank NetLogo instance and run your model.

Your setxy code for the players is problematic- if that is fixed, I don't get the same error you describe- the code below runs for me:

globals [ ball-owner the-ball owner ]

breed [ players player ]
breed [ balls ball ]

players-own [ team ]

to setup
  clear-all
  reset-ticks
  setup-players-red
  setup-players-blue
  setup-ball 
  print BALL-OWNER
end


to setup-ball
  create-balls 1 [
    setxy 5 -1
    set shape "circle"
    set size 2.5
    set the-ball self
    set BALL-OWNER one-of players with [distance the-ball = 0]
    set owner BALL-OWNER
  ]
end

to setup-players-red
  create-players 1[
    set color red
    set shape "person"
    set size 5
    setxy 5 -1
    set team "red"
  ]

end

to setup-players-blue 
create-players 1[
    set color blue
    set shape "person"
    set size 5
    setxy -5 1
    set team "blue" 
  ]
end

Upvotes: 2

Related Questions