user17809837
user17809837

Reputation:

EMPTY? expected input to be a string or list but got the TRUE/FALSE false instead

I used "empty?" in many parts of the code and I don't understand the error in which part it refers exactly. I write here a part of code where I used 'empty?'. I don't understand what is wrong.

""ask shuttles [
     ifelse empty? onlyNodes = TRUE
    [ calc-short-shuttles
      ;get the original lists back
      set place last onlyNodes
      ;change the location (lew location is the prior destination)
      if place = node 98 [
        set destination "MilanoCentrale1"
      ]
      if place = node 191 [
        set destination "InnovationCampus1"
      ]
      if place = node 192 [
        set destination "InnovationCampus2"
      ]
      if place = node 219 [
        set destination "MilanoLinate1"
      ]
      calc-short-shuttles
      ;new shortest path for the way back
    ]""

Upvotes: 0

Views: 85

Answers (1)

LeirsW
LeirsW

Reputation: 2305

The order om which Netlogo tries to execute the different procedures is the problem here. If I would write it down using brackets, Netlogo is trying to: (ifelse (empty? (onlyNodes = TRUE)))

You can introduce brackets of yourself into your code when you are not sure in which order Netlogo would execute the procedure. This allows you to make sure that empty? is executed before = TRUE: ifelse (empty? onlyNodes) = TRUE

For this specific case, none of this actually matters.ifelse requires an input that is either TRUE or FALSE. = TRUE generates an output that is either TRUE or FALSE but so does empty?, so =TRUE is redundant.

ifelse empty? onlyNodes [<command1>][<command2>]

Upvotes: 1

Related Questions