• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • It's time for the first HD Modeling Contest of 2025. Join the theme discussion for Hive's HD Modeling Contest #7! Click here to post your idea!

[Lua] Correct way of use load?

Status
Not open for further replies.
Level 24
Joined
Jun 26, 2020
Messages
1,921
I'm making TPs but as they are practically the same thing when coding and to make easier to configure later I opted to use the function load, the problem is I don't know how to do it correctly, this is what I do:

Lua:
do
    function Teleport(enterRect, leaveRect, enterTP, leaveTP, enterText, leaveText)
        load(
            "local enterRect = ".. enterRect .." ---@type rect\n"..
            "local leaveRect = ".. leaveRect .." ---@type rect\n"..
            "local enterTP = GetRectCenter(".. enterTP ..") ---@type location\n"..
            "local leaveTP = GetRectCenter(".. leaveTP ..") ---@type location\n"..
            "\n"..
            "-- Enter\n"..
            "local t = CreateTrigger()\n"..
            "TriggerRegisterEnterRectSimple(t, enterRect)\n"..
            "TriggerAddAction(t, function ()\n"..
                "SetUnitPositionLoc(GetEnteringUnit(), enterTP)\n"..
                "DisplayTimedTextToPlayer(GetOwningPlayer(GetEnteringUnit()), 0, 0, 5., '|cffffff00[\"".. enterText .."\"]|r')\n"..
            "end)\n"..
            "\n"..
            "-- Leave\n"..
            "t = CreateTrigger()\n"..
            "TriggerRegisterEnterRectSimple(t, leaveRect)\n"..
            "TriggerAddAction(t, function ()\n"..
            "    SetUnitPositionLoc(GetEnteringUnit(), leaveTP)\n"..
            "    DisplayTimedTextToPlayer(GetOwningPlayer(GetEnteringUnit()), 0, 0, 5., '|cffffff00[\"".. leaveText .."\"]|r')\n"..
            "end)\n"
        )
    end
end
So when I call this:

Lua:
OnMapInit(function ()
    Teleport("gg_rct_Jijimon_House_Outside",
        "gg_rct_Jijimon_House_Inside",
        "gg_rct_JijimonTP_inside",
        "gg_rct_JijimonTP_outside",
        "Jijimon's House",
        "File City")
end)
The result should be:

Lua:
OnMapInit(function ()
    local enterRect = gg_rct_Jijimon_House_Outside ---@type rect
    local leaveRect = gg_rct_Jijimon_House_Inside ---@type rect
    local enterTP = GetRectCenter(gg_rct_JijimonTP_inside) ---@type location
    local leaveTP = GetRectCenter(gg_rct_JijimonTP_outside) ---@type location

    -- Enter
    local t = CreateTrigger()
    TriggerRegisterEnterRectSimple(t, enterRect)
    TriggerAddAction(t, function ()
        SetUnitPositionLoc(GetEnteringUnit(), enterTP)
        DisplayTimedTextToPlayer(GetOwningPlayer(GetEnteringUnit()), 0, 0, 5., "|cffffff00[Jijimon's House]|r")
    end)

    -- Leave
    t = CreateTrigger()
    TriggerRegisterEnterRectSimple(t, leaveRect)
    TriggerAddAction(t, function ()
        SetUnitPositionLoc(GetEnteringUnit(), leaveTP)
        DisplayTimedTextToPlayer(GetOwningPlayer(GetEnteringUnit()), 0, 0, 5., "|cffffff00[File City]|r")
    end)

end)
But is not working, the map doesn't even run, what did I do wrong?

Edit: I forgot import the Global Initialization, so that's why the map didn't run, but I will still appreciate feedback.
 
Last edited:
you need to call the function load creates.
load( whatever )()

When your map does not run (can't be started) and shows an error popup in the game, then check the logfile users\user\Documents\Warcraft III\Logs\War3Log.txt. It might tell you why.

Example, error message in the logfile:
5/27 08:48:20.487 Map contains invalid Jass scripts that couldn't be compiled by war3, file: war3map.lua, error: attempt to call a nil value (global 'DasHaus')
 
Level 24
Joined
Jun 26, 2020
Messages
1,921
When your map does not run (can't be started) and shows an error popup in the game, then check the logfile users\user\Documents\Warcraft III\Logs\War3Log.txt. It might tell you why.

Example, error message in the logfile:
5/27 08:48:20.487 Map contains invalid Jass scripts that couldn't be compiled by war3, file: war3map.lua, error: attempt to call a nil value (global 'DasHaus')
Thank you for the tip.
you need to call the function load creates.
load( whatever )()
I tried that and didn't work, maybe I wrote something bad.
 
Status
Not open for further replies.
Top