• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Casual C/C++ Programmer Looking For General JASS AI (1.26a) Advice.

Level 1
Joined
Apr 22, 2024
Messages
1
Hi, I'm not new to Hive Workshop or WC3Campaigns and it's been wonderful resources for me well over 15 years before Firelord was a tavern hero. I don't believe I've posted here before in all that time, so forgive my community's naiveté and etiquette. I own Reforged, but I still don't like it. I've got a "retro" Windows 98/XP PC that has 3DS MAX 4, official Art Tools, and Warcraft III. This isn't important to my upcoming question; I just wish to present some perspective. Recently I've returned to a feature I've been amazed at when I was a young teenager, the "AI Editor". Since then though, I've become experienced in programming and game logic in general and decided to attempt something, regardless of feasibility, that was intimidating then: JASS scripting. I've been working with JASS Craft, it's adequate for basic editing but I use PJASS outside of it. Anyway, here are my questions. My project is to create a monolithic (independent) AI that is significantly better than Blizzard's default AI and not reliant on, then, AMAI either. To achieve this, I only refer to native functions, types, etc. so it can perform alongside any other AI or mods in general. If I've found a non-native function useful, I reimplement it even though I understand the ridiculousness. I'm not using vJASS due to preferring a simpler "toolchain".

So here are my questions:

1. I have a lot of constants, that include several IDs for units, orders, abilities, etc. From my understanding, JASS is interpreted. Are constants any more efficient than normal variables? In compiled languages at large, constants are recognized as "references" for magic numbers (multi-occurrence, unchanged number) and are optimization-swapped. Does JASS do this? If not, is there a tool to help with that?

2.
I've read that memory leaks are possible, and considering my script is already large, I feel that is necessary to pay attention to them. I have only read about replacing locations with coordinates (X, Y). How large of a difference is it? Should I instead create global locations or global reals for X and Y to reuse? The same question applies to Rects too.

3. I've read some posts about issues with using heavy math, mainly speed/efficiency. Should I "pre-compute" the math instead, if possible, and write them into variables for reuse or is it fine? Are there certain math-related functions or operations that I should look out for (sqrt, divide, etc.)?
 
1) Vexorian's Optimizer can inline constants. There is no performance gain with 'constant' keywords, the most confusing of all of these is 'constant function', which is completely useless. All functions are constant in JASS, regardless of the 'constant' keyword, however 'constant' functions have some limitations compared to non-constant ones, so it's just best to avoid that realm.
2) When you can use x,y coordinates instead of locations, go ahead and do so. Otherwise, locations are fine as long as you remove the ones that you create dynamically.
3) Most optimization in JASS is not going to be worth it. Look for general areas of performance moreso in terms of setting things to a variable rather than using repetitive getter functions or re-running the same math in the same thread. JASS does not benefit as much from optimization as other programming languages do.
 

Cokemonkey11

Spell Reviewer
Level 30
Joined
May 9, 2006
Messages
3,560
+1 to what Bribe said

Wurstlang is an optimizing compiler and as far as I know it's the only one

Be aware that with latest wc3 patches, lua is now the execution engine for wc3 scripts, even if your code is jass. I'm told that this is more efficient, so "slow" algorithms are less relevant than ever

I believe there are some tools for finding leaks

Good luck
 
Maybe you would consider this slightly off-topic, but years ago when I dinked around with custom AI scripts, I found that sometimes and in some seemingly arbitrary cases, the non-JASS prebuilt behaviors of the system would simply shut down. For example, sometimes "the computer forgets to mine gold." This would seemingly happen despite the functions being called to establish gold miners.

It has been quite some time, but the debugging tools for problems with these AI scripts seemed abysmal at best. Perhaps I simply didn't know what I was doing, but that was how I felt after dabbling for years.

I have a certain mad respect for keeping an XP machine with 3ds 4 and everything else. I used to want to do that, but I guess old Microsoft got in my head, and as a second-best option I was trying to recreate from source emulations of the types of systems that I wanted instead of the originals. They're always never quite as good. "Select and Animate" in Retera Model Studio has the same slider bar as when we do War3 art tools, and the "set time scale" button and the "set keyframe" button in essentially the same physical positions, but it's never quite as good. My Tension/Continuity/Bias mathematics for drawing hermite/bezier hand-made animations are literally non-existent. So, then I went to simulate a replacement game system. And that's working sometimes, but it has so many problems. JASS is one of those problems. Everyone said I should not make a JASS emulator and should put LUA in the game because it's easier, but I wrote a JASS emulator into the game, just to show 'em, and do it my own way. So, anyway, I didn't make bindings for AI functions yet, but I would rather to make them and develop on there than on the original binary at this point. I can dump a stacktrace when the JASS crashes in the simulator, or freeze the simulator in a debugger and inspect named program variables, unit statistics, etc. The absence of this technology on Warcraft 3 is a comedy. In hindsight, you can imagine it feels like an artificial suffering. My handle systems are more lightweight for now, mapping more directly to the game components, so there aren't handle leaks yet. Locations can be used freely without calling "RemoveLocation," which is a do-nothing placeholder function, because the existing garbage cleaning utilities from the systems used to build my simulator kick in and clean it all up anyway.

So, anyway, let me know if you find a solution to the problem where sometimes the workers simply don't mine gold as they are told, and the custom AI dies. I would be quite interested. In the meantime, I can solve the problem by rewriting the game, so that I don't have to deal with Activision Microsoft apathetic money men.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,220
Be aware that with latest wc3 patches, lua is now the execution engine for wc3 scripts, even if your code is jass. I'm told that this is more efficient, so "slow" algorithms are less relevant than ever
I thought that this was a proposed feature that never made it into Reforged before main development stopped. Last I knew the dev working on this ran into some issue so the change was pulled and never made it to live. So Reforged was still be using the JASS virtual machine for JASS script and the Lua virtual machine for Lua. Unless one of the recent melee balance focused patches somehow incorporated this change...
 

~El

~El

Level 17
Joined
Jun 13, 2016
Messages
559
probably not the advice you're looking for but i think it needs to be said

if you're on retail, seriously just ditch jass and use lua (or any of the languages that can transpile to it - ts, c#, etc.). jass is an extremely simplistic language to a point where it's an absolute pain in the ass to work with for anything of mid-level (or more) complexity. pain points include: no custom types (also no dynamic typing), no dynamic allocation (emulated only with arrays and smart id allocation), ops limit (esp. on older patches - you'll be running into this for any kind of serious logic. not as big of an issue on modern retail), the list goes on. lua is also magnitudes faster than jass as an execution engine

a lot of people here will still prefer jass/vjass but i argue that it's more out of habit than any real benefit that jass has. if you're coming with experience from another well-established programming language, you'll be endlessly frustrated with its shortcomings

if you're not on retail and don't have access to lua, i'd suggest at least looking at Wurst as an alternative. you can also take a look at W3CE since that also doesn't run on reforged and has lua as well as wasm for scripting options. someone else has made a PoC c++ layer to write maps in via wasm
 
a lot of people here will still prefer jass/vjass but i argue that it's more out of habit than any real benefit that jass has. if you're coming with experience from another well-established programming language, you'll be endlessly frustrated with its shortcomings
I tried to rewrite a simulator of the game using LibGDX game engine as mentioned above, and using the stuff I learned about parsers in my university compilers course I wrote a JASS parser with ANTLR for parser generation combined with an interpreter that allows my LibGDX game to run War3 maps and their jass script, so that I can continue to support my existing mannerisms of liking JASS for no particularly good reason other than that nostalgia for my hobbies and the compatibility that it has with existing dorky Warcraft 3 tools.

So, I wanted to add my 2 cents here that the opinion of @~El from an ideological standpoint is entirely correct in terms of user experience.

However, I would also like to flip that back and ask the question, does retail allow .ai files to contain LUA format code? In general, I would anticipate that the integration of Warcraft 3 lua based systems (and maybe even Wurst->Jass compilation) is probably much worse for .ai files than for war3map.j files, even though we can generally think of both files as "Jass" because they use the same syntax.

I would also be curious if anybody knows whether LUA is available on W3CE for AI scripts. I wouldn't be totally surprised to hear that W3CE got it right and allows lua in both map script and AI, but that retail only allows lua in map script, or some-such. But I don't remember, so I was curious if somebody else who knows could add their thoughts.

It seems entirely possible to me that lua and wurst might be "the better user scripting experience" but that their integration and support with .ai files might be trashy.
 

Cokemonkey11

Spell Reviewer
Level 30
Joined
May 9, 2006
Messages
3,560
probably not the advice you're looking for but i think it needs to be said

if you're on retail, seriously just ditch jass and use lua (or any of the languages that can transpile to it - ts, c#, etc.). jass is an extremely simplistic language to a point where it's an absolute pain in the ass to work with for anything of mid-level (or more) complexity. pain points include: no custom types (also no dynamic typing), no dynamic allocation (emulated only with arrays and smart id allocation), ops limit (esp. on older patches - you'll be running into this for any kind of serious logic. not as big of an issue on modern retail), the list goes on. lua is also magnitudes faster than jass as an execution engine

a lot of people here will still prefer jass/vjass but i argue that it's more out of habit than any real benefit that jass has. if you're coming with experience from another well-established programming language, you'll be endlessly frustrated with its shortcomings

if you're not on retail and don't have access to lua, i'd suggest at least looking at Wurst as an alternative. you can also take a look at W3CE since that also doesn't run on reforged and has lua as well as wasm for scripting options. someone else has made a PoC c++ layer to write maps in via wasm

This is an incredibly limited and low-context perspective

Jass has a lot of similarities to many general purpose programming languages that Lua lacks
 
Jass has a lot of similarities to many general purpose programming languages that Lua lacks
So, I actually almost never used lua for Reforged, but I did help/play with a CanFight project that he added me to where he was developing with TypeScript to Lua as his configuration.

And I have to say I was impressed. I've gone off in other directions and not personally created any large-scale projects for Reforged, so when I did stuff on Reforged I tended to write extremely throw-away and leaky JASS because it didn't need transpilers or mode changes or any of that, and I could just go into the Trigger Editor and hack something up. But I feel I have a certain respect for people developing things in something like TypeScript to Lua, because it offers them the ability to use those syntaxes that are common with other languages (that both Lua and Jass lack).

Is there a reason for that perspective to be uninformed as well? I haven't done a lot of Wc3 lua, to be fair.

But still, on the main topic, my experiences with AI JASS were maybe in hindsight what I would describe as borderline miserable. I enjoyed it because I enjoyed the source material, and because I wanted to do it. But the tool of using JASS syntax for AI files exists because it was reasonably fun/fast for Blizzard to implement in 2002 with their existing JASS system, not because it is some robust solution to developing computer player brains. That's why I think it is much more on topic for us to investigate and post back here whether LUA is even usable in the context of AI files at all. If it is not, and they only ever use the older system, then discussions of lua for this topic could most likely be discarded.

Edit: for what it's worth, I would also be skeptical of the availability of Wurst tools for AI files. A Wurst developer/contributor like @Frotty who might be very familiar with the system would most likely tell us that Wurst is usable for AI files, but I'm guessing that online tutorials for getting a basic Wurst configuration would probably be wrong for AI files and probably be focused on map script. When you move to AI files, you would probably have to throw out large portions of the Wurst stdlib as being incompatible, or whatever, because the AI file JASS environment is such a soup of gobbletygook by comparison to the map script JASS environment.
 
Top