debdeep chatterjee
debdeep chatterjee

Reputation: 1

Netlogo Coding - IF codes

here is the issue that I am facing in Netlogo. I want a turtle to check one of its own variable and another variable of the other turtle (different breed). based on these 2 two values I want to set a reward for the turtle. Let's say that I have "student" and "teachers" as two breeds. Students may "cheat" (binary) and teachers may catch (binary) - so based on whether they cheat and get caught or not an appropriate reward would follow. I am trying to incorporate this by the following code

if comply? = 1
[ 
ask students [ set gain reward1 ] 
] 

if comply? = 0 and caught? < random-float 1
[
ask students [set gain reward2 ] 
] 

if comply? = 0 and caught? > random-float 1 
[ 
ask suppliers [set gain reward3 ] 
] 
end 

gain is a student own variable and caught? is a teacher-own variable which represents the chances that the teacher may catch a student.

When I run the model there is an error "STUDENTS breed does not own variable CAUGHT? error while running Student1 running Caught?

I was wondering if someone can share some insights about this? Thanks Deb

Upvotes: 0

Views: 82

Answers (1)

javylow
javylow

Reputation: 119

STUDENTS breed does not own CAUGHT? : Insight

When the ownership error pops up, usually, the issue is that a turtle, or in this case student, referenced a variable that does not belong to their breed. Below is an example of how I imagine the model was initialized for your code, along with a passing and failing example.

breed [ students student]
breed [ teachers teacher]

students-own [ gain comply?]
teachers-own [ caught? ]

... ; initialize
to go
  ask students [ set gain 3 ]    ; this passes
  ask students [ set caught? 3 ] ; this fails
end

The importance of context

Most likely your issue is related to adding conflicting variables in a procedure for students. (Example below)

to listen-in-class ; student procedure
  if comply? = 0 [ set gain 7 ]
  ; the comply? variable assumes a student is calling the procedure

  if gain = 3 [ set gain 4 ] 
  ; The gain variable assumes a student is calling the procedure

  if caught? = 0 [ set gain 2 ] 
  ; The caught? variable assumes a teacher is calling the procedure
end

Since procedures can call other procedures, each procedure assumes their environment (context) from the variables/procedures.

to starting-class ; should be a student procedure
   ask student [ listen-in-class ]
   ; "ask student" assumes listen-in-class only takes global or student only variables
end

Most likely, it could be that the wrong set of variables for a procedure was added. Asks tend to limit the scope of variables depending on the breed.

Upvotes: 1

Related Questions