• 🏆 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] A problem about the struct inclusion

Status
Not open for further replies.
Level 1
Joined
Apr 4, 2009
Messages
4
I am learning both c++ and vjass now so I get a liittle confused.
in c++,when we have defined one class(eg.class bag),in the definition of another class,we can write

private bag thisbag

to create one private bag variable,but in jass,it get a liitle tricky,when we have defined one struct(eg,struct bag),in the definition of another struct,we are informed to write

private bag thisbag=bag.create().

to create one private bag variable.I just wonder if we can write

private bag thisbag

to get the things done because after the definition for bag struct is done,the compiler regards the bag as a new data type so we can directly declare it here.

one more question:In GUI,After I create one global variable of type unit,I can not find it in the unit parameter(the variable set) in the parameter list of event "specific unit event".What is wrong here?
 

Cokemonkey11

Spell Reviewer
Level 30
Joined
May 9, 2006
Messages
3,540
JASS:
private bag thisbag
works fine, but you won't be able to use its contents without setting it to something first.

Here's an example:

JASS:
    private function p takes nothing returns nothing
        local cruiserDat tempDat
        local integer index=0
        local effect fx
        local unit sentry
        local player tempPlayer
        loop
            exitwhen index>dbIndex
            set tempDat=cruiserDB[index]
            set tempDat.offset=tempDat.offset-10
            call SetUnitFlyHeight(tempDat.cruiser,(.005)*(tempDat.offset*tempDat.offset)+150,0)
            call SetUnitX(tempDat.cruiser,GetUnitX(tempDat.cruiser)-10)
            call SetUnitVertexColor(tempDat.cruiser,255,255,255,255-R2I(.2*(GetUnitFlyHeight(tempDat.cruiser))))
            if tempDat.offset<150 then
                if tempDat.box==null then
                    set tempPlayer=GetOwningPlayer(tempDat.cruiser)
                    set tempDat.box=CreateUnit(tempPlayer,BOXID,GetUnitX(tempDat.cruiser),GetUnitY(tempDat.cruiser),270)
                    call SetUnitFlyHeight(tempDat.box,GetUnitFlyHeight(tempDat.cruiser)-100,0)
                endif
                if GetUnitFlyHeight(tempDat.box)>10 then
                    call SetUnitX(tempDat.box,GetUnitX(tempDat.box)-5)
                    call SetUnitFlyHeight(tempDat.box,GetUnitFlyHeight(tempDat.box)-20,0)
                elseif GetWidgetLife(tempDat.box)>1 then
                    set fx=AddSpecialEffect("Objects\\Spawnmodels\\Undead\\ImpaleTargetDust\\ImpaleTargetDust.mdl",GetUnitX(tempDat.box),GetUnitY(tempDat.box))
                    call DestroyEffect(fx)
                    set tempPlayer=GetOwningPlayer(tempDat.box)
                    call GroupEnumUnitsInRange(grp,GetUnitX(tempDat.box),GetUnitY(tempDat.box),150,Filter(function f))
                    call KillUnit(tempDat.box)
                    set sentry=CreateUnit(GetOwningPlayer(tempDat.box),SENTRYID,GetUnitX(tempDat.box),GetUnitY(tempDat.box),270)
                    call UnitApplyTimedLife(sentry,BUFFID,30)
                endif
            endif
            if GetUnitFlyHeight(tempDat.cruiser)<350 then
                call UnitAddAbility(tempDat.cruiser,BOMBCODE)
            else
                call UnitRemoveAbility(tempDat.cruiser,BOMBCODE)
            endif
            if tempDat.offset<-500 then
                call RemoveUnit(tempDat.cruiser)
                call tempDat.destroy()
                set cruiserDB[index]=cruiserDB[dbIndex]
                set dbIndex=dbIndex-1
                if dbIndex==-1 then
                    call PauseTimer(time)
                endif
            endif
            set index=index+1
        endloop
        set tempPlayer=null
    endfunction
 
Level 1
Joined
Apr 4, 2009
Messages
4
So,I see the difference between c++ and jass.Thanks to both of you.I will come up to more questions when I go forward in my mapping.
 
In GUI,After I create one global variable of type unit,I can not find it in the unit parameter(the variable set) in the parameter list of event "specific unit event".What is wrong here?
You're referring to the gg_unit_hf00_0000 game-generated variable. That is generated when you choose "select unit" from the trigger editor, and then the unit shows up in "specific unit" lists thereafter.

I recommend creating your units in JASS, because you'd be surprised the weird things GUI does.

Modifying a unit's starting mana individually translates into:
JASS:
call SetUnitState(u,UNIT_STATE_MANA,50.)

And once you modify his starting mana, there is no way to remove that modification, aside from deleting the whole unit!

Far worse, having an item drop auto-generates a massive trigger for what you'd think would happen. Instead of "TriggerRegisterDeathEvent" they create one trigger for EVERY unit you want to drop an item. I looked at WarChasers.j, and the auto-generated item drops consumed a whopping 60% of the total script size! :O
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
I would say C++ is a lot like Java, which shares similar syntax patterns as JASS but in no way does JASS come even close to the capabilities of a language like Java. Actual interfaces, nested classes (or "structs"), and plenty more.
 
Status
Not open for further replies.
Top