gpt4 book ai didi

mit-scratch - 在 Scratch 中模拟自定义报告 block ?

转载 作者:行者123 更新时间:2023-12-01 15:32:28 27 4
gpt4 key购买 nike

在 Scratch 2.0 中,添加了对自定义堆栈 block (procedures) 的支持。但是有什么方法可以使用它来“抽象掉”返回值的逻辑吗?

例如,我这里有一个简单计算指数的脚本:( view graphic representation )

set [base v] to [2]
set [index v] to [3]
... // above is for initializing
set [result v] to (base)
repeat until <(index) = [1]>
set [result v] to ((result) * (base))
change [index v] by (-1)

我如何将此逻辑导出到“自定义报告程序”以重复使用?

最佳答案

这是一个例子(rendered):

define split [text] by [splitter]
delete (all v) of [output list v]
set [parse v] to [0]
set [cur string v] to []
repeat until ((parse) > (length of (splitter))
if <(letter (parse) of (text)) = (splitter)> then
add (cur string) to [output list v]
set [cur string v] to []
else
set [cur string v] to (join (cur string) (letter (parse) of (text)))
end
end

when GF clicked
split [Hello, world! Do you like this?] by [ ] // That's a space.

// That should output a list: ["Hello,", "world!", "Do", "you", "like", "this?"]

define the answer to life
set [output var v] to (42)

when GF clicked
the answer to life
say (output var)

它展示了如何同时使用列表输出和变量输出。

关于mit-scratch - 在 Scratch 中模拟自定义报告 block ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27948249/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com