"create-links-with <parent>"?

94 views
Skip to first unread message

Unruh Lee

unread,
Jun 9, 2022, 11:37:12 AM6/9/22
to netlogo-users
There must be a way to specify "create-links-with <parent>", in code like the following, no? 

ask turtles
  [ hatch-<breeds> 1 [
    move-to one-of patches
     create-links-with <parent>
  ] ]
  
Thanks, 
Lee

Michael Tamillow

unread,
Jun 9, 2022, 11:58:47 AM6/9/22
to Unruh Lee, netlogo-users

--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/085f86b1-e7ac-401b-a5d0-974ea6d55163n%40googlegroups.com.

James Steiner

unread,
Jun 9, 2022, 12:50:20 PM6/9/22
to Unruh Lee, netlogo-users
First: i think you’ll need to use the singular form — create-link-with.  The plural form is used with agent setss 

Next: As Michael wrote so succinctly: “myself” refers to the agent that is making this agent do things. In this case it’s the agent that ran “hatch” and is therefore making the new agent run it’s initial code.

That value is dynamic, and myself has meaning ONLY when an agent is being called to do stuff by another agent. It is not a fixed reference to a “parent”

You’ve made a link, but it is non-directional; so it doesn’t explicitly record who is the parent. 

HOWEVER: Non-directional links use WHO number order to assign the agents to END1 and END2.  END1 is always the turtle with the smaller WHO, so it is always the older agent, so  in this case, [ END1 ] of the link between them is the parent. 

If you otherwise needed an agent to remember its creator, you could add a variable like “parent” and assign “myself” to it in the Hatch code. 

Likewise, you can use a local variable like “new-child”, assign SELF to it during hatching, then assign new-child to “child” after hatching. 

;; turtles-own [ parent child ]

To make-linked-child
;; run by a turtle
Let new-child nobody
Hatch 1 ;; breed is inherited
[ Set new-child self
   Set parent myself
   Set child nobody
   Create-link-with myself
    [ ;; link runs this
      ;; note that here,
      ;; myself will refer to the new turtle
      ;; that ran “create-link” 
      ;; note that [ myself ] of [ myself ] is just self. 
 ]
  Set child new-child
End



--

Unruh Lee

unread,
Jun 10, 2022, 3:27:44 PM6/10/22
to ja...@turtlezero.com, netlogo-users
Thank you both! Very helpful!
Lee
Reply all
Reply to author
Forward
0 new messages