- Joined
- Oct 17, 2009
- Messages
- 1,579
function Function2 takes nothing returns string
local string message = SomeFunction("Hello World")
endfunction
function SomeFunction takes string returns nothing
local string a message
a message = 'Something is wrong'
call DisplayTextToPlayer(Player(0), 0, 0, a message)
endfunction
function DivideNumbers takes integer n returns nothing
// your code here
endfunction
unction ChallengeTrigger takes nothing returns nothing
local unit u = GetTriggerUnit()
//This unit is in the game, it needs to be kept (hint)
local effect SFX = AddSpecialEffect(…)
local group g = CreateGroup()
local unit u2
//this is going to be a dummy unit and should be removed (hint)
local real r = 4
//actions
//(hint) only one of these variables isn’t nulled.
endfunction
Challenge!
-Clean this function of all memory leaks:
fthats it.JASS:unction ChallengeTrigger takes nothing returns nothing local unit u = GetTriggerUnit() //This unit is in the game, it needs to be kept (hint) local effect SFX = AddSpecialEffect(…) local group g = CreateGroup() local unit u2 //this is going to be a dummy unit and should be removed (hint) local real r = 4 //actions //(hint) only one of these variables isn’t nulled. endfunction
function Function2 takes nothing returns string
local string message = SomeFunction("Hello World") // cant use functions before their declaration
// missing return
endfunction
function SomeFunction takes string returns nothing // parameters must have a name // function must return a string
local string a message // identifiers may not have a space inside
a message = 'Something is wrong' // strings have to be inside double quotes
// assigning a variable works like this:
// set <variableName> = <newValue>
call DisplayTextToPlayer(Player(0), 0, 0, a message)
// missing return
endfunction
function SomeFunction takes string s returns string
local string a_message
set a_message = "Something is wrong"
call DisplayTextToPlayer(Player(0), 0, 0, a_message)
return a_message
endfunction
function Function2 takes nothing returns string
local string message = SomeFunction("Hello World")
return message
endfunction
function DivideNumbers takes integer n returns nothing
// your code here
endfunction
function ModuloInteger takes integer dividend, integer divisor returns integer
local integer modulus = dividend - (dividend / divisor) * divisor
// If the dividend was negative, the above modulus calculation will
// be negative, but within (-divisor..0). We can add (divisor) to
// shift this result into the desired range of (0..divisor).
if (modulus < 0) then
set modulus = modulus + divisor
endif
return modulus
endfunction
How do you know what is the ID of a spell?
function Omni_Slash_Conditions takes nothing returns boolean
return GetSpellAbilityId() = 'A000'
endfunction
function Oni_Slash_Actions takes nothing returns nothing
local unit caster = GetSpellAbilityUnit()
local location start_loc = GetUnitLoc(caster)
local unit enemy
local group enemy_group = CreateGroup()
local integer hit_count = 8
call GroupEnumUnitsInRangeOfLoc(enemy_group,start_loc,800.0,null)
loop
set enemy = FirstOfGroup(enemy_group)
exitwhen enemy == null or hit_count == 0
if IsUnitEnemy(enemy, GetOwningPlayer(caster))then
set temp_loc = GetUnitLoc(enemy)
call SetUnitPositionLoc(caster, temp_loc)
call UnitDamageTarget(caster, enemy, 100.0, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, null)
set hit_count = hit_count - 1
endif
call GroupRemoveUnit(enemy_group, enemy)
endloop
endfunction
function InitTrig_Slash takes nothing returns nothing
set gg_trg_Slash = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(gg_trg_Slash, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(gg_trg_Slash, Condition(function Omni_Slash_Conditions))
call TriggerAddAction(gg_trg_Slash, function Omni_Slash_Actions)
endfunction
function Omni_Slash_Conditions takes nothing returns boolean
return GetSpellAbilityId() == 'A000'
endfunction
function Omni_Slash_Actions takes nothing returns nothing
local unit caster = GetTriggerUnit()
local unit enemy
local group enemy_group = CreateGroup()
local integer hit_count = 8
call GroupEnumUnitsInRange(enemy_group,GetUnitX(caster),GetUnitY(caster),800.0,null)
loop
set enemy = FirstOfGroup(enemy_group)
exitwhen enemy == null or hit_count == 0
if IsUnitEnemy(enemy, GetOwningPlayer(caster))then
call SetUnitPosition(caster, GetUnitX(enemy),GetUnitY(enemy))
call UnitDamageTarget(caster, enemy, 100.0, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, null)
set hit_count = hit_count - 1
endif
call GroupRemoveUnit(enemy_group, enemy)
endloop
//Clear any potential leaks
call DestroyGroup(enemy_group)
set caster = null
set enemy = null
set enemy_group = null
endfunction
function InitTrig_Slash takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t, Condition(function Omni_Slash_Conditions))
call TriggerAddAction(t, function Omni_Slash_Actions)
endfunction
function Omni_Slash_Conditions takes nothing returns boolean
return GetSpellAbilityId() == 'A000'
endfunction
function Omni_Slash_Actions takes nothing returns nothing
local unit caster = GetTriggerUnit()
local unit enemy
local group enemy_group = CreateGroup()
local integer hit_count = 8
call GroupEnumUnitsInRange(enemy_group, GetUnitX(caster), GetUnitY(caster), 800.0, null)
loop
set enemy = FirstOfGroup(enemy_group)
exitwhen enemy == null or hit_count == 0
if IsUnitEnemy(enemy, GetOwningPlayer(caster))then
call SetUnitPosition(caster, GetUnitX(enemy), GetUnitY(enemy))
call UnitDamageTarget(caster, enemy, 100.0, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, null)
set hit_count = hit_count - 1
endif
call GroupRemoveUnit(enemy_group, enemy)
endloop
set caster = null
set enemy = null
call DestroyGroup(enemy_group)
set enemy_group = null
endfunction
function InitTrig_Omni_Slash takes nothing returns nothing
local trigger Omni_Slash = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(Omni_Slash, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(Omni_Slash, Condition(function Omni_Slash_Conditions))
call TriggerAddAction(Omni_Slash, function Omni_Slash_Actions)
endfunction
set enemy = FirstOfGroup(enemy_group)
exitwhen enemy == null or hit_count == 0
i have vjass but how do i use timers?
function endtime takes nothing returns nothing
call BlaBlaBla
endfunction
function onInit takes nothing returns nothing
local timer t = CreateTimer()
local real time = 30 //your timer count
call TimerStart(t, time, false, function endtime)
endfunction
CreateTimer()
native TimerStart takes timer whichTimer, real timeout, boolean periodic, code handlerFunc returns nothing