- Joined
- Sep 3, 2009
- Messages
- 458
So I have a question. But first let me show you two different codes that should do the same thing.
Now in the first code I use
Basically I check if data.ctime > 1.0 and I check again if finish is == false.
What this does is that if data.ctime becomes less than 1.0 it runs the code where it checks if finish == false. If false it will run the code then set data.finish == true so that it will not run another time.
So this Code works but lest got to the second code.
In the second code
Instead of making an additional if I just do if data.ctime > 1.0 and data.finish == false
What I don't understand is when I set data.finish == true, it still runs the code. In theory it should be working like the first code but it doesn't
Please enlighten me I'm still new with vJass/Jass in general. Please and thank you
JASS:
private static method Loop takes nothing returns nothing
local integer i = 1
loop
exitwhen i > TOTAL
set data = TRANS_ARRAY[i]
if data.revert == false then
if data.ctime > 1.0 then
set data.ctime = data.ctime - TICK
else
if data.finish == false then
call DestroyEffect(AddSpecialEffect("", GetUnitX(data.master), GetUnitY(data.master)))
call BJDebugMsg("FINISHED!")
call RemoveItem(UnitRemoveItemFromSlot( data.master, 0 ))
call UnitAddItemToSlotById( data.master, TRANS_ITEM[GetUnitPointValue(data.servant)], 0 )
call ShowUnit( data.servant, false)
set data.finish = true
endif
endif
else
call RemoveItem(UnitRemoveItemFromSlot( data.master, 0 ))
call UnitAddItemToSlotById( data.master, TRANS_WEAPON, 0 )
call ShowUnit( data.servant, true)
call SetUnitX( data.servant, GetUnitX(data.master))
call SetUnitY( data.servant, GetUnitY(data.master))
set TRANS_ARRAY[i] = TRANS_ARRAY[TOTAL]
set TOTAL = TOTAL - 1
set i = i - 1
call data.destroy()
endif
if TOTAL == 0 then
call PauseTimer(TRANS_TIMER)
endif
set i = i + 1
endloop
endmethod
JASS:
private static method Loop takes nothing returns nothing
local integer i = 1
loop
exitwhen i > TOTAL
set data = TRANS_ARRAY[i]
if data.revert == false then
if data.ctime > 1.0 and data.finish == false then
set data.ctime = data.ctime - TICK
else
call DestroyEffect(AddSpecialEffect("", GetUnitX(data.master), GetUnitY(data.master)))
call BJDebugMsg("FINISHED!")
call RemoveItem(UnitRemoveItemFromSlot( data.master, 0 ))
call UnitAddItemToSlotById( data.master, TRANS_ITEM[GetUnitPointValue(data.servant)], 0 )
call ShowUnit( data.servant, false)
set data.finish = true
endif
else
call RemoveItem(UnitRemoveItemFromSlot( data.master, 0 ))
call UnitAddItemToSlotById( data.master, TRANS_WEAPON, 0 )
call ShowUnit( data.servant, true)
call SetUnitX( data.servant, GetUnitX(data.master))
call SetUnitY( data.servant, GetUnitY(data.master))
set TRANS_ARRAY[i] = TRANS_ARRAY[TOTAL]
set TOTAL = TOTAL - 1
set i = i - 1
call data.destroy()
endif
if TOTAL == 0 then
call PauseTimer(TRANS_TIMER)
endif
set i = i + 1
endloop
endmethod
Now in the first code I use
JASS:
if data.ctime > 1.0 then
set data.ctime = data.ctime - TICK
else
if data.finish == false then
call DestroyEffect(AddSpecialEffect("", GetUnitX(data.master), GetUnitY(data.master)))
call BJDebugMsg("FINISHED!")
call RemoveItem(UnitRemoveItemFromSlot( data.master, 0 ))
call UnitAddItemToSlotById( data.master, TRANS_ITEM[GetUnitPointValue(data.servant)], 0 )
call ShowUnit( data.servant, false)
set data.finish = true
endif
endif
Basically I check if data.ctime > 1.0 and I check again if finish is == false.
What this does is that if data.ctime becomes less than 1.0 it runs the code where it checks if finish == false. If false it will run the code then set data.finish == true so that it will not run another time.
So this Code works but lest got to the second code.
In the second code
JASS:
if data.ctime > 1.0 and data.finish == false then
set data.ctime = data.ctime - TICK
else
call DestroyEffect(AddSpecialEffect("", GetUnitX(data.master), GetUnitY(data.master)))
call BJDebugMsg("FINISHED!")
call RemoveItem(UnitRemoveItemFromSlot( data.master, 0 ))
call UnitAddItemToSlotById( data.master, TRANS_ITEM[GetUnitPointValue(data.servant)], 0 )
call ShowUnit( data.servant, false)
set data.finish = true
endif
Instead of making an additional if I just do if data.ctime > 1.0 and data.finish == false
What I don't understand is when I set data.finish == true, it still runs the code. In theory it should be working like the first code but it doesn't
Please enlighten me I'm still new with vJass/Jass in general. Please and thank you