0

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
David C
  • 3,659
  • 5
  • 34
  • 46

2 Answers2

1

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.

Jose M Vidal
  • 8,816
  • 6
  • 43
  • 48
  • so if I replace 'myself' with 'self' it would then refer to the individual link? – David C Feb 12 '11 at 12:27
  • yes, 'self' would be the link. It would be silly, since 'ask self [doit]' is the same as 'doit', except maybe if you hear voices in your head telling you to do things. – Jose M Vidal Feb 14 '11 at 01:46
0

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 ] ]

Badoet
  • 21
  • 2
  • Hi Badoet, that would be a good alternative but I'd like to find out how to call the parent's variable in case I ever need it. – David C Feb 12 '11 at 08:20