北大侠客行MUD论坛

 找回密码
 注册
搜索
热搜: 新手 wiki 升级
查看: 2039|回复: 6

lua 小白问题

[复制链接]
发表于 2022-12-18 04:48:24 | 显示全部楼层 |阅读模式
请教各位大神, 我想在mudlet里做个挑水机器人, 因为要慢慢走, 就想用 tempTimer 每次等一秒再走。
所有步骤在一个数组里, 然后一个个给慢走函数。

在manzou函数里, 如果执行print, 所有步骤都可以正常显示。
但tempTimer(1, [[ send(v1) ]]) 显示下面错误:
        
[错误:] 对象: 函数:

这是怎么回事 ?
=========================================================
function goTS1()
local v_array = {"n","n","w","n","n","w","carry mu tong","e","s","s","e","s","s","sd","s","open gate","s","s","sd","sd","sd","wd","w","sd","sd","eu","fill mu tong"}  
for _, v1 in ipairs(v_array) do
   manzou(v1)
   --print(v1)
end
end


function manzou(v1)
   
    print("xxx" ..v1)
    tempTimer(1, [[ send(v1) ]])
end
北大侠客行Mud(pkuxkx.net),最好的中文Mud游戏!
 楼主| 发表于 2022-12-18 07:49:24 | 显示全部楼层


改了一下, 这样不出错, 但是20 个'x' 同时出现。

function goTS1()
local v_array = {"n","n","w","n","n","w","carry mu tong","e","s","s","e","s","s","sd","s","open gate","s","s","sd","sd","sd","wd","w","sd","sd","eu","fill mu tong"}  
v_num = 0
for _, v1 in ipairs(v_array) do
   manzou()
end
end

function manzou()   
    tempTimer(1, [[ print("x") ]])
end
北大侠客行Mud(pkuxkx.net),最好的中文Mud游戏!
发表于 2022-12-18 07:51:31 | 显示全部楼层
manzou(n)

tempTimer(1 * n, print)
北大侠客行Mud(pkuxkx.net),最好的中文Mud游戏!
 楼主| 发表于 2022-12-18 07:52:08 | 显示全部楼层
读了一些论坛,看来lua不允许这样的操作
动作 1
等一秒
动作2
等一秒

怎么做头一个最简单的机器人就遇到这么倒霉的问题
北大侠客行Mud(pkuxkx.net),最好的中文Mud游戏!
 楼主| 发表于 2022-12-18 08:59:45 | 显示全部楼层
终于找到解决办法了,有点笨,一次发n个tempTimer,哪位大神有更好的办法请告知。

function goTS1()
local v_array = {"n","n","w","n","n","w","carry mu tong","e","s","s","e","s","s","sd","s","open gate","s","s","sd","sd","sd","wd","w","sd","sd","eu","fill mu tong"}  
t1 = 0
for _, v1 in ipairs(v_array) do
   t1 = t1 +1
   manzou(t1,v1)
end
end

function manzou(t1,v1)   
    tempTimer(t1, [[ send(" ]]..v1..[[") ]])
end
北大侠客行Mud(pkuxkx.net),最好的中文Mud游戏!
发表于 2022-12-18 09:07:26 | 显示全部楼层
这样设计
1 定义变量
  1. v_array = {"n","n","w","n","n","w","carry mu tong","e","s","s","e","s","s","sd","s","open gate","s","s","sd","sd","sd","wd","w","sd","sd","eu","fill mu tong"}  
  2. v_num = 1
  3. v_chk = true
  4. v_fuc = function ()
  5. if v_chk then
  6. print (v_array[v_num])
  7. v_num=v_num+1
  8. end
  9. end
复制代码


2 创建一个计时器,计时器负责发送v_fuc()

3改变控制变量v_chk的布尔值可以停止发送命令

北大侠客行Mud(pkuxkx.net),最好的中文Mud游戏!
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2022-12-18 16:12:57 | 显示全部楼层
@dtp
多谢回复!这样可以,但也是创建了n个timer, 优化不好而且觉得别扭。

@creat
感觉这是最好的方法,还没学到mudlet里面的timer功能,太感谢了!
北大侠客行Mud(pkuxkx.net),最好的中文Mud游戏!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|北大侠客行MUD ( 京ICP备16065414号-1 )

GMT+8, 2024-11-24 12:27 AM , Processed in 0.012405 second(s), 14 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表