• 🏆 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 or vJass + Related Questions

Status
Not open for further replies.
Level 18
Joined
Oct 25, 2006
Messages
1,171
Hey there.

I'm working on a decent sized project and I need to step up my programmation game.

I have decent programming skills, both in map (GUI) and game (C#, Visual Scripting and C++) development. Though I'm not necessarily comfortable with advanced programming techniques out of game scopes (or techniques which are abstract or belong to the macro-level architecture, IE the engine).

I'm pretty confident in my ability to learn a new language such as LUA or vJass but I'm not familiar with their verbose or code orientation. And I would like to know your opinion on which one would be worth investing time in. I would also have a couple of other questions.

I've went through code examples of both of these languages and vJass instantly appeared more "clear" to me, I feel like I can understand more or less what functions are being fired and ultimately what gameplay events will fire off them.

LUA seems a bit more odd to parse for me, I have read that it didn't declare its variable type, that is probably one of the first thing that confuses me when I'm reading a bunch of code.
But I also read that LUA is "more powerful", though nobody cared to explain on the thread I've diggen up.

Question #1: What would be the main differences between vJass and LUA? Why would one want to learn one over the other?

I'm not looking at making complicated abilities (with independant projectiles) and I'm not looking at making RPG systems with attribute intrication.

I'm more looking towards managing large scale "risk-like" maps with strategy and macro mechanisms such as income, alliances and unit spawning, related to specific towns. I also would like to maybe make some kind of "homemade" AI for this (through LUA or vJass).

Question #2: While parsing the code of people over here, I noticed many people were using the quicker possible variable names (u, temp etc.). Both for LUA and vJass.
Is there a reason for that other than saving typing time?

Question #3: Which one of the two languages would be closer to object oriented programming?

Pseudo code of an example of what I'm looking to achieve:
Code:
MapInit()
Get all Town Hall unit types
- Store them in a Town[] array
- Assign ID
- Bind for each "when full mana" -> SpawnVillager(TownID)
//
- Bind "on unit attacked" -> Diplomacy(War, InstigatorPlayer, TargetPlayer)

SpawnVillager()
- Empty Town Mana

- Spawn Villager
-> OrderVillager()
-> CalculateTownIncome()

OrderVillager()
- check for missing workers(returns Work)
- if work = X -> SendToLumber(targetVillager)
- if work = Y -> SendToGold(targetVillager)

Diplomacy()
- if parameter = War -> DeclareWar(targetPlayer)
- if parameter = xxx -> www

GetTownIncome(townID, resource)
- getTownIncome (variable of some sort)
- add any resourceType modificators
-> Returns integer()

Thanks in advance for any answer!
 
Level 18
Joined
Jan 1, 2018
Messages
728
Question #1: What would be the main differences between vJass and LUA? Why would one want to learn one over the other?
With lua you have access to additional functions that can provide certain functionality which is impossible to do with (v)jass.
[Lua] Basic lua functions

Question #2: While parsing the code of people over here, I noticed many people were using the quicker possible variable names (u, temp etc.). Both for LUA and vJass.
Is there a reason for that other than saving typing time?
Naming your unit variable 'u' makes sense because otherwise it'd have the same name as its type (unless you make the variable name extra long like Blizzard's 'whichUnit').
Other than that I don't think there's a specific reason, it's just preference, though you should of course always make sure you keep your variable names readable and consistent.
Naming convention (programming) - Wikipedia

Question #3: Which one of the two languages would be closer to object oriented programming?
vJass, but if you're looking for an object oriented language, I recommend C# to get the benefits that lua has over jass, and so you don't need to learn a new language.
[C#] Mapmaking in csharp
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,543
Out with the old, in with the new as they say. Lua was introduced last year for a good reason, vJass is now 10+ years old.

In my case I went straight from GUI and no programming experience to Lua and I've been able to create just about anything that comes to mind. Now anytime I help someone with their Jass code it feels like torture... Mind you I probably don't use Jass to it's full potential so perhaps I have an unfair impression of it.

With that being said, because you can only use one language at a time (although I've seen workarounds to this) you lose access to Hive's many Jass resources that have been created over the years.

However, this wasn't a problem for me as the main resource that I needed was Bribe's Damage Engine which thankfully already has a Lua version. What didn't exist in Lua yet was a Knockback system, but it was rather easy to make my own.

Just to give some examples of Lua in action: Lua allows you to store the handle of an object in tables without needing to Get it's integer id. Because of this Hashtables and Unit Indexers become obsolete.
For example, saving a custom attribute to a unit:
Lua:
AbilityPower = {} --create a table to keep track of a unit's AbilityPower attribute
local u = CreateUnit(...) --create a unit
AbilityPower[u] = 100 --use the unit as the index in the table

--Now as long as you have access to a unit you also have access to this attribute:
print( AbilityPower[GetTriggerUnit()] )
Also, Lua has Coroutines which are pretty neat. They allow you to Pause/Resume code. I've been using them to create buff systems and for ending effects prematurely. For example, I have a Dash spell that moves a unit towards a direction, however, if the unit becomes stunned or collides with something then the Dash ends early. The function to end the Dash is stored in a local Coroutine, which is saved in a Table linked to the Dashing unit. Now all I have to do is loop through that Table and resume the Coroutine(s) stored in it to end any and all effects. This acts like a Dispel effect essentially. This works wonders and I bet I'm not even using them to their full potential.

So I'd recommend using anything other than vJass.
 
Last edited:
Level 17
Joined
Mar 21, 2011
Messages
1,597
For me as a programmer, vJass is way more clear to read and understand. I also dislike that lua is not typesafe, but all of that is just personal taste. Lua is obviously the better choice performance wise, but i still use vJass nontheless
 
Level 18
Joined
Oct 25, 2006
Messages
1,171
Thanks for your answers everyone, it really is enlightening. I should be leaning towards [LUA] I guess then.

Don't hesitate to post if you have an opinion in that regard, I'm keeping an eye on the thread!

Naming your unit variable 'u' makes sense because otherwise it'd have the same name as its type (unless you make the variable name extra long like Blizzard's 'whichUnit').
Other than that I don't think there's a specific reason, it's just preference, though you should of course always make sure you keep your variable names readable and consistent.
Naming convention (programming) - Wikipedia
Yeah I'm kind of a naming convention nazi myself :p
And I'm often going for very descriptive, camelCasedNames.
 
Last edited:
Level 1
Joined
Apr 8, 2020
Messages
110
Why not both, using JNGP Lua edition? This way you can still utilize a plethora of already available systems while enjoying the more robust Lua. Of course, you can just reprogram all the systems that you need in less development time with the aid of more powerful languages. And there are projects that already provide standard libraries ready to utilize like mentioned.
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
If using Lua you will want to build around having a framework to help with debugging. Such as having a global flag you can set that makes all functions run with error catching and reporting. This can be used during development and early releases to help track down scripting errors and bugs. I also recommend using variable names which help infer what type the variable is.
 
Status
Not open for further replies.
Top