NetLogo-如何从阵列设置海龟颜色

NetLogo-如何从阵列设置海龟颜色,netlogo,Netlogo,如何从数组中设置海龟的颜色 这是我的代码,但它不起作用: let colors array:from-list ["red" "yellow" "blue" "pink"] set index random 3 let c array:item colors index set color array:item colors index 这导致了这个错误: can't set flower variable COLOR to non-number blue error while flower

如何从数组中设置海龟的颜色

这是我的代码,但它不起作用:

let colors array:from-list ["red" "yellow" "blue" "pink"]
set index random 3
let c array:item colors index
set color array:item colors index
这导致了这个错误:

can't set flower variable COLOR to non-number blue error while flower 101 running SET

尝试将颜色名称设置为数值,根据

尝试将颜色名称设置为数值,根据

在NetLogo color中,14种主要颜色的名称加上黑色和白色被定义为常量,因此不需要引号。此外,由于它们是常量,因此被视为文字值,因此您可以在括号中的列表表示法中使用它们,否则,您需要使用(list…)reporter来创建该列表

此外,数组的使用可能比需要的更复杂

你可以写:

let colors [ red green blue yellow ]
set index random 3
let c item colors index
set color c
作为额外奖励,您可以使用primitive中的一个来执行上述所有操作:

set color one-of [ red green blue yellow ]

在NetLogo颜色中,14种主要颜色的名称加上黑色和白色被定义为常量,因此不需要引号。此外,由于它们是常量,因此被视为文字值,因此您可以在括号中的列表表示法中使用它们,否则,您需要使用(list…)reporter来创建该列表

此外,数组的使用可能比需要的更复杂

你可以写:

let colors [ red green blue yellow ]
set index random 3
let c item colors index
set color c
作为额外奖励,您可以使用primitive中的一个来执行上述所有操作:

set color one-of [ red green blue yellow ]

接受的答案是正确的,但请注意,该函数将基本NetLogo颜色名称解释为颜色值:

observer> show read-from-string "red"
observer: 15
了解内置函数也很有用,该函数将14种基本NetLogo颜色的数组报告为数值,允许您执行以下操作:

ask turtles [ set color one-of base-colors ]

接受的答案是正确的,但请注意,该函数将基本NetLogo颜色名称解释为颜色值:

observer> show read-from-string "red"
observer: 15
了解内置函数也很有用,该函数将14种基本NetLogo颜色的数组报告为数值,允许您执行以下操作:

ask turtles [ set color one-of base-colors ]
哦,我不知道“底色”。。。我希望它在NetLogo 5中是新的,而不是我已经错过多年的东西!非常感谢。哦,我不知道“底色”。。。我希望它在NetLogo 5中是新的,而不是我已经错过多年的东西!非常感谢。