- Joined
- Nov 6, 2009
- Messages
- 279
Can somebody explain or post a link about operators and keywords? And are modules something more than struct expansions?
Last edited:
struct a
b data
endstruct
struct b
a dat
endstruct
Thats quite simple.
Keywords allow you to acces stuff "below" your code.
If two structs use each other, like
This throws errors without keywords.JASS:struct a b data endstruct struct b a dat endstruct
Operators are "=", so you can call functions via normal "sets". There is more, but I have to go![]()
method operator ohMyGod= takes real omg
set this.myreal = omg
call SetUnitFacing(this.myUnit, omg)
endmethod
set this.ohMyGod = 325.
Okay, just an addition:
keywords are also used for the .execute and .evaluate methods, just anything that is below the calling code.
Method operators allow you, to access functions with a "set".
For example: (= means set, there is > for comparisons, and so on. An operator without anything means "read" (like reading a variable))
Would be called via:JASS:method operator ohMyGod= takes real omg set this.myreal = omg call SetUnitFacing(this.myUnit, omg) endmethod
JASS:set this.ohMyGod = 325.
What makes operators useful?
You can define seperate methods for getting and retrieving data.
For example, in my projectile system it is much more efficient to keep all of the variables such as speed in per interval times, but you give the speeds in a per second time.
Thus, using operators, I can do:
p.Velocity = 100
and have it automatically conerted to 100 * INTERVAL (which is usually 0.04). This also allows the user to get the speed whenever he desires and have it return the right thing, without requiring usage of a function and making things more complicated on his end.
It's more of an aesthetics thing than anything, but it really is much more beautiful and sense making.
cJass seems to be the most hated language but it provides some extensions that vJass doesn't have, but I don't need them (they love their "define").
Method operators are nothing but normal functions, that take a SINGLE argument and are called via "set this.opMethod = xyz".
Modules seem to be the same then delegates for me, dunno what's the difference :O
Read this: http://www.wc3c.net/vexorian/jasshelpermanual.html![]()
And seriously man cJass?
scope Win initializer Init:
private player P
private void Init():
group g = groups.Get()
P = Player(0)
GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, Filter(lambda bool()
{
return GetOwningPlayer(GetFilterUnit()) == P
}))
ForGroup(g, lambda void()
{
KillUnit(GetEnumUnit())
})
groups.Give(g)
//! zinc
scope Win
{
Player P
function onInit()
{
group g = CreateGroup(); //Seriously was that group.get thing cJass intern?
P = Player(0);
GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, function() -> boolean
{
return GetOwningPlayer(GetFilterUnit()) == P;
});
ForGroup(g, function()
{
KillUnit(GetEnumUnit());
});
DestroyGroup(g);
g = null;
}
}
//! endzinc
#define
{
<CreateUnit>(unit) = CreateUnit(unit, Player(0), 0, 0, 0)
<CreateUnit>(unit, player) = CreateUnit(unit, player, 0 ,0 ,0)
<CreateUnit>(unit, player, x, y) = CreateUnit(unit, player, x, y, 0)
<CreateUnit>(unit, player, x, y, f) = CreateUnit(unit, player, x, y, f)
}