Sonic's JASS questions

S

sonic_kun

Guest
OK I'm new at this even though I've done abit of java before so I'm probably gonna have alotta qusetions.......hence this thread


How exactly does the "condition" function in JASS work? I've seen an example in Daelin's tutorial where he writes something like this:

function Cond takes nothing returns boolean
return GetSpellAbilityId() == ‘A000’
endfunction




as opposed to the default WE way of doing it by using ifs and nots and what not else.......

function Trig_Untitled_Trigger_001_Copy_Conditions takes nothing returns boolean
if ( not ( IsUnitInGroup(gg_unit_H005_0125, GetUnitsOfPlayerAll(Player(1))) == true ) ) then
return false
endif
if ( not ( IsUnitInGroup(gg_unit_H005_0034, GetUnitsOfPlayerAll(Player(1))) == true ) ) then
return false
endif
if ( not ( IsUnitInGroup(gg_unit_E001_0033, GetUnitsOfPlayerAll(Player(1))) == true ) ) then
return false
endif
return true
endfunction




In the above function, I want each of those conditions to be true (it's not an "or" function) So I tried combining the 2, by doing:

function Trig_Untitled_Trigger_001_Conditions takes nothing returns boolean
return IsUnitInGroup(gg_unit_H005_0125, GetUnitsOfPlayerAll(Player(1)))== true
return IsUnitInGroup(gg_unit_H005_0034, GetUnitsOfPlayerAll(Player(1))) == true
return IsUnitInGroup(gg_unit_E001_0033, GetUnitsOfPlayerAll(Player(1))) == true
endfunction




But instead of doing what I wanted, the trigger functioned like an "or" condition........of O want to use this method of writing the conditions, how should I write the condition function so that the actions will run only if all the conditions are fulfilled?
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
return test1() == true or test2() == true or test3() == true

Or even without the "== true".

> the trigger functioned like an "or" condition

It returned the result from the first test, and ignored the rest.
 
S

sonic_kun

Guest
Let me get this straight, so it's supposed to be

function Trig_Untitled_Trigger_001_Conditions takes nothing returns boolean
return IsUnitInGroup(gg_unit_H005_0125, GetUnitsOfPlayerAll(Player(1)))== true
or
return IsUnitInGroup(gg_unit_H005_0034, GetUnitsOfPlayerAll(Player(1))) == true
or
return IsUnitInGroup(gg_unit_E001_0033, GetUnitsOfPlayerAll(Player(1))) == true
endfunction


???
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
return IsUnitInGroup(gg_unit_H005_0125, GetUnitsOfPlayerAll(Player(1))) == true or IsUnitInGroup(gg_unit_H005_0034, GetUnitsOfPlayerAll(Player(1))) == true or IsUnitInGroup(gg_unit_E001_0033, GetUnitsOfPlayerAll(Player(1))) == true

- or -

return IsUnitInGroup(gg_unit_H005_0125, GetUnitsOfPlayerAll(Player(1))) or IsUnitInGroup(gg_unit_H005_0034, GetUnitsOfPlayerAll(Player(1))) or IsUnitInGroup(gg_unit_E001_0033, GetUnitsOfPlayerAll(Player(1)))


Some function don't work correctly without the "== true" test, but I don't remember which...


> GetUnitsOfPlayerAll

This will actually leak a unit group.
Three times for every test...

Why not test for "Owner of (<unit>) equal to Player 1"?
 
D

Dino.pl

Guest
You propably want
Code:
return IsUnitInGroup(gg_unit_H005_0125, GetUnitsOfPlayerAll(Player(1))) and IsUnitInGroup(gg_unit_H005_0034, GetUnitsOfPlayerAll(Player(1))) and IsUnitInGroup(gg_unit_E001_0033, GetUnitsOfPlayerAll(Player(1)))
instead of
Code:
return IsUnitInGroup(gg_unit_H005_0125, GetUnitsOfPlayerAll(Player(1))) or IsUnitInGroup(gg_unit_H005_0034, GetUnitsOfPlayerAll(Player(1))) or IsUnitInGroup(gg_unit_E001_0033, GetUnitsOfPlayerAll(Player(1)))
 
C

Capt Griffen

Guest
You want:

return GetOwningPlayer(gg_unit_H005_0125) == Player(1) and GetOwningPlayer(gg_unit_H005_0034) == Player(1) and GetOwningPlayer(gg_unit_E001_0033) == Player(1)

Player(1) in JASS == player 2.
 
S

sonic_kun

Guest
'expected a name'

OK thanks guys now I've got another question:

Code:
function Trig_test_morph_Actions takes nothing returns nothing
local integer item1
set item1 = GetItemTypeID(UnitItemInSlot(gg_unit_U000_0077, 1))
    call ReplaceUnitBJ( gg_unit_U000_0077, 'Hamg', bj_UNIT_STATE_METHOD_RELATIVE )
    call UnitAddItemByIdSwapped( item1,GetLastReplacedUnitBJ() )
endfunction

//===========================================================================
function InitTrig_test_morph takes nothing returns nothing
    set gg_trg_test_morph = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_test_morph, Player(1), "morph", true )
    call TriggerAddAction( gg_trg_test_morph, function Trig_test_morph_Actions )
endfunction

This trigger doesn't work and I get the error for the "set item1 = GetItemTypeID(UnitItemInSlot(gg_unit_U000_0077, 1))" line which says 'expected a name'. UnitItemInSlot() returns an item, and GetItemTypeID takes an item and returns an integer, and local item1 is an integer........so why doesn't this work?
 

SFilip

Gone but not forgotten
Reaction score
634
itemtype=integer
 
S

sonic_kun

Guest
Mmm yeah....anyhow, it doesn't make sense, I tried it using itemtype too but it doesn't work either, and at any rate it would be much easier using integer variables because I cant find a function which takes in itemtype arguments.
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
As already mentioned, an 'item type' is an integer. The letters used in world editor ('I000') is just a ascii code that represents that integer number.

The problem is that you spelled GetItemTypeId wrong ^^ ( It shouldn't be a capital d)

Code:
function Trig_test_morph_Actions takes nothing returns nothing
local integer item1= GetItemTypeId(UnitItemInSlot(gg_unit_U000_0077, 1))
    call ReplaceUnitBJ( gg_unit_U000_0077, 'Hamg', bj_UNIT_STATE_METHOD_RELATIVE )
    call UnitAddItemByIdSwapped( item1,GetLastReplacedUnitBJ() )
endfunction

//======================================================================  =====
function InitTrig_test_morph takes nothing returns nothing
    set gg_trg_test_morph = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_test_morph, Player(1), "morph", true )
    call TriggerAddAction( gg_trg_test_morph, function Trig_test_morph_Actions )
endfunction

Also, you should be aware of that '1' is the second slot the unit has.
 
S

sonic_kun

Guest
Arrgghhh......I can't figure out at all what's wrong this time...I can disable/re-enable the trigger fine in the editor, and the editor allows me to test the map, but once it shows that its compiling the variables, things go wrong.......the error message I get says that the line "function cond takes nothing returns boolean" expects a name, and apart from that theres about 50 more errors, spanning this trigger AND other triggers.......really need somehelp here :(

Code:
function cond takes nothing returns boolean
  return GetSpellAbilityId() == 'A00J' or GetSpellAbilityId() == 'A00F' or GetSpellAbilityId() == 'A00H'
endfunction

function act takes nothing returns nothing
  local effect lastcast
  local unit replaced
  local integer array itemInSlot
  local integer array charges
  local item newestItem
  local unit casting = GetSpellAbilityUnit()
  local integer a = 0
  loop
    exitwhen a>5
    if( UnitItemInSlot(casting, a) == null ) then
    else
      set itemInSlot[a] = GetItemTypeId(UnitItemInSlot(casting, a))
      set charges[a] = GetItemCharges(UnitItemInSlot(casting, a))
    endif
    set a = a+1
  endloop
  if (GetSpellAbilityId() == 'A00J') then
    call AddSpecialEffectLocBJ( GetUnitLoc(casting), "Abilities\\Spells\\Orc\\FeralSpirit\\feralspiritdone.mdl" )
    call ReplaceUnitBJ( casting, 'E005', bj_UNIT_STATE_METHOD_RELATIVE )
  else 
    if (GetSpellAbilityId() == 'A00F') then
      call AddSpecialEffectLocBJ( GetUnitLoc(casting), "Abilities\\Spells\\Other\\Charm\\CharmTarget.mdl" )
      call ReplaceUnitBJ( casting, 'E006', bj_UNIT_STATE_METHOD_RELATIVE )
    else
      call AddSpecialEffectLocBJ( GetUnitLoc(casting), "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl" )
      call ReplaceUnitBJ( casting, 'E004', bj_UNIT_STATE_METHOD_RELATIVE )
    endif
  endif
  set replaced = GetLastReplacedUnitBJ()
  set lastcast = GetLastCreatedEffectBJ()
  call SelectUnitAddForPlayer( replaced, GetOwningPlayer(replaced) )
  set a = 0
  loop
    exitwhen a>5
    if(UnitItemInSlot(replaced, a) == null) then
    else
      call RemoveItem( UnitItemInSlot(replaced, a) )
    endif
    call UnitAddItemByIdSwapped( itemInSlot[a], replaced )
    set newestItem = GetLastCreatedItem()
    call SetItemCharges( newestItem, charges[a] )
    call UnitDropItemSlot( replaced, newestItem, a )
    set a = a+1
  endloop
  call TriggerSleepAction( 10.00 )
  call DestroyEffect(lastcast)
endfunction

//===========================================================================
function InitTrig_morph takes nothing returns nothing
    set gg_trg_morph = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_morph, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_morph, Condition(function cond) )
    call TriggerAddAction( gg_trg_morph, function act )
endfunction
 

emjlr3

Change can be a good thing
Reaction score
395
looks fine, JASS Craft gives no errors
 
S

sonic_kun

Guest
lol, good suggestion, phyrex1an....u were right. Damn, I thought it was ok to repeat function names.......
 
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