user12092724
user12092724

Reputation:

Error: You can't use % in a turtle context, because % is observer only

I know that there are a lot of questions (and answers) about this error, but unfortunately I have not fixed the error in my code, not yet, even following the past answers. I hope you can help me on this. I know that something does not work because of ask one-of A, but I have no any other idea how implement it in a different way, in order to ask an agent to create a new object. The error messages comes when I call the procedure create_object in go.
The breed A is owner of agenda. The breed object is owner of att1

to go
  ifelse random-float 1 < 0.5
  [ ask one-of A
     [
      ifelse empty? agenda

      [ ifelse random-float 1 < 0.5
        [create_object]  ;; this returns the error message
        [remove_object] 
      ]
     ]
   ]
[...]
end

The error comes from create_object. This is defined as follows

to create_object

  create-object 1[
          hide-turtle
          set att1 random-float 1  
          let this-post myself ; is it the same object that I am creating?
        if (condition1= TRUE)
              [set agenda fput this-post agenda] ; this should add the object in the agent A's list
         ]
end

I do not know if you require more code. Feel free to comment it if you need more information.

Thanks

Upvotes: 0

Views: 826

Answers (1)

JenB
JenB

Reputation: 17678

Are 'A' and 'object' both breeds of turtles? If so, you have a turtle (of breed A) calling a procedure in which it is trying to create a turtle (of breed object). However, if you look at the Netlogo dictionary, you will see that create-turtles (and other forms like create-object) is only valid when used by the observer, not when used by a turtle.

If you want a turtle to create a new turtle, you need the hatch command. Note that the newly hatched turtle will have the same attributes (such as position) as the parent turtle.

Upvotes: 0

Related Questions