• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

quick question

Status
Not open for further replies.
Level 8
Joined
Jul 25, 2009
Messages
194
JASS:
function GA_Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterVariableEvent(t, "udg_DamageEvent", EQUAL, 1.00)
    call TriggerAddAction(t, ExecuteFunc("GA_Actions"))
    set t = null
endfunction

im getting this error: Cannot convert nothing to code
anyone know how to fix this?
Im trying to make function GA_Actions (takes nothing returns nothing) run when the event for t is triggered.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
I'm not sure but:
JASS:
 call TriggerAddAction(t, ExecuteFunc("GA_Actions"))
// ->
 call TriggerAddAction(t, function GA_Actions)
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Well, that's the correct way to do it. If it's not working it's because of something else, probably, in the GA_Actions function.

How do you know the event runs?
 
Level 8
Joined
Jul 25, 2009
Messages
194
heres the code: (I dont have much exp with jass)

JASS:
function GA_HeroAbility takes nothing returns integer
    return 'A000'
endfunction

function GA_DummyAbility takes nothing returns integer
    return 'A001'
endfunction

function GA_Dummy takes nothing returns integer
    return 'u000'
endfunction

function GA_Actions takes nothing returns nothing
    local unit a = udg_DamageEventSource
    local unit t = udg_DamageEventTarget
    local integer chance
    local integer level
    local integer i
    local integer abilityId
    local player p
    local unit dummy
    call BJDebugMsg("1")
    if GetUnitAbilityLevel(a, GA_HeroAbility()) > 0 then
        call BJDebugMsg("2")
        set level = GetUnitAbilityLevel(a, GA_HeroAbility())
        if level == 1  then
            set chance = 60
        endif
        if level == 2 then
            set chance = 10
        endif
        if level == 3 then
            set chance = 8
        endif
        if level == 4 then
            set chance = 5
        endif
        set i = GetRandomInt(1, 100)
        if i <= chance then
            set abilityId = GA_DummyAbility()
            set p = GetOwningPlayer(a)
            set dummy = CreateUnit(p, GA_Dummy(), GetUnitX(a), GetUnitY(a), 0)
            call UnitAddAbility(dummy, abilityId)
            call IssueTargetOrder(dummy, "drunkenhaze", a)
            call UnitApplyTimedLife(dummy, 'BTLF', 1)
            set dummy = null
        endif
    set a = null
    set t = null
    endif
endfunction


function GA_Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterVariableEvent(t, "udg_DamageEvent", EQUAL, 1.00)
    call TriggerAddAction(t, function GA_Actions)
    set t = null
endfunction
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
You could use "Elseif" instead of "endif - if" works the same way, but better :p

the dummy local unit is created and not nulled. It'st just nulled if chance is correct.. Which is a leak.

There's no need for all that. You could just place that in the GA_Actions
JASS:
function GA_HeroAbility takes nothing returns integer
    return 'A000'
endfunction

function GA_DummyAbility takes nothing returns integer
    return 
endfunction

function GA_Dummy takes nothing returns integer
    return 'u000'
endfunction

You don't need to local the globals. And there's no need to create locals for everything. Remember that using a local requires creating it, using it, and nullying it afterwards. If you're not going to use the local value more than 3 times, then there's no need to create it. Also, the greater the level is, the less the chance is? What does this ability do? You're not using the t variable never :) Why dont you reduce the chance gradually by 20? level 1 65, levl 2 45, lvl 3 25, lvl 4 5. So you can use "Set chance = 65 - (level*20)"


JASS:
function GA_Actions takes nothing returns nothing
    local integer chance
    local integer level = GetUnitAbilityLevel(udg_DamageEventSource, 'A000')
    local unit dummy
    call BJDebugMsg("1")
    if level > 0 then
        call BJDebugMsg("2")
        if level == 1  then
            set chance = 60
        elseif level == 2 then
            set chance = 10
        elseif level == 3 then
            set chance = 8
        elseif level == 4 then
            set chance = 5
        endif
        if GetRandomInt(1, 100) <= chance then
            set dummy = CreateUnit(GetOwningPlayer(udg_DamageEventSource), 'u000', GetUnitX(udg_DamageEventSource), GetUnitY(udg_DamageEventSource), 0)
            call UnitAddAbility(dummy, 'A001')
            call IssueTargetOrder(dummy, "drunkenhaze", udg_DamageEventSource)
            call UnitApplyTimedLife(dummy, 'BTLF', 1)
        endif
    set dummy = null
    endif
endfunction

// For this, just create the trigger, name it "GA" and place all the script inside

function InitTrig_GA takes nothing returns nothing
    local trigger GA = CreateTrigger()
    call TriggerRegisterVariableEvent(GA, "udg_DamageEvent", EQUAL, 1.00)
    call TriggerAddAction(GA, function GA_Actions)
    set GA = null
endfunction
 
JASS:
library GA initializer Init
globals
    public constant integer HERO_ABILITY  = 'A000'
    public constant integer DUMMY_ABILITY = 'A001'
    public constant integer DUMMY_ID      = 'u000'
    
    public integer array CHANCE
endglobals

public function Actions takes nothing returns nothing
    local unit a = udg_DamageEventSource
    local unit t = udg_DamageEventTarget

    local integer level
    local integer i
    local integer abilityId
    local player p
    local unit dummy
    
    call BJDebugMsg("1")
    
    set level = GetUnitAbilityLevel(a, HERO_ABILITY)
    
    if level > 0 then
        call BJDebugMsg("2")
        
        set i = GetRandomInt(1, 100)
        
        if i <= CHANCE[level] then
            set abilityId = DUMMY_ABILITY
            set p = GetOwningPlayer(a)
            set dummy = CreateUnit(p, DUMMY_ID, GetUnitX(a), GetUnitY(a), 0)
            call UnitAddAbility(dummy, abilityId)
            call IssueTargetOrder(dummy, "drunkenhaze", a)
            call UnitApplyTimedLife(dummy, 'BTLF', 1)
            set dummy = null
        endif
    endif
    
    set a = null
    set t = null
    set p = null
    set dummy = null
endfunction

private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterVariableEvent(t, "udg_DamageEvent", EQUAL, 1.00)
    call TriggerAddAction(t, function Actions)
    set t = null
    
    //Here you can setup chances,
    //so it is easier to code and faster to run
    
    set CHANCE[1] = 60
    set CHANCE[2] = 10
    set CHANCE[3] = 8
    set CHANCE[4] = 5
endfunction
endlibrary

This now requires vJass, which I think everyone should be using by now. If you have any questions about 'fixes' in the code, do ask.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Using the variables helps keeping track of everything... but is still slower than using the value directly if it's not going to be used more than twice, so you can avoid creating/nullying variables. Like "i" for example, that's just used for the random integer chance

If it's an ability to share in Spell Section, then, yeah, you need to make it clear and clean for the user to understand and configure easily, but this seems too simple for that.
 
Status
Not open for further replies.
Top