dimanche 20 décembre 2015

netlogo: nested ifelse cannot access the last ifelse command

I have three level of ifelse command. I attempt to make an agent to do something by comparing 2 variable of different agent. A brief description about the ifelse command.

Procedure 1 & 2 attempt to compare variable of two different agent on the same patch and do something; else

Procedure 3 attempt to compare variable of two agent on different patch in radius 2, then do something ; else.

Problem : When I run procedure 1 and 3 (disable procedure 2) OR procedure 2 and 3 (disable procedure 1), code is fine. But when I tried to run the whole procedure, it can't access [do something] command on procedure 3.

My code looks like this;

to cocreate-value1
  ask capabilities-here
    [ let this-resource one-of resource
     ask one-of prevalues-here  
      [ ifelse value = this-resource
             [ use-resource ]
             [ cocreate-value2]
      ] ]
end

to cocreate-value2
  ask capabilities-here
  [ let this-knowledge one-of knowledge 
    ask one-of prevalues-here   
    [ ifelse value = this-knowledge
      [use-knowledge ]
      [cocreate-value3]
    ] ]
end

to cocreate-value3
   ask one-of other capabilities in-radius 2 
       [let resource2 sentence (resource) (knowledge)
        let this-resource2 one-of resource2
        let new-cap capabilities with [one-of resource = this-resource2] 
        ask prevalues-here 
            [ ifelse value = this-resource2
                [ask capabilities-here
                  [if any? other new-cap in-radius 2 
                     [ create-link-to one-of other new-cap in-radius 2
                       set color white]] ;; this code is not executed
                       use-network ] ;; this one too
                      [set color yellow ]
 ]]
end

Can anyone find the problem? Thank you for your help

Aucun commentaire:

Enregistrer un commentaire