0

I have turtles placed in the environment using GIS data. The model runs for 5 years. At the end of each year, based on the turtle's annual income, I am killing one turtle and I want to create a new turtle in the same GIS point where the previous turtle was. I am trying the line of code written below but I am getting the following error:

this code can't be run by a turtle, only the observer
error while TAK 6244 running GIS:CREATE-TURTLES-INSIDE-POLYGON
  called by (anonymous command: [ this-vector-feature -> gis:create-turtles-inside-polygon this-vector-feature TAK 1 [ set shape "house" set size 0.9 set color 17 ] ask minhealth [ die ] ])
  called by procedure less-profitable
  called by procedure GO
  called by Button 'go'

My code:

to less-profitable 
    let minhealth one-of RES with-min [annual-earnings-h]
     let minunhealth one-of TAK with-min [annual-earnings-nh]
     ifelse ([annual-earnings-nh] of minunhealth < [annual-earnings-h] of minhealth)
      [ask minhealth [foreach gis:feature-list-of healthy-dataset [this-vector-feature -> gis:create-turtles-inside-polygon this-vector-feature RES 1 [set shape "house" set size 0.9 set color 57] ask minunhealth [die]]]]
    [ask minunhealth [foreach gis:feature-list-of unhealthy-dataset [this-vector-feature -> gis:create-turtles-inside-polygon this-vector-feature TAK 1 [set shape "house" set size 0.9 set color 17] ask minhealth [die]]]]
    end
desertnaut
  • 57,590
  • 26
  • 140
  • 166
amik89
  • 11
  • 2

1 Answers1

0

Dislaimer: I am not well versed in the GIS package

GIS:CREATE-TURTLES-INSIDE-POLYGON is an observer context procedure. As such it can't be called by a turtle. You could however execute your procedure in observer context rather than in turtle context. Looking at your code, it seems that RES and TAK are relevant turtles-own variables that you are using to create your new turtle, but other than that I don't see any reason why you would have it operate in turtle context.

  ifelse ([annual-earnings-nh] of minunhealth < [annual-earnings-h] of minhealth)
   [
      let the-RES [RES] of minhealth
      foreach gis:feature-list-of healthy-dataset [this-vector-feature -> gis:create-turtles-inside-polygon this-vector-feature the-RES 1 [set shape "house" set size 0.9 set color 57] ask minunhealth [die]]
   ] [
      let the-TAK [TAK] of minunhealth
      foreach gis:feature-list-of unhealthy-dataset [this-vector-feature -> gis:create-turtles-inside-polygon this-vector-feature the-TAK 1 [set shape "house" set size 0.9 set color 17] ask minhealth [die]]
   ]

I was also wondering why the ask minhealth part is situated within the foreach. Currently you try to kill it once for each feature.

LeirsW
  • 2,070
  • 4
  • 18
  • Thank you! I tried and I get this error:Extension exception: Not a polygon feature error while observer running GIS:CREATE-TURTLES-INSIDE-POLYGON called by (anonymous command: [ this-vector-feature -> gis:create-turtles-inside-polygon this-vector-feature the-TAK 1 [ set shape "house" set size 0.9 set color 17 ] ask minhealth [ die ] ]) called by procedure IDENTIFY-LESS-PROFIT called by procedure GO called by Button 'go' – amik89 Jul 16 '23 at 15:16
  • I'm afraid I can't help any further, since that is an error with the extension of which I don't know enough. But hey, you got a different error and that is progress – LeirsW Jul 17 '23 at 11:28