• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

vJass, Lua, Wurst and what not... time for a switch ?

Status
Not open for further replies.
Level 12
Joined
Jan 30, 2020
Messages
875
Hello there !

OK I have started reading vJass manual. There is quite a lot to read, but it is quite interesting indeed.

This said, there are things that attracted my attention since I came back to map making after 16 years, things that were not a thing in Warcraft 3 back in 2004.

Well neither was vJass to be honest, but as it is in fact still Jass2 did make me learn a bit more, especially as I could do things with it that required me to edit the whole war3map.j. Actually last time I made a map in 2004, I was completely ignoring WE once objects were setup, and was working directly in the map script. Nice but not necessarily practical.

Anyways, now there is Lua. Another scripting language that has been implemented into the WE, I suppose thanks to the community. And I also have seen a lot of good spoken about Wurst.

So my questions are :
- is Wurst still a thing since reforged ? I mean I like the idea of an IDE with a compiler, but it seems it has not been updated for a while now, and I am not even sure it can work with Reforged.

- what can Lua do that Jass2 or vJass can't do ? Do we still need to null local handles ? Is there a garbage collector working in multiplayer - or should I still destroy unused agents ? Can we pass arguments to a callback function in Lua? Do we still need HashTables ? I probably miss quite many other important points, but as the only documentation I have found about Lua is talking about general use, it only partially helps. All I know for the moment is that Lua can use all common.j natives (and AI natives too ?).

So before converting my map (quite intensive mazing TD) to Lua, I would like to know if I am going in the right direction, and what are the traps I should not fall into.

A thousand thanks in advance for any useful advice !

Take care guys.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,534
Lua is great and I highly recommend it.

1) MOSTLY no nulling (aka nil in Lua) required
2) Edit: Lua objects get garbage collected as usual. One can make a garbage collector for locations and groups but some people say that is desync prone.You still need to remove locations/conditions/groups/special effects/etc (@Dr Super Good )
3) Not sure about Callbacks but I'm pretty sure it works exactly the same as Jass, and if not I imagine there's an even better method
4) No longer need Hashtables as you can create tables with as many dimensions as you'd like and you can use any handle as the index for these tables
5) Declare local variables anywhere

#4 Example:
Lua:
Table = {} --Create a new 1 dimensional table
local u = CreateUnit(footman, blah blah blah)
Table[u] = 100

print(u) --This will print the unit's handle id
print(Table) --This will print the Table's id
print(Table[u]) --This will print the unit's value in table (100)
^You can plug the unit's handle into the table's index. This goes for just about anything as well.

Some Lua quirks:
Rawcodes need the prefix "FourCC". This goes for Units, Buffs, Abilities, etc...
Lua:
UnitAddAbility(u, FourCC("Arav"))

There's probably some other stuff I'm forgetting.

Anyway, as someone who went from zero programming/using GUI to Lua, it's like a night and day difference. The only issue is the lack of Lua resources but that should come with time. That being said, it's not that difficult to convert Jass to Lua as you can find and replace most of the syntax stuff (endfunction -> end). Plus Bribe has a Lua version for his Damage Engine and that's really the only system I think you need as the rest can be created yourself fairly easily.
 
Last edited:

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,196
Strings need two backslashes:
This was the case with JASS2 as well.
2) Garbage Collector works for most local variables although I believe you still need to remove locations/conditions/groups/special effects/etc (@Dr Super Good )
Local variables do not need garbage collection since they are local variables. Lua objects get garbage collected as usual. One can make a garbage collector for locations and groups but some people say that is desync prone.
 
Level 12
Joined
Jan 30, 2020
Messages
875
OK guys, thank you!

Well that really sounds attractive, I think I am going to do the switch.

@Uncle :
1) Noted, but why "MOSTLY" ?
2) OK
3) IS there is a way, it would make many scripts so much easier.
4) This is really helping in many situations, wow really.
5) Worth knowing, although I wouldn't use this, just like I never declared globals everywhere in vJass, mostly because I hadn't created scopes or libraries yet.
I like to keep things nicely sorted :) but yes this can be useful.

I noted the extra information, especially the FourCC. I can't think of a map that do not use Ids

As for strings, and as Dr Super Good mentioned, we already needed double slashes. Strange enough, that is not the case for antislash (used for sound flac variables by the Sound Editor and then the Asset Manager)

@Drake53 : Yes that is indeed very useful, I have already seen an os function used to get the os Timestamp for benchmarks.
But then how do we know when a function from a Lua library can be used in wc3 or not ?

@Dr Super Good : You again. I have the feeling you are a real encyclopedia !

So about custom garbage collector, maybe it would be less risky to keep removing unused agents instead ?
And while you're there, would you know about passing arguments to the callback functions, that would be something huge...


OK now let's say I do the switch.
Of course as I heard, Jass and Lua cannot cohabit in the same map because the game can only use one type of virtual machine.

So to switch to Lua, I need to remove all my triggers, probably export my map script first, then change the script language in map options, convert my triggers to Lua one by one and add them once I am done.

As for the initialization function, is there anything specific to Lua ?

Will first read some more documentation and do this progressively.


Again, thank you.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,534
This was the case with JASS2 as well.

Local variables do not need garbage collection since they are local variables. Lua objects get garbage collected as usual. One can make a garbage collector for locations and groups but some people say that is desync prone.
Okay, my mistake. I edited my post. So just to clarify, what do I have to nil?

I've been doing this:
Lua:
local g = CreateGroup()
--do some stuff
DestroyGroup(g)
g = nil
^ The nil is unnecessary, right?
 
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,534
OK guys, thank you!

Well that really sounds attractive, I think I am going to do the switch.

@Uncle :
1) Noted, but why "MOSTLY" ?
2) OK
3) IS there is a way, it would make many scripts so much easier.
4) This is really helping in many situations, wow really.
5) Worth knowing, although I wouldn't use this, just like I never declared globals everywhere in vJass, mostly because I hadn't created scopes or libraries yet.
I like to keep things nicely sorted :) but yes this can be useful.

I noted the extra information, especially the FourCC. I can't think of a map that do not use Ids

As for strings, and as Dr Super Good mentioned, we already needed double slashes. Strange enough, that is not the case for antislash (used for sound flac variables by the Sound Editor and then the Asset Manager)

@Drake53 : Yes that is indeed very useful, I have already seen an os function used to get the os Timestamp for benchmarks.
But then how do we know when a function from a Lua library can be used in wc3 or not ?

@Dr Super Good : You again. I have the feeling you are a real encyclopedia !

So about custom garbage collector, maybe it would be less risky to keep removing unused agents instead ?
And while you're there, would you know about passing arguments to the callback functions, that would be something huge...


OK now let's say I do the switch.
Of course as I heard, Jass and Lua cannot cohabit in the same map because the game can only use one type of virtual machine.

So to switch to Lua, I need to remove all my triggers, probably export my map script first, then change the script language in map options, convert my triggers to Lua one by one and add them once I am done.

As for the initialization function, is there anything specific to Lua ?

Will first read some more documentation and do this progressively.


Again, thank you.
You can disable your triggers as well, instead of removing them when converting.

Also, [Lua] Global Initialization
 
The Lua compiler won't tell you about wrong types for natives or wrong written names, it will just silently break when the function runs, if the function was not set up to tell you about errors in runtime for such a case (xpcall).

There were/are some problems with comparing some warcraft 3 types which can be bypassed by comparing handleIds instead. For example BlzGetFrameByName can return a framehandle for a not existing frame but is not nil, still GetHandleId for that Frame would be 0. Which is wierd/annoying.

Lua can have function arrays which also can be called with arguments. Arguments can be from any type be it array (table in Lua), a function or whatever.

To swap a map one can also export triggers, reset triggers, change language and reimport the exported triggers. (create a backup before doing this)
 
Level 12
Joined
Jan 30, 2020
Messages
875
Wow guys thanks, so much information.

I quickly went through the whole Lua reference manual for v5.3.
To be honest I learnt a lot, but I don't think I will assimilate all this that easily.
It has a lot of references to C, unfortunately my C coding days are as old as 20 years :D


@Uncle : OK I will try the disabled trigger method then. About the initialization, it seems much trickier than with vJass. the Init Globals is quite confusing as I read all variables are globals in Lua when not explicitly declared as locals.

@Drake53 : Wow nice finding about the hidden functions. Pity they don't seem to properly work, and I suppose thats why they were hidden. The method for finding out is very useful anyways, and answers my question :)
EDIT : Wait
"function DzAPI_Map_IsAuthor takes player whichPlayer returns boolean
return RequestExtraBooleanData(50, whichPlayer, null, null, false, 0, 0, 0)
endfunction"

Are all these DzAPI functions actually usable in a Map ????

@Tasyen : OK thats a non negligible downside I'll come back to you if I fail to properly convert my vertical camera zoom out slider ;-)

Now I read a bit about function arrays. We had a basic version in Jass with trigger arrays, but thats something too specific. What I am interested in is the flexibility with arguments. So does that mean I can use them in callback functions ?

Exporting & resetting triggers then change scripting language and finally re-importing triggers..... do you mean it will convert them into Lua ???

EDIT : No it didn't work. After importing, my triggers are still in Jass2 / vJass.
 
Last edited:

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
I do not know enough about the specifics of Lua in Warcraft 3 to compare it fully, but from what I gather it should at least equal vjass in terms of functionality.
My personal preference is wurst as I really love the syntax and it has some features that vjass does not have.

Seen plenty of support for typescript too which I would easily pick over vjass since I am a bit of a javascript fan.

I don't think you can go wrong with either, but vjass really should not be used anymore. And god forbid using jass
 
Level 18
Joined
Jan 1, 2018
Messages
728
Are all these DzAPI functions actually usable in a Map ????
You can use them, but they all call RequestExtraXData, and I don't think those actually do anything unless you're playing on NetEase. Never bothered to test them though.
 
Level 12
Joined
Jan 30, 2020
Messages
875
@Chaosy :
Yes I was convinced already that Lua would be a better choice, in spite of some small problems about initialization and type comparison.

I was very tempted with Wurst, but my question is still the same : is it still an active project ? is it compatible with Reforged ?
As for Typescript, I have never tried it, when I was web dev a few years back, I only used php. And a bit of JavaEE and C#. Of course I used some javascript, but not JavaScript.

Anyways, at the moment I haven't yet converted my map. I started reading more about Lua, and although I admit the syntax is not my cup of tea, I can already feel the potential.

If Wurst is indeed still active and Reforged compatible, I will definitely investigate and find the best option of the two that fits my developing style the most.

@Drake53 : I see what you mean, well it still is better to know they exist than not. Even if currently useless.
 
Level 12
Joined
Jan 30, 2020
Messages
875
Ok I will try to investigate on Wurst website, and see what I can achieve.

Will be interesting to compare the possibilities of both languages in wc3 context.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,196
So about custom garbage collector, maybe it would be less risky to keep removing unused agents instead ?
That is what my Lua garbage collector did. Some people say it desyncs with 1.32.3.
And while you're there, would you know about passing arguments to the callback functions, that would be something huge...
With Lua you can use a local function to do this. With JASS2 one has to pass it via some sort of system, either using hashtables or globals.
OK now let's say I do the switch.
Of course as I heard, Jass and Lua cannot cohabit in the same map because the game can only use one type of virtual machine.

So to switch to Lua, I need to remove all my triggers, probably export my map script first, then change the script language in map options, convert my triggers to Lua one by one and add them once I am done.

As for the initialization function, is there anything specific to Lua ?
Yes this is basically what one has to do. Blizzard does plan to automate the process in a future update but for now one has to do annoying steps like this.

Initialization in Lua is basically the same in JASS. Exception being there is a new initialization time as well, script parse time, but running script then can be buggy so is not recommended outside of setting up tables and other global mappings
 
Level 12
Joined
Jan 30, 2020
Messages
875
Ok thanks a lot, now I know whee I am heading.

Will also explore Wurst a bit, probably just for fun. I suppose there is a reason why Blizzard adopted Lua rather than anything else.
 
Status
Not open for further replies.
Top