Skip to content

MacOS script path issue #128

@ZJouba

Description

@ZJouba

Ran into an issue on MacOS:

OnBotScriptDetails Team 2, bError NO, pResult 1, count 1
Initscripting Team 2: /Users/izak.joubert/Library/Application Support/Steam/steamapps/workshop/content/570/3246316298
Radiant bot scripting using script path /Users/izak.joubert/Library/Application Support/Steam/steamapps/workshop/content/570/3246316298
LoadScript: /Users/izak.joubert/Library/Application Support/Steam/steamapps/workshop/content/570/3246316298/hero_selection.lua, scope name HeroSelectionScriptScope
[VScript] Script Runtime Error: error in error handling
Failed to run script '/Users/izak.joubert/Library/Application Support/Steam/steamapps/workshop/content/570/3246316298/hero_selection.lua'!
LoadScript: /Users/izak.joubert/Library/Application Support/Steam/steamapps/workshop/content/570/3246316298/team_desires.lua, scope name TeamDesiresScriptScope
LoadScript: /Users/izak.joubert/Library/Application Support/Steam/steamapps/workshop/content/570/3246316298/team_desires.lua not found!
[VScript] Script Runtime Error: attempt to index a number value
OnBotScriptDetails Team 3, bError NO, pResult 1, count 1
Initscripting Team 3: /Users/izak.joubert/Library/Application Support/Steam/steamapps/workshop/content/570/3246316298
Dire bot scripting using script path /Users/izak.joubert/Library/Application Support/Steam/steamapps/workshop/content/570/3246316298
LoadScript: /Users/izak.joubert/Library/Application Support/Steam/steamapps/workshop/content/570/3246316298/hero_selection.lua, scope name HeroSelectionScriptScope
[VScript] Script Runtime Error: error in error handling
Failed to run script '/Users/izak.joubert/Library/Application Support/Steam/steamapps/workshop/content/570/3246316298/hero_selection.lua'!
LoadScript: /Users/izak.joubert/Library/Application Support/Steam/steamapps/workshop/content/570/3246316298/team_desires.lua, scope name TeamDesiresScriptScope
LoadScript: /Users/izak.joubert/Library/Application Support/Steam/steamapps/workshop/content/570/3246316298/team_desires.lua not found!
[VScript] Script Runtime Error: attempt to index a number value

According to GPT The Mac VScript runtime is stricter [than Windows'] and fails i.e. on Mac, the lua file can't be found.

I fixed it "temporarily" (I'm sure it's not the best fix) by overwriting the global require to change from paths to module imports:

local original_require = _G.require

_G.require = function(name)
    if type(name) == "string" and string.find(name, "/") then
        local scriptDir = GetScriptDirectory()
        name = string.gsub(name, "^" .. scriptDir .. "/", "")
        name = string.gsub(name, "%.lua$", "")
    end

    return original_require('bots.'..name)
end

more permanent fix would be to refactor all imports to use module paths. GPT suggests the following:

Clean cross-platform fix

At the very top of hero_selection.lua, add:

local scriptPath = GetScriptDirectory()

package.path = package.path .. ";" .. scriptPath .. "/?.lua"
package.path = package.path .. ";" .. scriptPath .. "/?/init.lua"
package.path = package.path .. ";" .. scriptPath .. "/?/?.lua"

Now this works everywhere:

require("FunLib.aba_global_overrides")

Lua will search:

<scriptPath>/FunLib/aba_global_overrides.lua

which resolves correctly whether the script is loaded from:

vscripts/bots

or

workshop/content/570/3246316298

I haven't touched Lua ever so take mine and GPT's suggestions with a tablespoon of salt. Anyway, working now on Mac M4 Pro.

Also, identifying the issue was a pain in the a$$. As a quality of life update, might be a good idea to incorporate this in the future

local ok, err = pcall(function()

-- ORIGINAL CONTENT OF hero_selection.lua

end)

if not ok then
   print("HERO_SELECTION ERROR: "..tostring(err))
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions