• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] It isnt telling me the problem

Status
Not open for further replies.
Level 4
Joined
Jul 22, 2010
Messages
63
So, I've tried to edit a recipe system to my settings, but when I save it I keep getting an endblock missing error, I do use JNGP, please, check the code for wrong things

JASS:
library DDItemCombineBasic initializer Init

    globals
        // *** Edit to your own will ***
		private constant string ITEM_COMBINE_EFFECT = "Abilities\\Spells\\Items\\AIlm\\AIlmTarget.mdl"
		private constant string ATTACH_POINT		= "origin"
        // *** End edit ***
	
        private sound ItemCombineSound = null
        private integer array CType[8191]
		private integer ItemN = 0
    endglobals

    function NewItemGroup takes nothing returns nothing
        local integer i = ItemN*6 + 7
        local integer h = 1
        set ItemN = ItemN + 1

        loop
        exitwhen (h == 7)
            set udg_CItemType[i] = udg_CItemType[h]
            set udg_CItemType[h] = 0
            set h = h + 1
            set i = i + 1
        endloop
        set CType[ItemN-1] = udg_CItemType[0]
        set udg_CItemType[0] = 0
    endfunction

    private function UnitRemoveItemById takes unit whichUnit, integer itemId returns nothing
        local integer i = 0
        local item it
        
        loop
        exitwhen (i >= bj_MAX_INVENTORY)
            set it = UnitItemInSlot(whichUnit, i)
            if GetItemTypeId(it) == itemId then
                call RemoveItem(it)
                exitwhen (true)
            endif
            set i = i + 1
        endloop
        set it = null
    endfunction

    private function Actions takes nothing returns nothing
        local integer n = 0
        local integer array it
        local integer i = 7
        local integer h = 0
        local integer x = 0
        local unit u = GetTriggerUnit()
        local boolean b = true
        local integer y = 0
        local integer z = 0
        local integer array hero_item_type
        local real c = 0

        // Get hero items
        loop
        exitwhen (x >= bj_MAX_INVENTORY)
            set hero_item_type[x] = GetItemTypeId(UnitItemInSlot(u, x))
            set x = x + 1
        endloop

        loop
        exitwhen (n >= ItemN)
            set h = i + 6
            
            set x = 0
            set it[x] = hero_item_type[x]
            set x = x + 1
            set it[x] = hero_item_type[x]
            set x = x + 1
            set it[x] = hero_item_type[x]
            set x = x + 1
            set it[x] = hero_item_type[x]
            set x = x + 1
            set it[x] = hero_item_type[x]
            set x = x + 1
            set it[x] = hero_item_type[x]
            set x = x + 1
            
            set y = 0 // N of items that hero has ()
            set z = 0 // N of items needed ()
            loop
            exitwhen (i >= h or udg_CItemType[i] == 0)
                set z = z + 1
                // Does unit contain item n
                set x = 0
                loop
                exitwhen (x >= bj_MAX_INVENTORY)
                    if (it[x] == udg_CItemType[i]) then
                        // Kick out the item
                        set it[x] = 0
                        set y = y + 1
                        // And increase by 1
                        exitwhen (true)
                    endif
                    set x = x + 1
                endloop
                
                set i = i + 1
            endloop
            set i = h
            
            if (y == z) then
                set h = i
                set i = i-6
                loop
                exitwhen (i > h or udg_CItemType[i] == 0)
                    call UnitRemoveItemById(u, udg_CItemType[i])
                    set i = i + 1
                endloop
            if ( not ( GetRandomReal(0, 100.00) <= 30.00 ) ) then
                 return false
                        call RemoveItem( GetManipulatedItem() )
                        call DisplayTimedTextToForce( GetPlayersAll(), 30, "A sua asa falhou" )
                 return true
                        call UnitAddItemById(u, CType[(GetRandomInt(1, 6)])
                        call SetSoundPosition(ItemCombineSound, GetUnitX(u), GetUnitY(u), 0.)
                        call StartSound(ItemCombineSound)
                        call DestroyEffect(AddSpecialEffectTarget(ITEM_COMBINE_EFFECT, u, ATTACH_POINT))
                        set u = null
            endif
            set n = n + 1
        endloop
endfunction

    //===========================================================================
private function Init takes nothing returns nothing
        set udg_RecipeTrigger = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(udg_RecipeTrigger, EVENT_PLAYER_UNIT_PICKUP_ITEM )
        call TriggerAddAction(udg_RecipeTrigger, function Actions )

        call Preload(ITEM_COMBINE_EFFECT)

        set ItemCombineSound = CreateSound( "Abilities\\Spells\\Orc\\MirrorImage\\MirrorImage.wav", false, true, true, 10, 10, "" )
        call SetSoundParamsFromLabel( ItemCombineSound, "MirrorImage" )
        call SetSoundDuration( ItemCombineSound, 1756 )
        call SetSoundPitch(ItemCombineSound, 1.2)
        call SetSoundVolume(ItemCombineSound, 100)
    endfunction

endlibrary
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
if (y == z) then
set h = i
set i = i-6
loop
exitwhen (i > h or udg_CItemType == 0)
call UnitRemoveItemById(u, udg_CItemType)
set i = i + 1
endloop
if ( not ( GetRandomReal(0, 100.00) <= 30.00 ) ) then

No where do you break out of the first conditional block before starting the second. This is valid for nesting conditional blocks but you do not break out of the first before breaking out of the containing loop.

2 possible fixes.
- add an endif before or after the second conditional block.
- change the second conditional block to an "else if" block making a single conditional statement.
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
also
JASS:
            if ( not ( GetRandomReal(0, 100.00) <= 30.00 ) ) then
                 return false
                        call RemoveItem( GetManipulatedItem() )
                        call DisplayTimedTextToForce( GetPlayersAll(), 30, "A sua asa falhou" )
                 return true
                        call UnitAddItemById(u, CType[(GetRandomInt(1, 6)])
                        call SetSoundPosition(ItemCombineSound, GetUnitX(u), GetUnitY(u), 0.)
                        call StartSound(ItemCombineSound)
                        call DestroyEffect(AddSpecialEffectTarget(ITEM_COMBINE_EFFECT, u, ATTACH_POINT))
                        set u = null
            endif
the return will stop the execution of function so nothing after that return statement executes
 
Level 4
Joined
Jul 22, 2010
Messages
63
thanks, but now im getting a problem here:
JASS:
            if ( not ( GetRandomReal(0, 100.00) <= 30.00 ) ) then
                 return false
                        call RemoveItem( GetManipulatedItem() )
                        call DisplayTimedTextToForce( GetPlayersAll(), 30, "A sua asa falhou" )
                 return true
                        call UnitAddItemById(u, CItemType[(GetRandomInt(1, 6))])
                        call SetSoundPosition(ItemCombineSound, GetUnitX(u), GetUnitY(u), 0.)
                        call StartSound(ItemCombineSound)
                        call DestroyEffect(AddSpecialEffectTarget(ITEM_COMBINE_EFFECT, u, ATTACH_POINT))
                        set u = null
            endif
it says something about the return true/false setence

Just checkd out the last comment, how do I fix the return?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
By not returning a type the function cannot return? You do know what a return does?

JASS:
function returntest takes nothing returns nothing
    // this function cannot return a type
    return
endfunction

function returnboolean takes nothing returns boolean
    // this function can return a boolean
    return true
endfunction

function test takes nothing returns nothing
    // how the functions can be invoked
    local boolean b = returnboolean()
    call returntest()
endfunction
 
Level 4
Joined
Jul 22, 2010
Messages
63
I dont know Jass at all, I was just trying to implement a chance for an item creating failing...
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
JASS:
            if ( not ( GetRandomReal(0, 100.00) <= 30.00 ) ) then
                 return false
                        call RemoveItem( GetManipulatedItem() )
                        call DisplayTimedTextToForce( GetPlayersAll(), 30, "A sua asa falhou" )
                 return true
                        call UnitAddItemById(u, CType[(GetRandomInt(1, 6)])
                        call SetSoundPosition(ItemCombineSound, GetUnitX(u), GetUnitY(u), 0.)
                        call StartSound(ItemCombineSound)
                        call DestroyEffect(AddSpecialEffectTarget(ITEM_COMBINE_EFFECT, u, ATTACH_POINT))
                        set u = null
            endif

-->

JASS:
            if ( not ( GetRandomReal(0, 100.00) <= 30.00 ) ) then
                        call RemoveItem( GetManipulatedItem() )
                        call DisplayTimedTextToForce( GetPlayersAll(), 30, "A sua asa falhou" )
             else
                        call UnitAddItemById(u, CType[(GetRandomInt(1, 6)])
                        call SetSoundPosition(ItemCombineSound, GetUnitX(u), GetUnitY(u), 0.)
                        call StartSound(ItemCombineSound)
                        call DestroyEffect(AddSpecialEffectTarget(ITEM_COMBINE_EFFECT, u, ATTACH_POINT))
                        set u = null
            endif
 
Status
Not open for further replies.
Top