Liam Mason
Liam Mason

Reputation: 3

Netlogo Patch can't access a turtle variable without specifying which turtle

Im trying to setup a procedure to change the colour of the outer patches of my cell-like patches so that it can be easily identified which cell is which. So far I have the below code but im getting issues when trying to go-once the program. Code is below

globals [
  radius 
]
patches-own [
  patch-state
  CellID
]

to setup
  clear-all
  set radius 2
  create-turtles #cells [
    ifelse mode =  "Restricted"
    [ setxy random-float #units - random-float #units random-float #units - random-float #units ]
    [ setxy random-xcor random-ycor ]
   ]
  reset-ticks
end

to go
  expand-cells
  make-membrane
  tick
end

to expand-cells
  set radius radius + 1
  ask turtles [ ask patches in-radius radius [
    if pcolor = black or CellID = [who] of myself + 1 [
      build-up-cells 
    ]
   ]
  ]
  ask patches with [ pcolor = black ] [
   set patch-state "X"
  ]
end

to build-up-cells
  set pcolor [ color ] of myself
  set CellID [who] of myself + 1
end

to make-membrane
  ask patches with [pcolor != black] [
    ifelse not any? neighbors with [ CellID = [who] of myself + 1 ]
    [ set patch-state "I" ]
    [ set patch-state "M" ]
  ]
  ask patches with [ patch-state = "M" ] [
    set pcolor pcolor - 1
  ]
  trim
end

to trim
end

Error im getting is this: A patch can't access a turtle variable without specifying which turtle. error while patch 40 6 running OF called by procedure MAKE-MEMBRANE called by procedure GO called by Button 'go-once'

Upvotes: 0

Views: 253

Answers (1)

LittleLynx
LittleLynx

Reputation: 1181

The error results from the wrong usage of who. If you take a look into the Netlogo dictionary, you will see that who is a turtle variable, but you run make-membrane on the patches.

I guess, what you want to do is check, if there are any neighbors, that don't belong to the same cells (i.e. don't have the same CellID), and if so, make that patch a membrane patch.

ifelse any? neighbors with [ CellID != [CellID] of myself]
    [ set patch-state "M" ]
    [ set patch-state "I" ]

Upvotes: 2

Related Questions