如何在Roblox Studio中更新模块脚本的变量?
2021-10-15 9:58:31
收藏:0
阅读:238
评论:2
我有scriptOne
(模块)和scriptTwo
(我认为是本地脚本)。我使用scriptTwo
来require()
并更改这些变量。但是如何将scriptOne
中的值更新到这些新值(我也想从其他脚本中访问)?
scriptOne代码
local module = {}
module.test = 100
while true do
wait(1)
print(module.test)
end
return module
scriptTwo代码
local data = require(workspace.playerStats)
data.test = 0
原文链接 https://stackoverflow.com/questions/69582992
点赞
stackoverflow用户14551413
问题出在 ModuleScript 中的 while 循环。ModuleScript 用于 require()
共享变量。在你的情况下,你的 ModuleScript 有一个无限循环,这不让 require()
返回,并导致第二个脚本被卡住。你可能正在使用 while 循环来调试变量,所以我建议将其移到第二个脚本中。
2022-08-04 21:58:32
评论区的留言会收到邮件通知哦~
推荐文章
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?
- addEventListener 返回 nil Lua
- Lua中获取用户配置主目录的跨平台方法
- 如何编写 Lua 模式将字符串(嵌套数组)转换为真正的数组?
原文:
changing variables inside of a modulescript is global, change a variable and every script using the module gets the new variable the reason why the code you provided doesnt work is because of the while loop. the loop yields and cant proceed, meaning it cant also return the module so the server script is waiting forever.
翻译:
在一个模块脚本中更改变量是全局的,更改一个变量后,使用该模块的每个脚本都会得到新的变量。
你提供的代码之所以不起作用,是因为其中有一个 while 循环。循环会 yield,导致无法继续运行,也就无法返回模块,因此服务器脚本会一直等待。