• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] If I want to use and learned vJass. Can I find basic tutorials?

Status
Not open for further replies.
Level 16
Joined
Mar 3, 2006
Messages
1,564
I wonder about this

JASS:
Initailizer xxx
JASS:
constant
tell me more, Plz!!

for the initializer. You probably know that when the map is saved a .j file is created.

At the end of the file is this:
JASS:
//***************************************************************************
//*
//*  Main Initialization
//*
//***************************************************************************

//===========================================================================
function main takes nothing returns nothing
    call SetCameraBounds(- 3328.0 + GetCameraMargin(CAMERA_MARGIN_LEFT), - 3584.0 + GetCameraMargin(CAMERA_MARGIN_BOTTOM), 3328.0 - GetCameraMargin(CAMERA_MARGIN_RIGHT), 3072.0 - GetCameraMargin(CAMERA_MARGIN_TOP), - 3328.0 + GetCameraMargin(CAMERA_MARGIN_LEFT), 3072.0 - GetCameraMargin(CAMERA_MARGIN_TOP), 3328.0 - GetCameraMargin(CAMERA_MARGIN_RIGHT), - 3584.0 + GetCameraMargin(CAMERA_MARGIN_BOTTOM))
    call SetDayNightModels("Environment\\DNC\\DNCAshenvale\\DNCAshenvaleTerrain\\DNCAshenvaleTerrain.mdl", "Environment\\DNC\\DNCAshenvale\\DNCAshenvaleUnit\\DNCAshenvaleUnit.mdl")
    call NewSoundEnvironment("Default")
    call SetAmbientDaySound("AshenvaleDay")
    call SetAmbientNightSound("AshenvaleNight")
    call SetMapMusic("Music", true, 0)
    call CreateCameras()
    call CreateAllUnits()
    call InitBlizzard()

    @call ExecuteFunc("jasshelper__init366")@

    call InitGlobals()
    call InitTrig_Initialization() // INLINED!!
    call ConditionalTriggerExecute(gg_trg_Initialization) // INLINED!!

endfunction

//***************************************************************************
//*
//*  Map Configuration
//*
//***************************************************************************

function config takes nothing returns nothing
    call SetMapName("TRIGSTR_001")
    call SetMapDescription("TRIGSTR_003")
    call SetPlayers(2)
    call SetTeams(2)
    call SetGamePlacement(MAP_PLACEMENT_USE_MAP_SETTINGS)

    call DefineStartLocation(0, 0.0, 0.0)
    call DefineStartLocation(1, - 1024.0, - 384.0)

    // Player setup
    call InitCustomPlayerSlots()
    call SetPlayerSlotAvailable(Player(0), MAP_CONTROL_USER)
    call SetPlayerSlotAvailable(Player(1), MAP_CONTROL_COMPUTER)
    call InitGenericPlayerSlots()
endfunction




//All initializer functions called in proper order:

function jasshelper__init366 takes nothing returns nothing


call ExecuteFunc("scopeName___xxx")
//------------------------------------

endfunction
Those 2 functions run before the map start (not sure though during loading or at initialization)

As for constant, this keyword is not vJASS; it already exists before the making of vJASS.

This will prevent the variables that use it from changing their values later in any part of the map script. But there are certain types of variables that can't use constant.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
But there are certain types of variables that can't use constant

False, however i think wc3mapoptimizer inline all constants, so something like that would be totally broken, each use of MY_GROUP would be replaced by CreateGroup(), and then a new group would be created :

constant group MY_GROUP = CreateGroup()

Constant handles are not that useful though, even if it's clearly a lack of wc3mapoptimizer to handle constant handles correctly. (but maybe it doesn't have this behavior anymore with the latest version, never tried)
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
constant group MY_GROUP = CreateGroup()

Should not be possible in the first place because CreateGroup is no constant function. Then again, I have never quite understood the marking of constant functions in jass. Independently from that, a pile of functions do not work in the globals block.

hashtable and group are default as constants, so no need to call them as such, since
the only way for them to work is by declaring InitHashtable() and CreateGroup(), and
you can never change it...

You can change the variable to null or another object of the kind.
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
Null variables are not unset, so you can at least read this null value or use it as a special parameter case in your own functions. My point was though that you can reset the variables and therefore such object vars are not constant by default. You are not even asked to give them an initial value.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
@Waterknight : Ok, i forgot about this constant function stuff.

But yeah i also don't get the usefulness of constant native functions in jass.
It would make sense if every constant functions could work with a constant variable, but i hardly see how for example constant native GetTriggeringTrigger takes nothing returns trigger could work with a constant trigger variable.
I mean, it seems that the way of which function are constant or not is "random".
Well, all responses event functions seem constant (Get...), but i don't get why for example the math api functions are not constant.
Same for constant native GetHeroLevel takes unit whichHero returns integer
Why it's constant and not native GetHeroXP takes unit whichHero returns integer, again just as an example.

Talking about custom (not native) function, if it's defined in blizzard.j it could be used inside a constant variable which is inside the map script (in theory, never tried).

Then the behavior of wc3mapoptimizer is not a real problem (if it acts like i say in the current version), since all create functions are not constant.
It would still inline constant handles which use a constant function such as Player(), but at least it doesn't break the code (or make leaks).

EDIT : Hmm, it will break a constant real variable which use GetHeroLevel, and probably with some other functions (i have not scrolled the whole common.j).
Meh, GetHeroLevel would always return 1 or 0, dependly if it's an hero or not, because afair even preplaced units are leveled up during the map init.
But still, a such constant would be still useful to know if an unit is an hero or not.
Oh, wait ... you can't create an unit inside a constant variable definition :p
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
@Troll-Brain: I said constant vars should not accept non-constant functions as values. Apparently, they do. At least optimizer could have a hint from that what to inline, or just leave all functions because printing in Order("abc") is likewise crap when it's not evaluated.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Hmm why he said that then :

I remember that I got an error when making a constant hashtable.

I'm 100 % sure InitHashtable works inside a not constant global variable definition, so well the script will "compile", but a constant variable "doesn't work" if it's used with a not constant function ?
Is it a lack of script validity checking from japi ? (i mean the map will start or not ? , in other words the script will be considered as valid or not by the jass vm ?)
Wc3 is crashing on map loading ?
Or is he wrong ?
 
Level 5
Joined
Jan 4, 2009
Messages
118
Err I ask something. Why I can't compare between Global and Local Variable.It's error and display message "Don't Allow toCompare it"

JASS:
if(udg_Kill[tmpInt] == 3)then
    // Do stuff
endif

It can't uses this?
 
Level 5
Joined
Jan 4, 2009
Messages
118
JASS:
function Trig_Check_Integer_Actions takes nothing returns nothing
    local integer Int_Kill
    
    if(udg_ScoreKills[Int_Kill] == 3)then
        set udg_ScoreKills[Int_Kill] = udg_ScoreKills[Int_Kill] + 1
    endif
endfunction

//===========================================================================
function InitTrig_Check_Integer takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterPlayerChatEvent( t, Player(0), "", false )
    call TriggerAddAction( t, function Trig_Check_Integer_Actions )
    set t = null
endfunction

error msg : Comparing two variables of defferent primatives types

I'll try on other map it allow me, but My Map don't allow...
 
Level 5
Joined
Jan 4, 2009
Messages
118
I create global from Crtl+B. I don't create global from this function. I don't use vJass. I use normal jass. Sorry for unclear Question. and This case What is problem?

I'll try on other map. It's still run and save normally, but my project map It's don't allowed me to use this compare.

Help me, Please.
 
Status
Not open for further replies.
Top