How do I call a parent procedure's variable in netlogo

613 views Asked by At

In netlogo I have a procedure that calls another procedure. How can I go about getting the value

for example, I have two breeds of agents, a hub and a link. A hub has a local variable called 'budget' and I'm trying to modify its value.

hubs-own [
  budget
]

to go
  ask hub 0 [
    do-ivalue
  ]
end

to do-ivalue
  ask links [
    ;; I'm trying to set the local variable budget of the hub that's calling this link
    set self.budget newvalue ;; this is obviously wrong, how can I fix this?
  ]
end
2

There are 2 answers

2
Jose M Vidal On BEST ANSWER

what you want to do is use is 'myself', it refers to the caller (asker): the one who asked to run the code where the 'myself' is located.

to do-ivalue   
  ask links [
    ask myself [set budget 10]   ] 
end

The 'self' refers to the agent running the code. It is similar to 'this' in Java.

1
Badoet On

hmm. not sure why u want to do it this way.. what u can do for now is

ask links[ let new_value new_value_from_link ask hubs[ set budget new_value ] ]