I need your support as I'm using the (interact) command as a button it it gives me an error ( you can not use it as an observer context), as I need to make interaction in area = 1 among agents.the setup button as I defined 5 areas with agents with different colors, and I want them to move to area = 1 and interact as per their culture features
This is the code
breed [ parents parent ]
breed [ childrens children ]
patches-own [ area]
turtles-own [ my_area culture ]
to setup
ca
define_areas
create_parent
create_children
ask turtles [ set culture [] ]
ask turtles [ set my_area [area] of patch-here ]
repeat cultural_features
[ ask turtles [ set culture fput ( random traits_per_feature + 1 ) culture ] ]
reset-ticks
end
to define_areas
ask patches with [ (pxcor > -3) and (pxcor < 3) and (pycor > -3) and (pycor < 3) ] [ set pcolor white set area 1 ]
ask patches with [ (pxcor > 5 ) and (pxcor < 16 ) and (pycor > 4) and (pycor < 16) ] [ set pcolor white set area 2 ]
ask patches with [ (pxcor < -5 ) and (pxcor > -16 ) and (pycor > 4) and (pycor < 16) ] [ set pcolor white set area 3 ]
ask patches with [ (pxcor < -5 ) and (pxcor > -16 ) and (pycor < -4) and (pycor > -16) ] [ set pcolor white set area 4 ]
ask patches with [ (pxcor > 5 ) and (pxcor < 16 ) and (pycor < -4) and (pycor > -16) ] [ set pcolor white set area 5 ]
end
to create_parent
ask n-of Population patches with [ ( area = 2 ) ] [ sprout 1 [ set shape "person" set color green set size 1.5 ] ]
ask n-of Population patches with [ ( area = 3 ) ] [ sprout 1 [ set shape "person" set color red set size 1.5 ] ]
ask n-of Population patches with [ ( area = 4 ) ] [ sprout 1 [ set shape "person" set color blue set size 1.5 ] ]
ask n-of Population patches with [ ( area = 5 ) ] [ sprout 1 [ set shape "person" set color grey set size 1.5 ] ]
end
to create_children
ask n-of ( kids * ( Population / 2 ) ) patches with [ ( area = 2 ) ] [ sprout 1 [ set shape "person" set color green set size .5 ] ]
ask n-of ( kids * ( Population / 2 ) ) patches with [ ( area = 3 ) ] [ sprout 1 [ set shape "person" set color red set size .5 ] ]
ask n-of ( kids * ( Population / 2 ) ) patches with [ ( area = 4 ) ] [ sprout 1 [ set shape "person" set color blue set size .5 ] ]
ask n-of ( kids * ( Population / 2 ) ) patches with [ ( area = 5 ) ] [ sprout 1 [ set shape "person" set color grey set size .5 ] ]
end
to move_in_event
ask n-of random ( (count turtles with [ size = .5 ]) / 2 ) turtles with [ size = .5 ]
[ move-to one-of patches with [ (not any? other turtles-here) and ( area = 1 ) ] ]
end
to interact
; identifing the agent chosen
let selected_agent one-of turtles with [ area = 1 ]
print ( word "selected agent="" " selected_agent)
;; culture of selected_agent
let my_culture culture
print ( word "selected agent culture ="" "my_culture)
;; the agent chooses one neighbor
let chosen one-of neighbors with [ area = 1 ]
print ( word "chosen agent ="" "chosen)
;; identify the culture of her neighbor
let chosen_culture [culture] of chosen
print ( word "chosen agent culture ="" "chosen_culture)
; Creating a local variable to track the number of similarities between the
;agents and calculate the probabilities of interactions between two agents
let similarities 0
let position_different_traits []
; create a list from 0 to number of cultural features
let N_traits n-values cultural_features [ i -> i ]
print ( word "Number of traits to be compared ="" "N_traits)
; For each traits of the cultural features
foreach N_traits
[ i -> ifelse ( (item i my_culture) = (item i chosen_culture ))
[ set similarities similarities + 1 ]
[ set position_different_traits lput i position_different_traits ] ]
;; print out some information to check how does the procedure performs
print ( word "position_different_traits ="" "position_different_traits)
print ( word "number of similarities ="" "similarities)
; Calculate probability
let p ( similarities / cultural_features) * 100
print ( word "probability ="" "p)
; Calculate a random number between 1 & 100
let dice random 100 + 1
print ( word "Roll a die ="" "dice)
if (dice <= p)
[
ifelse(similarities != cultural_features)
[
let position_ one-of position_different_traits
print ( word "position_trait_to_be_changed in the agent="" "position_)
let replacement_item item position_ chosen_culture
print ( word "element to from chosen agent to be replaced in active agent culture="" "replacement_item)
set culture replace-item position_ culture replacement_item
print ( word "active agent culture updated ="" "culture)
]
[
]
]
; only for visualization purposes
ask selected_agent [ set color [ color ] of chosen]
ask chosen [ set color [ color ] of selected_agent ]
end