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!
I'm not quite sure how to get started with a map using Lua as the primary scripting language. My initial method for exploring Jass was often creating a trigger and converting to custom text, but that doesn't seem to work with the scripting mode set to Lua. Does anyone know of documentation/tutorials or examples of Lua in wc3 maps? I know it only became supported as a beta feature a few days ago, but I'm eager to try it out.
EDIT:
There are other options to use besides pure Lua. Here's a link to C# and TypeScript.
These all compile to Lua so you're still required to use Lua as the supported language in your map:
Hello there ! I am trying to use @TriggerHappy 's TypeScript template for wc3. First let me tell you that I am a complete newbie at TS, although I have already used JavaScript a while back. So like any well-behaved newbie, I have followed the quick startup guide found at...
www.hiveworkshop.com
HOW TO GET STARTED USING LUA: Lua VSCode Integration <--- Follow the instructions in this
Then setup your map to be compatible with Lua (picture 1).
Then create a custom script in the trigger editor and paste your Lua code in it (picture 2).
You'll have to disable any existing triggers that use Custom Script before converting to Lua. This is because that Custom Script was using Jass and as of now Lua cannot be used with Jass/vJass.
You'll also have to update that Custom Script to follow Lua's syntax rules. Some examples, Lua doesn't require you to type "call" or "set" and I believe you don't have to null local variables (look into the Garbage Collector, you probably still want to null some things and clean up leaks). "null" also becomes "nil". "endif" becomes "end". NOT EQUAL TO changes from 5 != 10 to 5 ~= 10. These are just a few examples, you can get a much better understanding of this if you read through the Lua manual:
Functions no longer use "takes nothing returns nothing" and instead look like this:
Lua:
function HelloWorldTest()
print("Hello World")
end
function CreateAUnit()
local newUnit = CreateUnit(Player(0), FourCC("hfoo"), 0, 0, 270)
DisplayUnitName(newUnit)
end
--Comments use this double hyphen instead of double slash //
--If you wanted to pass some data in the parameters you would do it like so:
function DisplayUnitName(unit)
local stringExample = GetUnitName(unit)
print(stringExample)
end
Also, rawcodes in Lua require the FourCC() prefix:
Lua:
FourCC("hfoo")
FourCC("A000")
If memory serves me right then apostrophes in the rawcode DON'T work either -> 'hfoo'
This link has some important information in it. I find some of the comments in there (see Eikonium's post) very resourceful when it comes to structure, formatting, desyncs, what to avoid doing, etc: Lua Submission Rules Discussion
DISCLAIMER: I'm no Lua expert and I'm probably doing things wrong here! Wrong in the sense that it's bad practice, not wrong that it doesn't work.
Look at the picture "lua 2" that I uploaded above. You press "Control + U" to create a new Custom Script and then paste your code inside of it.
Also, you can call functions in GUI like this:
HelloWorld
Events
Player - Player 1 (Red) types a chat message containing test as An exact match
Conditions
Actions
Custom script: HelloWorld()
Here is an example of creating a trigger in Lua:
Lua:
function StartEffectOfAbility()
local trigger = CreateTrigger()
TriggerRegisterAnyUnitEventBJ(trigger, EVENT_PLAYER_UNIT_SPELL_EFFECT)
TriggerAddAction(trigger, function()
local caster = GetTriggerUnit() --GetTriggerUnit references the Triggering Unit
if GetSpellAbilityId() == FourCC('AUan') then --If the ability being cast is equal to Animate Dead
KillUnit(caster) --Kill the triggering unit (casting unit) to show that it worked
end
end)
end
We can also create one function that runs ALL of our other functions. Then run this one function at the start of the map.
Lua:
function MapSetup()
--Call our functions
HelloWorld()
StartEffectOfAbility()
end
I run MapSetup() at the start of the game, which then runs HelloWorld() and StartEffectOfAbility().
Lua Setup
Events
Time - Elapsed game time is 0.00 seconds
Conditions
Actions
Custom script: MapSetup()
I attached a map with a bunch of examples. Note that I'm no expert on Lua and there's probably a way to do all this without the need of a single GUI trigger.
That looks like a bug with Reforged. The triggers shouldn't look like that. I would use the classic Editor until the Reforged Editor is in better working condition.
Look at the picture "lua 2" that I uploaded above. You press "Control + U" to create a new Custom Script and then paste your code inside of it.
Also, you can call functions in GUI like this:
HelloWorld
Events
Player - Player 1 (Red) types a chat message containing test as An exact match
Conditions
Actions
Custom script: HelloWorld()
Here is an example of creating a trigger in Lua:
Lua:
function StartEffectOfAbility()
local trigger = CreateTrigger()
TriggerRegisterAnyUnitEventBJ(trigger, EVENT_PLAYER_UNIT_SPELL_EFFECT)
TriggerAddAction(trigger, function()
local caster = GetTriggerUnit() --GetTriggerUnit references the Triggering Unit
if GetSpellAbilityId() == FourCC('AUan') then --If the ability being cast is equal to Animate Dead
KillUnit(caster) --Kill the triggering unit (casting unit) to show that it worked
end
end)
end
We can also create one function that runs ALL of our other functions. Then run this one function at the start of the map.
Lua:
function MapSetup()
--Call our functions
HelloWorld()
StartEffectOfAbility()
end
I run MapSetup() at the start of the game, which then runs HelloWorld() and StartEffectOfAbility().
Lua Setup
Events
Time - Elapsed game time is 0.00 seconds
Conditions
Actions
Custom script: MapSetup()
I attached a map with a bunch of examples. Note that I'm no expert on Lua and there's probably a way to do all this without the need of a single GUI trigger.
How did you get your syntax to highlight like that? I came back to warcraft with the release of reforged beta but none of the custom modding tools seem to work, there is no syntax auto complete nor any highlighting and the trigger editor looks like the poster's above me.
You mean here on Hive? Just use [ code=lua ] tags. For a syntax highlight for coding, there is a plug-in for VS Code, like Uncle above already pointed out.
You mean here on Hive? Just use [ code=lua ] tags. For a syntax highlight for coding, there is a plug-in for VS Code, like Uncle above already pointed out.
Yeah, that syntax highlighting is from the Hive code tags. The World Editor doesn't support that yet.
Some random things to note:
I do everything on VS Code then copy and paste it into the World Editor.
If you see weird characters when you try to paste your code then do the following: Delete the existing code (Control + A -> Delete) and then paste your code.
I wouldn't use the Reforged Editor until the issues have been fixed. Fortunately, you can work on your map in Classic and then play it on Reforged. Or import it from Classic to Reforged. However, I don't think you can import Reforged back to Classic.
Hey one thing I've been doing being new to Lua also, is copying my GUI triggers in my Lua map to a new Jass map then I convert them to Jass and then I copy paste them to Visual Studios.
Its probably more work than just writing from scratch but for someone who is new to Lua it helps.
Hey one thing I've been doing being new to Lua also, is copying my GUI triggers in my Lua map to a new Jass map then I convert them to Jass and then I copy paste them to Visual Studios.
Its probably more work than just writing from scratch but for someone who is new to Lua it helps.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.