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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top