sina eslamizadeh
sina eslamizadeh

Reputation: 11

Error: this isn't something you can use set on netlogo

I am trying to write a piece of code which asks some of the turtles to calculate 2 parameters, compare them and then if one is lower than the other, subtracts a characteristic of turtles by 1. here is the code I wrote but I receive this error: "this isn't something you can use set on netlogo"

        set monthly-electricity-consumption random-float((monthly-electricity-demand * 1.2) - (monthly-electricity-demand * 0.8)) + (monthly-electricity-demand *
0.8)
   ask turtles with [shape = "triangle"] [
      if monthly-electricity-consumption > monthly-electricity-demand [
        set [company-loyalty-level] of self company-loyalty-level - 1]]

Do you have any advice?

Upvotes: 1

Views: 259

Answers (1)

Charles
Charles

Reputation: 4208

I'm assuming that the line

set [company-loyalty-level] of self company-loyalty-level - 1]]

is the line that generates the error. NetLogo does not allow one turtle to directly set the variables of another turtle by using the of construction. E.g.,

ask turtle 1 [set [company-loyalty-level] of turtle 2 (company-loyalty-level - 1)]

breaks that rule. In your case, by using self, turtle 2 and turtle 1 are the same turtle, but NetLogo will still throw that error. The line that you want is simply,

set company-loyalty-level company-loyalty-level - 1]]

Once you are within an ask, the variable is understood to be the one associated with the turtle being asked. The of self is not necessary.

Upvotes: 1

Related Questions