Zho:分身的侦测

In order to detect properties of specific 分身. a variety of 清单s and local 变量s need to be used. Local variables are duplicated with a clone's properties, but a sprite cannot detect an individual clone's local variable's value. However, a clone can detect a sprite, which can therefore send a message to trigger the sprite's scripts. In order for a sprite to detect the properties of a clone, the clone must use lists in order to "communicate" with the sprite.

Sensing When Touching a Clone
To make a sprite detect when it is touching a specified clone of a specified sprite, the clone must sense instead when it is touching the sprite. Then, it adds a "true" to the item number corresponding to the clone in a list of true/false touching clones. For the following scripts, assume the following: These following scripts would go in sprite1
 * (clones) a global variable used to count how many clones have been created.
 * (clone id) a local variable duplicated with the clone that represents what clone number in chronological order of creation it is. (ex. Clone 5)
 * (touching?) // category=list a list used to store the true/false statements for each clone if its touching the specified sprite.
 * Sprite1 the sprite which creates the clones
 * Sprite2 the sprite that will sense when touching one of sprite1's clones

當 @greenflag 被點擊 // when the flag is clicked 刪除第 [全部 v] 項 \( [touching? v] \) 變數 [clones v] 設為 (0) // set the current amount of clones to 0

新增項目 [] \( [touching? v] \) // adds a new item to the list, representing the upcoming clone's "touching sprite2" statement 變數 [clones v] 改變 (1) // right before cloning, change the amount of clones by one 分身 [自己 v] 建立 // clone

當分身產生 變數 [clone id v] 設為 (clones) // this sets the clone's number to the amount of clones there are, since it is the most recent to be created 重複無限次 如果 <碰到 [sprite2 v] ?> 那麼 替換第 (clone id) 項於 [touching? v] 成 [true] // then, in the item number of "touching?" of the clone's number, "true" is inserted to show it is being touched 等待直到 <<碰到 [sprite2 v] ?> 不成立> // the clone waits until it is not touching sprite2 anymore 替換第 (clone id) 項於 [touching? v] 成 [false] // turns the statement to false end // this senses if the clone is touching sprite2 end Then, the following script would be inserted into sprite2, which will detect when touching the specified clone: 當 @greenflag 被點擊 重複無限次 移動 (3) 點 右轉 @turnright (3) 度 // just for example 如果 <(item (4) of [touching? v] :: list) = [true]> 那麼 說出 [Hi there, clone 4!] (2) 秒 end // if item 4 of the list is "true", that means clone 4 is touching sprite2, and vice-versa end

Making Connections
There are too many boolean reporter sensing arguments to have each one stated. Whether one is sensing a clone's costume, local variable, or x and y coordinates, the method above can be used with some minor tweaks. For example, to sense a clone's costume, instead of the clone checking if it is touching sprite 2 and then adding "true" to a list, a different list can be used called "costumes" in which each clone perpetually stores its costume#, allowing for, in the scenario above, sprite 2 to check the costume# of an individual, particular clone. In alternative to the clone's script above, this can be used for costume detection: 當分身產生 變數 [clone id v] 設為 (clones) 重複無限次 替換第 (clone id) 項於 [costumes v] 成 (costume#) end Therefore, sprite2's script would have to be modified as the following: 當 @greenflag 被點擊 重複無限次 如果 <(item (4 v) of [costumes v] :: list) = [2]> 那麼 說出 [Clone 4 is in costume 2] // for example end // meaning if clone 4's costume# is 2 end

参见

 * 分身的进阶用法
 * 分身制作粒子效果的方式