【发布时间】:2020-04-08 16:48:48
【问题描述】:
我的一个脚本有问题,我试图在脚本运行时加载一个文件,但我收到一条错误消息,提示他没有找到任何具有我给定名称的文件。
这是我设置加载文件的条件:
function checkAll()
if (global:getCountFight() >= (LAST_NB_FIGHT+MAX_FIGHT)) then
LAST_NB_FIGHT = global:getCountfight()
printMsg("Déconnecte le personnage pendant "..SLEEP_TIME.." heure(s)")
global:reconnect(SLEEP_TIME)
elseif (character:level()<8) then
goHomeAndLoadTrajet("[Combat] Bouftous")
setMinMonsters(1)
setMaxMonsters(8)
setForceMonsters({})
SLEEP_LVL = 50
SLEEP_TIME = 6
这是函数 goHomeAndLoadTrajet 调用的内容:
function goHomeAndLoadTrajet(trajetName)
trajetName = checkTrajetName(trajetName)
if trajetName ~= u_NEXT_TRAJET and trajetName ~= LAST_TRAJET then
u_NEXT_TRAJET = trajetName
goHome()
end
end
调用:
function checkTrajetName(trajetName)
if (file_exists(INCLUDES_PATH..trajetName)) then
return trajetName
elseif (file_exists(INCLUDES_PATH..trajetName..".lua")) then
return trajetName..".lua"
else
printMsg("Le trajet '"..trajetName.."' n'existe pas !", "ERREUR")
return
end
最终调用:
function file_exists(name)
local f=io.open(name,"r")
if f~=nil then io.close(f) return true else return false end
end
所以现在我很困惑..谢谢:)
编辑:INCLUDES_PATH 是一个包含我的路径的变量,INCLUDES_PATH = "C:\\Program Files (x86)\\SnowbotTouch\\Scripts Lua\\Trajets\\includes\\"
【问题讨论】:
-
错误信息是否来自
checkTrajetName()? -
是的! @EgorSkriptunoff
-
直接调用
checkTrajetName(trajetName)会发生什么?
标签: file import lua directory load