- Joined
- Jul 10, 2007
- Messages
- 6,306
lib AutoFly(UnitIndexer):
onInit:
EVENT_ANY_UNIT_INDEXED.register(Filter(lambda bool:
if GetEventUnit().addAbility('Amrf'):
GetEventUnit().removeAbility('Amrf')
))
Not everyone knows this algorithm...
It's like sometimes I try to find an algorithm online and there will be 0 tuts on it... it'll be like, everyone knows it, but nowhere is it explain. Doesn't that drive you crazy as well?
It requires your library UnitIndexer.Also, this is just a cnp into a map to make everything work, nothing special necessary =).
Using a custom CreateUnit function means that you have to change all CreateUnit calls in every resource you might be using to use your own CreateUnit function.
There's a non UnitIndexer version and an AIDS version at TH under that thread I linked.
library AutoFly /* v1.0.0.0
-Credits to Azlier for original
-thehelper.net/forums/showthread.php/139729-AutoFly
*************************************************************************************
*
* Makes SetUnitFlyHeight possible
*
*************************************************************************************
*
* */uses/*
*
* */ UnitIndexer /* hiveworkshop.com/forums/jass-functions-413/unit-indexer-172090/
*
************************************************************************************/
private function i takes nothing returns boolean
if UnitAddAbility(GetIndexedUnit(),'Amrf') then
return not UnitRemoveAbility(GetIndexedUnit(),'Amrf')
endif
return false
endfunction
private module Init
private static method onInit takes nothing returns nothing
call RegisterUnitIndexEvent(Condition(function i), UnitIndexer.INDEX)
endmethod
endmodule
private struct Inits extends array
implement Init
endstruct
endlibrary
ehhh, I don't know which one would be faster, but the dif in speed between them is so marginal that it doesn't even matter >.>.
The fact that I can't even tell which one is faster is proof of that, lol.
private function i takes nothing returns boolean
return UnitAddAbility(GetIndexedUnit(), 'Amrf') and UnitRemoveAbility(GetIndexedUnit(), 'Amrf')
endfunction
private function i takes nothing returns boolean
return UnitAddAbility(GetIndexedUnit(), 'Amrf') and UnitRemoveAbility(GetIndexedUnit(), 'Amrf') and false
endfunction
private function i takes nothing returns boolean
return UnitAddAbility(GetIndexedUnit(), 'Amrf')...) and UnitRemoveAbility(GetIndexedUnit(), 'Amrf')
endfunction
call _Z14UnitAddAbilityv
testb %al, %al
je .L4
call _Z17UnitRemoveAbilityv
testb %al, %al
je .L4
movl $1, %eax
jmp .L5
.L4:
movl $0, %eax
.L5:
popq %rbp
.LCFI8:
.cfi_def_cfa 7, 8
ret
private function i takes nothing returns nothing
call UnitAddAbility(GetIndexedUnit(), 'Amrf')...)
call UnitRemoveAbility(GetIndexedUnit(), 'Amrf')
endfunction
pushq %rbp
.LCFI6:
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.LCFI7:
.cfi_def_cfa_register 6
call _Z14UnitAddAbilityv
call _Z17UnitRemoveAbilityv
popq %rbp
.LCFI8:
.cfi_def_cfa 7, 8
ret
true or true and false
.true and false
to evaluate first making the whole expression evaluate to true because AND should have higher precedence than OR, but in JASS, it appears that they evaluate from left to right. I never noticed this before because I used parentheses to structure boolean expressions that mix different operations.Considertrue or true and false
.
You'd expecttrue and false
to evaluate first making the whole expression evaluate to true because AND should have higher precedence than OR, but in JASS, it appears that they evaluate from left to right. I never noticed this before because I used parentheses to structure boolean expressions that mix different operations.
and
have higher precedence than or
? Most of the time parentheses are a good thing b/c every operator is strange to us except +- and */ since we learned them forever.Even though this seems to be the spec because JASS has no spec and thus the implementation is the spec in itself, I hate this so much and thus I consider it a bug just like how I consider raw pointers in C++ a bug. They are a pest I tell you
call
b4 every call-statement in jass yet i don't consider it a bug.and
and or
have the same precedence or not. But this totaly doesnt't matter. It's a small annoyance for people thinkging every language should be alike or which take too much focus on syntax.Muh feelings. I don't like this therefore it's a bug.
I'm not a fan of writing call b4 every call-statement in jass yet i don't consider it a bug.
Your definition of bug is not mine.