• 🏆 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!

[JASS] Classes and lists in world editor or Jass?

Status
Not open for further replies.
Level 3
Joined
Feb 25, 2018
Messages
15
Hi, so I have a few questions about the editor

I have this map I want to make and it's mainly data driven. I'm stuck at the moment because I really need a class to get what I'm after.

when you build a farm, it needs to have a lot of unseen data which can be linked together. for example, a villager will spawn, who has a level of wealth. the villager takes a home as his own, and the farm itself now recognizes that it belongs to the villager.

in a programmatic sense, I would have a list of <farm> class objects, which would each have a variable like <inhabitants>, which would be populated by a list of all the unit objects which inhabit it.

if the farm gets destroyed, it would get stricken from the list and each of it's inhabitants would have the farm struck from their <home> variable and become homeless.

the problem is I only really have arrays at the moment, I'm not sure if lists or classes exist in the world editor or JASS, and if I plan on having the data stored using arrays I think that I will either have massive amounts of empty array variables after a number of farms or villagers have died or otherwise been removed and I would also have to loop through every single unit if I wanted to check that the unit dying would be one from the list.

is there a better way to do this?
 
Hi there, welcome. : )

JASS itself not by default, but there are several pre-compiler that allow to write in a new syntax and which will then allow class-like features. So we can write with good OOP style, and then in the end it will be translated to valid JASS code, so Warcraft can read it again.

I would recommend to have a look at Wurst, and you can scan Frotty's posts, to get some more threads for info (he is a main author of Wurst). It's maybe currently provides the best and most modern environment for coders.

There is also a bit older, but very widely used JASS extension called vJASS. It also required a third party tool, JASSHelper, which is for example integrated here already.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
As IcemanBo mentioned, vJass and Wurst both provide a bunch more useful language features which might help you with this. Wurst looks neat and is fairly feature-complete, but vJass is much more widely used and has the advantage of being both more widely supported and, more importantly, much closer syntax-wise and design-wise to vanilla Jass (thus giving you a clearer idea of how it will perform and making it easier for others to read it: everyone who's ever coded in the WE ought to know Jass, whereas many people won't know Wurst).

All that being said, the cleanest way to do this is probably to use a hashtable: you can use GetHandleId(farm) for the parent key and, for each farm, remember:

  • The number of inhabitants in it.
  • A vector of the inhabitants from indices 0..(size - 1).
 
Level 3
Joined
Feb 25, 2018
Messages
15
As IcemanBo mentioned, vJass and Wurst both provide a bunch more useful language features which might help you with this. Wurst looks neat and is fairly feature-complete, but vJass is much more widely used and has the advantage of being both more widely supported and, more importantly, much closer syntax-wise and design-wise to vanilla Jass (thus giving you a clearer idea of how it will perform and making it easier for others to read it: everyone who's ever coded in the WE ought to know Jass, whereas many people won't know Wurst).

All that being said, the cleanest way to do this is probably to use a hashtable: you can use GetHandleId(farm) for the parent key and, for each farm, remember:

  • The number of inhabitants in it.
  • A vector of the inhabitants from indices 0..(size - 1).
thanks
 
Status
Not open for further replies.
Top