• 🏆 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!

[JASS] Syntax!

Status
Not open for further replies.
Level 7
Joined
Mar 22, 2010
Messages
228
JASS:
function apple_Conditions takes nothing returns boolean
    return UnitHasItemOfTypeBJ(GetManipulatingUnit(), GetItemTypeId(GetManipulatedItem())) == true
endfunction

function apple takes nothing returns nothing
    if GetManipulatedItem() != GetItemOfTypeFromUnitBJ(GetManipulatingUnit(), GetItemTypeId(GetManipulatingItem()) then
        call SetItemCharges( GetItemOfTypeFromUnitBJ(GetManipulatingUnit(), GetItemTypeId(GetManipulatedItem())), ( GetItemCharges(GetItemOfTypeFromUnitBJ(GetManipulatingUnit(), GetItemTypeId(GetManipulatedItem()))) + GetItemCharges(GetManipulatedItem()) ) )
        call UnitRemoveItemSwapped( GetManipulatedItem(), GetManipulatingUnit() )
        call RemoveItem( GetManipulatedItem() )
    else
    endif
endfunction

function InitTrig_apple takes nothing returns nothing
    set gg_trg_apple = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_apple, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddCondition( gg_trg_apple, Conditions( function apple_Conditions ) )
    call TriggerAddAction( gg_trg_apple, function apple )
endfunction

why syntax keeps on showing?
 
Level 11
Joined
Apr 29, 2007
Messages
826
JASS:
    call TriggerAddCondition( gg_trg_apple, Conditions( function apple_Conditions ) )
It should be Condition, not Conditions
JASS:
    if GetManipulatedItem() != GetItemOfTypeFromUnitBJ(GetManipulatingUnit(), GetItemTypeId(GetManipulatingItem()) then
There is no GetManipulatingItem() afaik, what are you trying to do there?
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Looks pretty straight-forward, it's a script that combines item charges when a hero already has a charged item in its inventory.

machris13 said:
why syntax keeps on showing?

What do you mean, why does syntax keep showing? If you want help with something you need to give a better description of the problem than "why doesn't it do it!!".
 
Level 6
Joined
Oct 10, 2009
Messages
1,425
YourNameHere said:
There is no GetManipulatingItem() afaik, what are you trying to do there?

What do you mean there is no GetManipulatingItem()? There is as far as i know and JNPG knows :p but I've been wrong before.
Edit: NEVERMIND!! i thought you said Manipulated, Therefore, yes you are right. there is no manipulatingitem:p
-------------------------back to the problem-------------------------------------------------------------
well i played around with your code, and fixed it, this should work just the way you want it.
JASS:
function apple_Conditions takes nothing returns boolean
    return UnitHasItemOfTypeBJ(GetManipulatingUnit(), GetItemTypeId(GetManipulatedItem())) == true
endfunction

function apple takes nothing returns nothing
    if  GetManipulatedItem() != GetItemOfTypeFromUnitBJ(GetManipulatingUnit(), GetItemTypeId(GetManipulatedItem())) then
        call SetItemCharges( GetItemOfTypeFromUnitBJ(GetManipulatingUnit(), GetItemTypeId(GetManipulatedItem())), ( GetItemCharges(GetItemOfTypeFromUnitBJ(GetManipulatingUnit(), GetItemTypeId(GetManipulatedItem()))) + GetItemCharges(GetManipulatedItem()) ) )
        call UnitRemoveItemSwapped( GetManipulatedItem(), GetManipulatingUnit() )
        call RemoveItem( GetManipulatedItem() )
        endif
        endfunction

function InitTrig_apple takes nothing returns nothing
    set gg_trg_apple = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_apple, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddCondition( gg_trg_apple, Condition( function apple_Conditions ) )
    call TriggerAddAction( gg_trg_apple, function apple )
endfunction

problem 1= didnt need an else
problem 2=
It should be Condition, not Conditions
problem 3= well, I'm not sure but i fixed it, it was in line 6, and i think you were just missing an ")"
problem 4=
There is no GetManipulatingItem() afaik, what are you trying to do there?
(i changed it to manipulated item by assuming, but if it was supposed to be manipulating unit then just change that. nothing hard.)
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
JASS:
function apple takes unit u,item m,item n returns nothing
    local integer id = GetItemTypeId(m)
    local integer i = 0
    loop
 
        set n = UnitItemInSlot(u,i)
        if GetItemTypeId(n) == id and n != m then
            call SetItemCharges(n,GetItemCharges(n) + GetItemCharges(m))
            call RemoveItem(m)
 
            exitwhen true
        endif
        exitwhen i == 5
        set i = i + 1
    endloop
endfunction
 
function apple_Conditions takes nothing returns boolean
    call apple(GetTriggerUnit(),GetManipulatedItem(),null)
    return false
endfunction
 
function InitTrig_apple takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_PICKUP_ITEM)
    call TriggerAddCondition(t,Condition(function apple_Conditions))
endfunction
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Yes, I see that.

Exactly how much faster is using handle parameters as opposed to declaring/nulling them?

God I hate having to spread rep before giving it to the same person. I rarely give rep to anybody (I don't ask a lot of questions) but when I do I can't because it says I must spread the love.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Is it faster to call the actions from the conditions rather than just registering the trigger with actions instead of conditions?

JASS:
function apple takes nothing returns nothing
    local unit u=GetTriggerUnit()
    local item m=GetManipulatedItem()
    local item n=null

    local integer id = GetItemTypeId(m)
    local integer i = 0
    loop
 
        set n = UnitItemInSlot(u,i)
        if GetItemTypeId(n) == id and n != m then
            call SetItemCharges(n,GetItemCharges(n) + GetItemCharges(m))
            call RemoveItem(m)
 
            exitwhen true
        endif
        exitwhen i == 5
        set i = i + 1
    endloop

    set u=null
    set m=null
    set n=null
endfunction
 
function InitTrig_apple takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_PICKUP_ITEM)
    call TriggerAddAction(t,function apple)
endfunction

Like this?
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
Conditions execute faster, according to everyone I've spoken with about it and to the benchmarks I've tested. Actions create a new thread, and that apparently takes a slightly longer time than staying in the same thread. Like you can't do TriggerSleepAction inside of a Condition.

Benchmarks put parameters at a 24% faster speed than local declaration/nulling, but then again that's Jesus4Lyf's benchmark and really no one is willing to test that with another benchmark (I will not uninstall/reinstall just to use an earlier patch to test the JASS1 systems, which I've also heard are unreliable and could very well be different speeds in 1.24b anyway).
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
That is, unless your local unit is named Supercalifragilisticexpialidocious :p

That would be a good argument against using imported libraries as well.

But the best way to demolish the size of your map is to clear the terrain, doodads and all imported models, and delete all the triggers and object editor data. When I cleared my WarChasers of many useless features, I did lose a lot of KB, but I lost a lot of quality in the process. A difference of 5 words, even repeated thousands of times (however unlikely), will at most gain you a few dozens KB.

One deleted import would amount to much more.
 
Yeah. Deleting imports is the best way. (I was just mentioning that it has a slight effect on it) But it is still comparing a minuscule speed difference (non-percentage-wise) to a minuscule file size difference. =)

Sadly, I don't know how effective parameter functions are when JASSHelper has auto-inlining (not sure if it applies to custom funcs, if not, then disregard this) and since the optimizer might inline most of the stuff. =\ (Or at least that is what I think it does, not sure though, it might just inline BJ's)

>Supercalifragilisticexpialidocious

(No spelling suggestions) :D
 
Inlining two functions into one function? The only thing JassHelper ever does that I know of is split things into a ton of functions (yeah, like the good ol' function.evaluate() that creates an entire trigger just to run it).

Yeah, the inlining is a little limited. To have a function inlined it must follow these rules:
  • The function is a one-liner
  • If the function is called by call the function's contents must begin with set or call or be a return of a single function.
  • If the inlined function is an assigment (set) it should not assign one of its arguments.
  • Every argument must be evaluated once and only once by the function, in the same order as they appear in the arguments list.
  • If the function contains function calls, they should all be evaluated after the arguments UNLESS the function is marked as non-state changing, at the moment some very few native functions and also return bug exploiters are considered as non-state changing.

Or at least for JASSHelper.
 
Status
Not open for further replies.
Top