Josh Finkill
Josh Finkill

Reputation: 27

Saving data from dead turtles to a CSV NetLogo

I am using NetLogo to create a simulation modelling bees visiting flowers and pollinating them. I need to understand genetic diversity. Therefore to know possible patches that the pollen came from I am recording the location of every flower a turtle visits. This data is saved as a turtle variable, I was then hoping when a turtle pollinates a flower (visits a patch after it has enough pollen stored) it gives that list to the patch. Although it wont allow me to as the list of flowers visited is a turtle variable. Is there any way around this?

patches-own [
  scent
  fertilisation_list
]

turtles-own [
  pollen
  energy
  xy_list
]

to pollenate
  ask turtles [
    if (pollen > pollen-required-to-fertalise) and ((pcolor = yellow) or (pcolor = blue))
    [
      set pcolor white
      set pollen pollen - pollen-required-to-fertalise
      ask patches [ 
        set fertilisation_list xy_list
      ]
    ]
  ]
end

to record-patch
  ask turtles [
    if ((pcolor = yellow) or (pcolor = white) or (pcolor = blue)) [
  set xy_list fput patch-here xy_list
    ]
  ]
end


to setup-patches
  ask patches[
    if random 100 < number-of-flowers [ set pcolor yellow]
  ]
  ask patches [
    if ( pcolor = yellow )
    [ set scent 50
    ]
  ]
  ask patches [
    set fertilisation_list (list 0 0)
  ]
end

to setup-bees
  create-turtles number-of-bees
  ask turtles [ setxy 0 0 ]
  ask turtles [ set color red]
  ask turtles [
  set xy_list (list 0 0)
  ]
end

The above code is most of the relevant information when storing the lists spoken about.

I get the error ' you cant use xy_list in a patch context bexause xy_list is turtle only'

Is there a way around this?

Upvotes: 1

Views: 113

Answers (1)

Charles
Charles

Reputation: 4168

There is a way, with of.

ask patches [ 
        set fertilisation_list [xy_list] of myself
]

Since xy_list belongs to the turtle, but the ask puts you in patch context, you need to tell the patch whose xy_list to copy. myself refers to the agent who asked, in this case the turtle. But do you really want to ask all patches, or just the single patch on which the bee is sitting? If the latter, you should ask patch-here.

Upvotes: 1

Related Questions