HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Switching code to vjass

09-06-2007, 07:37 AM#1
kentchow75
Collapse JASS:
function TimerAct takes nothing returns nothing
local timer t = GetExpiredTimer()
local string name = GetHandleString(t,"DiedName")
call BJDebugMsg(name)
call FlushHandleLocals(t)
call DestroyTimer(GetExpiredTimer())
endfunction
     
function TimerTest takes nothing returns nothing
local timer t = CreateTimer()
local string named = GetUnitName(GetDyingUnit())
call SetHandleString(t,"DiedName",named)
call TimerStart(t,10,false,function TimerAct)
set t = null
endfunction


//===========================================================================
function InitTrig_Test_If_Timer_Mui takes nothing returns nothing
    set gg_trg_Test_If_Timer_Mui = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Test_If_Timer_Mui,EVENT_PLAYER_UNIT_DEATH)
    call TriggerAddAction( gg_trg_Test_If_Timer_Mui, function TimerTest )
endfunction

This code uses local handle vars...which enchance it to MUI code..
So how do i make the same thing using vjass function?

It seems that i cant make it through struct...by my noob jassing skill
09-06-2007, 08:42 AM#2
Fireeye
Couldn't check for any syntax error, because i don't have a computer with WE here, however i think this should be the same in vJASS.
Collapse JASS:
globals
    DyingData array GlobDDat
    integer GlobDInteger = 1
    timer GlobDTimer = CreateTimer()
endglobals

struct DyingData
    string name = "" //Which string should be displayed
    integer timeout = 0 //The amount of literations till the message is displayed
    //If you don't know static methods remove the following part and uncomment the lines in TimerTest
    static method create takes string s, integer i returns DyingData
        local DyingData dat = DyingData.allocate()
        set dat.name = s
        set dat.timeout = i
        return dat
    endmethod
    //The part ends here
endstruct

function TimerAct takes nothing returns nothing
    local integer loopi = 1
    local string name
    loop
        exitwhen loopi >= GlobDInteger
        if GlobDDat[loopi].timeout <= 0 then
            set name = GlobDDat[loopi].name
            call BJDebugMsg(name)
            call GlobDDat[loopi].destroy()
            set GlobDInteger = GlobDInteger - 1
            set GlobDDat[loopi] = GlobDDat[GlobDInteger]
        else
            set GlobDDat[loopi].timeout = GlobDDat[loopi].timeout - 1
            set loopi = loopi + 1
        endif
    endloop
    if GlobDInteger == 1 then
        call PauseTimer(GlobDTimer)
    endif
endfunction
     
function TimerTest takes nothing returns nothing
    //remove the following line and use the comments below afterwards
    local DyingData dat = DyingData.create(GetUnitName(GetTriggerUnit()),10)
    //local DyingData dat = DyingData.create()
    //set dat.name = GetUnitName(GetTriggerUnit())
    //set dat.timeout = 10
    set GlobDDat[GlobDInteger] = dat
    set GlobDInteger = GlobDInteger + 1
    if GlobDInteger == 2 then
        call TimerStart(GlobDTimer,1,false,function TimerAct)
    endif
endfunction

//===========================================================================
function InitTrig_Test_If_Timer_Mui takes nothing returns nothing
    set gg_trg_Test_If_Timer_Mui = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Test_If_Timer_Mui,EVENT_PLAYER_UNIT_DEATH)
    call TriggerAddAction( gg_trg_Test_If_Timer_Mui, function TimerTest )
endfunction
09-06-2007, 09:07 AM#3
kentchow75
well...I'm not really known all bout vjass...
I just learnt some basics such as libraries,struct,scope..
Not those methods and static methods...

So in return, i'm not understand to your code..
Because i dont know static method, .allocate thingy..T.T

Anymore other method to done the request?
09-06-2007, 09:19 AM#4
Fireeye
The static thing is the same like with .create() but in this case you can parse arguments which can save a few lines in the actual triggers.
The allocate() thing is also used in the normal create() but invisible.
Due i replaced it here i've to add it manually.
So basically the create() command is originally the allocate() command which just search for an unused array and return its slot with an integer.
That means i could remove the static method and replace
Collapse JASS:
    local DyingData dat = DyingData.create(GetUnitName(GetTriggerUnit()),10)
with
Collapse JASS:
    local DyingData dat = DyingData.create()
    set dat.name = GetUnitName(GetTriggerUnit())
    set dat.timeout = 10