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

[JASS] Help with advanced JASS

Status
Not open for further replies.
Level 5
Joined
Aug 16, 2007
Messages
149
Hi guys I learned JASS about a month or 2 ago now and I'm just starting to properly get the hang of it. Anyways theres 2 questions I really want answering that no tutorial I've read seems to answer properly (well, I suppose wyrmlord brushes over #2 but doesn't at all explain it enough)

#1:When browsing the JassCraft library of functions etc I came across the different object types: they were declared sort of like maybe constant variables. Heres what I think the syntax is:
JASS:
type typename extends parenttype
heres an example which declares the unit type:
JASS:
type unit extends widget
//unit is the type being declared
//widget is unit's parent or root type - you can give
//units as a param for a function which takes widgets
It would certainly be good to know how to use custom types and how to set their attached(I don't think thats the correct term)variables (such as a unit has hit points, man points, defense points, attack points...)

#2:what are boolexpr and how to use them? Because without this knowledge I can't properly use most enum functions and quite a bit more useful JASS. Wyrmlord just said, in his tutorial, "its a condition, kind of" which doesn't actually help me one bit

The first one might be me wanting to do more than JASS allows, but I think since you can declare custom types there must be a way to use them to your advantage in warcraft.

I hope you can help me with these problems as I think after I've learned these I'll be on my way to mastering JASS and will (hopefully) come up with many good systems and spells in JASS in the future.
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
Wow, one of the nicest thread I've ever seen.

I really don't understand the first question, sorry, but I'll be happy to answer the second one :)

A boolexpr is short for boolean expression, I think. It's a string-based handle which was considered as leaking handle before, but later people found out that it is (like strings) able to recycle and destroying it (DestroyBoolExpr) can cause errors. One of those errors is that if multiple boolexprs were created from the same function, destroying one would destroy the others, I believe there are more errors, but I'm not sure.

A boolexpr can be generated with these functions: Condition(), Filter(), And(), Or(), Not() (maybe there are more). It is used mainly for trigger conditions and GroupEnum functions. It is said that boolexprs generated by And()/Or()/Not() leak, I believe that is true, so better destroy those, but better avoid those, you can just use keywords and/or/not that are much better, faster and easier to use.

Condition() and Filter() functions are probably exactly the same, nobody found the difference yet.

If you noticed, TriggerAddCondition (in InitTrig_ functions) uses a boolexpr as a parameter.

Boolexprs are used almost always in GroupEnum functions and they are that matching part in GUI's Pick every unit in unit group functions. Matching unit is GetFilterUnit() in JASS. Example code:

JASS:
function GroupFilter takes nothing returns boolean
    return GetWidgetLife(GetFilterUnit()) > 0
endfunction

function EnumSomeGroup takes nothing returns nothing
    local group g = CreateGroup()
    local boolexpr b = Filter(function GroupFilter)
    local real x = 0
    local real y = 0
    
    call GroupEnumUnitsInRange(g, x, y, 500, b)

    // do something with the group here....
    
    call DestroyBoolExpr(b)
    call DestroyGroup(g)
    
    set g = null
    set b = null
endfunction


Not that all functions that are used as boolexprs must return a boolean, because it has to be a condition for those units. This examples filters only units that are alive.

I'm destroying the boolexpr because there is no chance of interfering, there is no chance that a boolexpr will be created (from the same function) and destroyed in the meantime, so if you have no waits between creating and destroying a boolexpr, that means there is no chance anything bad could happen.

I hope you understand those now :)
 
Level 20
Joined
Apr 22, 2007
Messages
1,960
Silvenon, never destroy boolexpr's. They don't need to be destroyed (mess around with boolexpr's and the H2I bug, and you'll see what I mean). They don't need to be nulled either.

@Bubba Ex.
You can't declare custom types in Jass. Sorry :(
 
Level 5
Joined
Aug 16, 2007
Messages
149
@Silvenon
is there no way of making a boolexpr without needing another function?

@HINDYhat
why would JassCraft tell you syntax such as
JASS:
type animal extends unittype
(statement must be outside function,global decleration,struct etc) is correct when theres no way of using it to do anything then?
 
Level 20
Joined
Apr 22, 2007
Messages
1,960
Bubba Ex, because that's the syntax used in common.j. Try it out in the editor, you'll see it doesn't work.

There is a way, though, to use the 'type' syntax with vJass (jasshelper), but I haven't looked into that yet. Your best bet now is to use structs (vJass again).
 
Level 5
Joined
Aug 16, 2007
Messages
149
ok maybe I'll look into vJass (I haven't got round to learning it yet) but if custom types were possible it would be cool (and could be listed as an advantage of JASS over GUI)
thx anyway
 
Level 20
Joined
Apr 22, 2007
Messages
1,960
Well they're not REALLY custom types. But structs and stuff in vJass will emulate custom types. JassHelper is just a preprocessor, so it will read through your vJass code, and then compile it to regular Jass (only during testing though). So yes, custom types are possible with vJass, but also with regular Jass (just alot harder to make and use, and requires good knowledges of arrays and general Jass).
 
Level 5
Joined
Aug 16, 2007
Messages
149
right... tyvm for help but seems it's lot more complicated than I hoped and needs vJass - I think that's what I need to learn next then...
 
Level 11
Joined
Feb 18, 2004
Messages
394
you could potentially define your own types if you wanted to, i would imagine. You would have to do it in common.j. (or maybe blizzard.j) It would serve no real purpose, as all types are 4 bytes long anyway. (Thus why the return bug works so well.) Types which extend from handle are internally implimented objects, whereas the variables of that type are pointers to such an object. Strings are also pointers, but to a diffrent table of data. (Strings in JASS are immutable, meaning something like "abc" + "def" creates 3 strings: "abc", "def", and "abcdef". Strings are not well cleaned, so avoid creating new unique strings.) Boolean, code, integer, and real are all basic types. boolean is true at any value except 0, and false at 0. I2B(0) == false I2B(42) == true there are exceptions to this, which are bugs. (Some natives ignore that rule, causing some big problems sometimes)

Boolexprs are similar to the code data type. A boolexpr is in essence a pointer to a function which returns a boolean. Condition() and Filter() have a chaching mechanism, meaning they will return the same boolexpr for the same function input. This means that destroying boolexprs is not needed, and potentially error-causing. Don't create a boolexpr on a function that returns nothing, thats just stupid.

In summary of your original two questions:
1: Custom typedefs are useless, but probably possible in a custom common.j
2: Boolexprs are pointers to functions which return boolean.
 
Level 5
Joined
Aug 16, 2007
Messages
149
ok but going back to what HINDYhat said about using structs as sort of custom types: I've read up a bit on vJass, but would you be able to use them as function params or return values? I mean, I think I understand how structs could be used as custom types but that would be useless if unusable in function params&return values.
 
Level 11
Joined
Feb 18, 2004
Messages
394
Structs exist as semi-normal types prior to and for some stages of vJASS->JASS compilation. After compilation, a struct ends up being a bunch of global arrays and functions. (Like a create function) A struct-type variable compiles down to an integer type variable. Struct methods become functions with an additional integer type parameter, a "this" parameter. The integer that the create function returns represents a location in the arrays which consist of the member variables. Thus MyStruct.create.x compiles down to something like MyStruct_x[MyStruct_create()].

When programming in vJASS, you can cast a struct-type value to an integer with a function-style cast, as in: integer(MyStructVariable) you can also cast an integer to a struct type. MyStruct(MyIntegerVar)

Bleh, go read the JASS Helper manual. it explains most of this and more.
http://wc3campaigns.net/vexorian/jasshelpermanual.html
 
Level 5
Joined
Aug 16, 2007
Messages
149
kk ty. thing is I just downloaded jassnewgenpack and tesh, but tesh highlights vJass syntax, but in a syntax check comes up with all kinds of syntax errors, not in function errors, etc! Just in case my code is wrong, here it is:
JASS:
struct HelloWorld
        string helloworld = " Hello World"
        method ShowHelloWorld takes nothing returns nothing
            call BJDebugMsg(this.helloworld)
        endmethod
endstruct
(its not supposed to do anything good, just to get me used to using vJass)

EarthFury, I think you've helped me enough to deserve +REP
 
Level 11
Joined
Feb 18, 2004
Messages
394
The syntax checker in TESH does not work with vJASS. It only works with normal, vanilla JASS. (it uses pJASS)

if you want to check your syntax, save the map. (It uses the JASSHelper compiler to compile vJASS to JASS, then it uses pJASS to check the syntax. This means the world editor will no longer crash due to syntax errors. when using NewGen, at least.)
 
Level 5
Joined
Aug 16, 2007
Messages
149
if it's an extension for NewGen it should work with vJass but wtever I suppose I don't need to keep checking my syntax constantly.
 
Level 5
Joined
Aug 16, 2007
Messages
149
i suppose but I prefer something that's just like, click a button instead of saving the map when sometimes you might not want to save it anyway. If you know what I mean lol.
 
Status
Not open for further replies.
Top