문제

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
도움이 되었습니까?

해결책

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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top