JASS problem, editor crashing

U

Unregistered

Guest
Hi, I've got a really bad problem and i thought this is the right playe to look for help...

I'm working on an AoS-type map with a concept like battle ships or tank wars... now i want to give players the ability to combine or upgrade certain weapons. I've written all the items into arrays like this:

Combination:

feature_CombineItem1[x] + feature_CombineItem2[x] + feature_CombineItem3[x] are needed in the inventory
to get=> feature_CombineItem4[x]

where not always 3 items are needed, if there are only 2 items to combine, CombineItem2 and 3 are the same.

Upgrades:

feature_UpgradeItem1[x] in the inventory + feature_UpgradeCost[x] of gold is needed to get=> feature_UpgradeItem2[x]

the upgrades and combinations should be launched by using an ability ("Combine/Upgrade Items") on an item in the inventory... then a trigger is launched that checks which upgrades or combinations are possible, those possibilities are listed on a dialog and saved in an array, the dialog is shown to the player and the selected option is done...

i haven't worked out the trigger fully because i couldn't test it yet... my problem is that everytime i want to test the map, the editor crashes down and i have no idea why... the error must be in this trigger because the editor works when i disable the trigger... can you please help me?

this is the trigger:
JASS:
function Trig_CombineUpgrade_3_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A036' ) ) then
        return false
    endif
    return true
endfunction

function IsItemUpgradeable takes nothing returns boolean
    if ( ( GetItemTypeId(GetSpellTargetItem()) == udg_feature_UpgradeItem1[GetForLoopIndexA()] ) ) then
        return true
    endif
    return false
endfunction

function IsItemCombinable takes nothing returns boolean
    if ( ( GetItemTypeId(GetSpellTargetItem()) == udg_feature_CombineItem1[GetForLoopIndexA()] ) ) then
        return true
    endif
    if ( ( GetItemTypeId(GetSpellTargetItem()) == udg_feature_CombineItem2[GetForLoopIndexA()] ) ) then
        return true
    endif
    if ( ( GetItemTypeId(GetSpellTargetItem()) == udg_feature_CombineItem3[GetForLoopIndexA()] ) ) then
        return true
    endif
    return false
endfunction

function IsUpgradePossible takes nothing returns boolean
    if ( IsItemUpgradeable() ) then
        if ( GetPlayerState(GetOwningPlayer(GetSpellAbilityUnit()), PLAYER_STATE_RESOURCE_GOLD) >= udg_feature_UpgradeCost[GetForLoopIndexA()] ) then
            return true
        endif
    endif
    return false
endfunction

function IsCombinePossible takes nothing returns boolean
    if ( IsItemCombinable() ) then
        if ( not ( UnitHasItemOfTypeBJ(GetSpellAbilityUnit(), udg_feature_CombineItem1[GetForLoopIndexA()] ) ) ) then
            return false
        else
            if ( not ( UnitHasItemOfTypeBJ(GetSpellAbilityUnit(), udg_feature_CombineItem2[GetForLoopIndexA()] ) ) ) then
                return false
            else
                if ( not ( UnitHasItemOfTypeBJ(GetSpellAbilityUnit(), udg_feature_CombineItem3[GetForLoopIndexA()] ) ) ) then
                    return false
                else
                    return true
            endif
        endif
    endif
endfunction

function GetFirstFreePossIndex takes nothing returns integer
    local integer i = 1
    loop
        exitwhen i == 20
        if ( poss<i> == 0 ) then
            return i
        endif
        set i = i + 1
    endloop
    return 0
endfunction
    
function Trig_CombineUpgrade_3_Actions takes nothing returns nothing
    local integer array poss
    local string array posstype
    local dialog possdialog
    local button array possbutton
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 20
    loop
        exitwhen bj_forLoopAIndex &gt; bj_forLoopAIndexEnd
        if ( IsUpgradePossible() ) then
            call DialogAddButtonBJ( possdialog, ( GetItemName(CreateItemLoc(udg_feature_UpgradeItem2[GetForLoopIndexA()], udg_temp_Point[0])) + ( &quot;: &quot; + ( I2S(udg_feature_UpgradeCost[GetForLoopIndexA()]) + &quot; Gold&quot; ) ) ) )
            set possbutton[GetFirstFreePossIndex()] = GetLastCreatedButtonBJ()
            set posstype[GetFirstFreePossIndex()] = &quot;upgrade&quot;
            set poss[GetFirstFreePossIndex()] = GetForLoopIndexA()
        endif
        if ( IsCombinePossible() ) then
            call DialogAddButtonBJ( possdialog, ( GetItemName(CreateItemLoc(udg_feature_CombineItem4[GetForLoopIndexA()], udg_temp_Point[0])) + ( &quot;: &quot; + ( GetItemName(CreateItemLoc(udg_feature_CombineItem1[GetForLoopIndexA()], udg_temp_Point[0])) + ( &quot; + &quot; + GetItemName(CreateItemLoc(udg_feature_CombineItem2[GetForLoopIndexA()], udg_temp_Point[0])) ) ) ) ) )
            set possbutton[GetFirstFreePossIndex()] = GetLastCreatedButtonBJ()
            set posstype[GetFirstFreePossIndex()] = &quot;combine&quot;
            set poss[GetFirstFreePossIndex()] = GetForLoopIndexA()
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
//------------------------------------------------------------------------------------
    call DialogSetMessageBJ( possdialog, &quot;Possible Items:&quot; )
    call DialogAddButtonBJ( possdialog, &quot;Cancel&quot; )
    call DialogDisplayBJ( true, possdialog, GetOwningPlayer(GetSpellAbilityUnit()) )
    call WaitForDialogEvent( possdialog, 0.10 )
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 20
    loop
        exitwhen bj_forLoopAIndex &gt; bj_forLoopAIndexEnd
        if ( GetClickedButtonBJ() == possbutton[GetForLoopIndexA()] ) then
            if ( posstype[GetForLoopIndexA()] == &quot;upgrade&quot; ) then
                call AdjustPlayerStateBJ( ( -1 * udg_feature_UpgradeCost[poss[GetForLoopIndexA()]] ), GetOwningPlayer(GetSpellAbilityUnit()), PLAYER_STATE_RESOURCE_GOLD )
                call RemoveItem( GetItemOfTypeFromUnitBJ(udg_player_SpielerEinheit[GetConvertedPlayerId(GetOwningPlayer(GetSpellAbilityUnit()))], udg_feature_UpgradeItem1[poss[GetForLoopIndexA()]]) )
                call UnitAddItemByIdSwapped( udg_feature_UpgradeItem2[poss[GetForLoopIndexA()]], udg_player_SpielerEinheit[GetConvertedPlayerId(GetOwningPlayer(GetSpellAbilityUnit()))] )
            else
            endif
        else
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    call EnumItemsInRectBJ( gg_rct_Item, call RemoveItem( GetEnumItem() ) )
endfunction

//===========================================================================
function InitTrig_CombineUpgrade_3 takes nothing returns nothing
    set gg_trg_CombineUpgrade_3 = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_CombineUpgrade_3, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_CombineUpgrade_3, Condition( function Trig_CombineUpgrade_3_Conditions ) )
    call TriggerAddAction( gg_trg_CombineUpgrade_3, function Trig_CombineUpgrade_3_Actions )
endfunction</i>
 
U

Unregistered

Guest
oh, it seems its petter to use the code marks than jass^^:
Code:
function Trig_CombineUpgrade_3_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A036' ) ) then
        return false
    endif
    return true
endfunction

function IsItemUpgradeable takes nothing returns boolean
    if ( ( GetItemTypeId(GetSpellTargetItem()) == udg_feature_UpgradeItem1[GetForLoopIndexA()] ) ) then
        return true
    endif
    return false
endfunction

function IsItemCombinable takes nothing returns boolean
    if ( ( GetItemTypeId(GetSpellTargetItem()) == udg_feature_CombineItem1[GetForLoopIndexA()] ) ) then
        return true
    endif
    if ( ( GetItemTypeId(GetSpellTargetItem()) == udg_feature_CombineItem2[GetForLoopIndexA()] ) ) then
        return true
    endif
    if ( ( GetItemTypeId(GetSpellTargetItem()) == udg_feature_CombineItem3[GetForLoopIndexA()] ) ) then
        return true
    endif
    return false
endfunction

function IsUpgradePossible takes nothing returns boolean
    if ( IsItemUpgradeable() ) then
        if ( GetPlayerState(GetOwningPlayer(GetSpellAbilityUnit()), PLAYER_STATE_RESOURCE_GOLD) >= udg_feature_UpgradeCost[GetForLoopIndexA()] ) then
            return true
        endif
    endif
    return false
endfunction

function IsCombinePossible takes nothing returns boolean
    if ( IsItemCombinable() ) then
        if ( not ( UnitHasItemOfTypeBJ(GetSpellAbilityUnit(), udg_feature_CombineItem1[GetForLoopIndexA()] ) ) ) then
            return false
        else
            if ( not ( UnitHasItemOfTypeBJ(GetSpellAbilityUnit(), udg_feature_CombineItem2[GetForLoopIndexA()] ) ) ) then
                return false
            else
                if ( not ( UnitHasItemOfTypeBJ(GetSpellAbilityUnit(), udg_feature_CombineItem3[GetForLoopIndexA()] ) ) ) then
                    return false
                else
                    return true
            endif
        endif
    endif
endfunction

function GetFirstFreePossIndex takes nothing returns integer
    local integer i = 1
    loop
        exitwhen i == 20
        if ( poss[i] == 0 ) then
            return i
        endif
        set i = i + 1
    endloop
    return 0
endfunction
    
function Trig_CombineUpgrade_3_Actions takes nothing returns nothing
    local integer array poss
    local string array posstype
    local dialog possdialog
    local button array possbutton
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 20
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        if ( IsUpgradePossible() ) then
            call DialogAddButtonBJ( possdialog, ( GetItemName(CreateItemLoc(udg_feature_UpgradeItem2[GetForLoopIndexA()], udg_temp_Point[0])) + ( ": " + ( I2S(udg_feature_UpgradeCost[GetForLoopIndexA()]) + " Gold" ) ) ) )
            set possbutton[GetFirstFreePossIndex()] = GetLastCreatedButtonBJ()
            set posstype[GetFirstFreePossIndex()] = "upgrade"
            set poss[GetFirstFreePossIndex()] = GetForLoopIndexA()
        endif
        if ( IsCombinePossible() ) then
            call DialogAddButtonBJ( possdialog, ( GetItemName(CreateItemLoc(udg_feature_CombineItem4[GetForLoopIndexA()], udg_temp_Point[0])) + ( ": " + ( GetItemName(CreateItemLoc(udg_feature_CombineItem1[GetForLoopIndexA()], udg_temp_Point[0])) + ( " + " + GetItemName(CreateItemLoc(udg_feature_CombineItem2[GetForLoopIndexA()], udg_temp_Point[0])) ) ) ) ) )
            set possbutton[GetFirstFreePossIndex()] = GetLastCreatedButtonBJ()
            set posstype[GetFirstFreePossIndex()] = "combine"
            set poss[GetFirstFreePossIndex()] = GetForLoopIndexA()
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
//------------------------------------------------------------------------------------
    call DialogSetMessageBJ( possdialog, "Possible Items:" )
    call DialogAddButtonBJ( possdialog, "Cancel" )
    call DialogDisplayBJ( true, possdialog, GetOwningPlayer(GetSpellAbilityUnit()) )
    call WaitForDialogEvent( possdialog, 0.10 )
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 20
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        if ( GetClickedButtonBJ() == possbutton[GetForLoopIndexA()] ) then
            if ( posstype[GetForLoopIndexA()] == "upgrade" ) then
                call AdjustPlayerStateBJ( ( -1 * udg_feature_UpgradeCost[poss[GetForLoopIndexA()]] ), GetOwningPlayer(GetSpellAbilityUnit()), PLAYER_STATE_RESOURCE_GOLD )
                call RemoveItem( GetItemOfTypeFromUnitBJ(udg_player_SpielerEinheit[GetConvertedPlayerId(GetOwningPlayer(GetSpellAbilityUnit()))], udg_feature_UpgradeItem1[poss[GetForLoopIndexA()]]) )
                call UnitAddItemByIdSwapped( udg_feature_UpgradeItem2[poss[GetForLoopIndexA()]], udg_player_SpielerEinheit[GetConvertedPlayerId(GetOwningPlayer(GetSpellAbilityUnit()))] )
            else
            endif
        else
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    call EnumItemsInRectBJ( gg_rct_Item, call RemoveItem( GetEnumItem() ) )
endfunction

//===========================================================================
function InitTrig_CombineUpgrade_3 takes nothing returns nothing
    set gg_trg_CombineUpgrade_3 = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_CombineUpgrade_3, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_CombineUpgrade_3, Condition( function Trig_CombineUpgrade_3_Conditions ) )
    call TriggerAddAction( gg_trg_CombineUpgrade_3, function Trig_CombineUpgrade_3_Actions )
endfunction
 

Monovertex

Formerly Smith_S9
Reaction score
1,461
Forgot an endif:

Code:
function IsCombinePossible takes nothing returns boolean
    if ( IsItemCombinable() ) then
        if ( not ( UnitHasItemOfTypeBJ(GetSpellAbilityUnit(), udg_feature_CombineItem1[GetForLoopIndexA()] ) ) ) then
            return false
        else
            if ( not ( UnitHasItemOfTypeBJ(GetSpellAbilityUnit(), udg_feature_CombineItem2[GetForLoopIndexA()] ) ) ) then
                return false
            else
                if ( not ( UnitHasItemOfTypeBJ(GetSpellAbilityUnit(), udg_feature_CombineItem3[GetForLoopIndexA()] ) ) ) then
                    return false
                else
                    return true
                [B]endif[/B]
            endif
        endif
    endif
endfunction

Because of that endif, the WE doesn't see the endfunction.
 
U

Unregistered

Guest
oh..^^ thanks for the fast reply =)
but now the next problem i cant solve..:

"Name expected"

in this line:

Code:
        if ( GetPlayerState(GetOwningPlayer(GetSpellAbilityUnit()), PLAYER_STATE_RESOURCE_GOLD) >= udg_feature_UpgradeCost[GetForLoopIndexA()] ) then
 

Monovertex

Formerly Smith_S9
Reaction score
1,461
Usually, you have to look a few lines before the line that WE sais it has the error. But I can't see which is the problem... Btw, try stop using those BJ shits and start using natives. Good program here. :]
 
U

Unregistered

Guest
ok now i've made it work by triggering it in the ui and then replacing the udg's with locals... the next problem is that i don't know how to get the clicked dialog button without starting a new trigger... i need the locals but i dont know if i can handle a new event in the same trigger... help plz^^

my trigger:

PHP:
function Trig_CombineUpgrade_5_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A036' ) ) then
        return false
    endif
    return true
endfunction

function Trig_CombineUpgrade_5_ItemRemoval takes nothing returns nothing
    call RemoveItem ( GetEnumItem() )
endfunction

function Trig_CombineUpgrade_5_Actions takes nothing returns nothing
    local integer i = 1
    local integer index = 1
    local integer array poss
    local button array possbutton
    local string array posstype
    local dialog possdialog
    
    set udg_temp_Point[0] = GetRectCenter(gg_rct_Item)
    loop
        exitwhen i > 20
        if ( GetItemTypeId(GetSpellTargetItem()) == udg_feature_UpgradeItem1[i] ) then
            if ( UnitHasItemOfTypeBJ(GetSpellAbilityUnit(), udg_feature_UpgradeItem1[i]) == true ) then
                if (GetPlayerState(GetOwningPlayer(GetSpellAbilityUnit()), PLAYER_STATE_RESOURCE_GOLD) >= udg_feature_UpgradeCost[i] ) then 
                    call DialogAddButtonBJ( possdialog, ( GetItemName(CreateItemLoc(udg_feature_UpgradeItem2[i], udg_temp_Point[0])) + ( "" + ( I2S(udg_feature_UpgradeCost[i]) + " Gold" ) ) ) )
                    set possbutton[index] = GetLastCreatedButtonBJ()
                    set posstype[index] = "upgrade"
                    set poss[index] = i
                    set index = ( index + 1 )
                endif
            endif
        endif
        if ( GetItemTypeId(GetSpellTargetItem()) == udg_feature_CombineItem1[i] ) then
            if ( UnitHasItemOfTypeBJ(GetSpellAbilityUnit(), udg_feature_CombineItem1[i]) == true ) then
                if ( UnitHasItemOfTypeBJ(GetSpellAbilityUnit(), udg_feature_CombineItem2[i]) == true ) then
                    if ( UnitHasItemOfTypeBJ(GetSpellAbilityUnit(), udg_feature_CombineItem3[i]) == true ) then 
                        call DialogAddButtonBJ( possdialog, ( GetItemName(CreateItemLoc(udg_feature_CombineItem4[i], udg_temp_Point[0])) + ": " ) )
                        set possbutton[index] = GetLastCreatedButtonBJ()
                        set posstype[index] = "combine"
                        set poss[index] = i
                        set index = ( index + 1 )
                    endif
                endif
            endif
        endif
        if ( GetItemTypeId(GetSpellTargetItem()) == udg_feature_CombineItem2[i] ) then
            if ( UnitHasItemOfTypeBJ(GetSpellAbilityUnit(), udg_feature_CombineItem1[i]) == true ) then
                if ( UnitHasItemOfTypeBJ(GetSpellAbilityUnit(), udg_feature_CombineItem2[i]) == true ) then
                    if ( UnitHasItemOfTypeBJ(GetSpellAbilityUnit(), udg_feature_CombineItem3[i]) == true ) then 
                        call DialogAddButtonBJ( possdialog, ( GetItemName(CreateItemLoc(udg_feature_CombineItem4[i], udg_temp_Point[0])) + ": " ) )
                        set possbutton[index] = GetLastCreatedButtonBJ()
                        set posstype[index] = "combine"
                        set poss[index] = i
                        set index = ( index + 1 )
                    endif
                endif
            endif
        endif 
        if ( GetItemTypeId(GetSpellTargetItem()) == udg_feature_CombineItem3[i] ) then
            if ( UnitHasItemOfTypeBJ(GetSpellAbilityUnit(), udg_feature_CombineItem1[i]) == true ) then
                if ( UnitHasItemOfTypeBJ(GetSpellAbilityUnit(), udg_feature_CombineItem2[i]) == true ) then
                    if ( UnitHasItemOfTypeBJ(GetSpellAbilityUnit(), udg_feature_CombineItem3[i]) == true ) then 
                        call DialogAddButtonBJ( possdialog, ( GetItemName(CreateItemLoc(udg_feature_CombineItem4[i], udg_temp_Point[0])) + ": " ) )
                        set possbutton[index] = GetLastCreatedButtonBJ()
                        set posstype[index] = "combine"
                        set poss[index] = i
                        set index = ( index + 1 )
                    endif
                endif
            endif
        endif
        set i = i + 1
    endloop
    call DialogSetMessageBJ( possdialog, "Possible Items:" )
    call DialogAddButtonBJ( possdialog, "Cancel" )
    call DialogDisplayBJ( true, possdialog, GetOwningPlayer(GetSpellAbilityUnit()) )
    call RemoveLocation( udg_temp_Point[0] )
    call EnumItemsInRectBJ( gg_rct_Item, function Trig_CombineUpgrade_5_ItemRemoval )
//
//                          ==NEW EVENT NEEDED==
//
    set i = 1
    loop
        exitwhen i > 20
        if ( GetClickedButtonBJ() == possbutton[i] ) then
            if ( posstype[i] == "upgrade" ) then
                call RemoveItem( GetItemOfTypeFromUnitBJ(udg_player_SpielerEinheit[GetConvertedPlayerId(GetTriggerPlayer())], udg_feature_UpgradeItem1[poss[i]]) )
                call AdjustPlayerStateBJ( ( -1 * udg_feature_UpgradeCost[poss[i]] ), GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD )
                call UnitAddItemByIdSwapped( udg_feature_UpgradeItem2[poss[i]], udg_player_SpielerEinheit[GetConvertedPlayerId(GetTriggerPlayer())] )
            else
                if ( posstype[i] == "combine" ) then
                    call RemoveItem( GetItemOfTypeFromUnitBJ(GetSpellAbilityUnit(), udg_feature_CombineItem1[poss[i]]) )
                    call RemoveItem( GetItemOfTypeFromUnitBJ(GetSpellAbilityUnit(), udg_feature_CombineItem2[poss[i]]) )
                    if ( udg_feature_CombineItem2[poss[i]] != udg_feature_CombineItem3[poss[i]] ) then
                        call RemoveItem( GetItemOfTypeFromUnitBJ(GetSpellAbilityUnit(), udg_feature_CombineItem3[poss[i]]) )
                    endif
                    call UnitAddItemByIdSwapped( udg_feature_CombineItem4[poss[i]], GetSpellAbilityUnit() )
                else
                endif
            endif
        else
        endif
        set i = i + 1
    endloop
endfunction

//===========================================================================
function InitTrig_CombineUpgrade_5 takes nothing returns nothing
    set gg_trg_CombineUpgrade_5 = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_CombineUpgrade_5, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_CombineUpgrade_5, Condition( function Trig_CombineUpgrade_5_Conditions ) )
    call TriggerAddAction( gg_trg_CombineUpgrade_5, function Trig_CombineUpgrade_5_Actions )
endfunction
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top