| 02-26-2006, 05:52 PM | #1 |
Ok, im making some custom functions. The first 1 damages a unit. Code:
function DamageUnit takes unit who, real amount returns nothing call SetUnitLifeBJ( who, ( GetUnitStateSwap(UNIT_STATE_LIFE, who) - amount ) ) endfunction Next function: Code:
function DamageGroup takes group who, real amount returns nothing call ForGroupBJ(who, function DamageUnit(GetEnumUnit(), amount)) endfunction When i test it, i get the error "Expected ' " Which i have no idea what it means. Could anybody help please? ![]() |
| 02-26-2006, 06:14 PM | #2 |
for this: JASS:function DamageGroup takes group who, real amount returns nothing call ForGroupBJ(who, function DamageUnit(GetEnumUnit(), amount)) endfunction for this JASS:function DamageUnit takes unit who, real amount returns nothing call SetUnitLifeBJ( who, ( GetUnitStateSwap(UNIT_STATE_LIFE, who) - amount ) ) endfunction o and use the jass tag! |
| 02-26-2006, 06:15 PM | #3 |
I thought when using ForGroupBJ you need to have a function that takes nothing returns nothing, then inside that function use GetEnumUnit(). Could be wrong as I just started JASS and that's not how I loop anyways, but..pretty sure you can't have a function with arguements as one of the arguements in ForGroupBJ. Edit: Aw, you beat me =P. Guess I was right though. |
| 02-26-2006, 07:07 PM | #4 |
When i mean, DamageUnit. I mean a unit may now always damage a other unit. I mean it as in a trigger action. Not a spell or attack action. I dont completyl understand what you mean by "you cant use parmeters for code variables, just function <func name>" All i understand their is "you can use paramenters for 'what?', just 'what?' "Any other suggestions or other understanding? |
| 02-26-2006, 07:31 PM | #5 |
You can only use functions that take nothing and return nothing for a code parameter. |
| 02-26-2006, 07:39 PM | #6 |
So is their no way around this problem? All i want to do is damage a group, but not use 3 function, just 2. Nevermind il remake my code. Thanks for help people, i will give rep |
| 02-26-2006, 09:06 PM | #7 |
JASS:function DamageGroup takes group who real amount returns nothing local group g = CreateGroup() local unit u call GroupAddGroup(who, g) loop set u = FirstOfGroup(g) exitwhen u == null DamageUnit(u, amount) call GroupRemoveUnit(g,u) endloop call DestroyGroup(g) endfunction That's how I learned to loop through groups, I think it's easier anyways. |
| 02-26-2006, 09:48 PM | #8 |
Just don't forget to set g to null at end of function (no need to set u to null, as it already has to be null for the function to exit the loop) to avoid the local variable leak. |
| 02-27-2006, 04:37 PM | #9 |
Wow, great thx :D Works just how i wanted it too. Rep given Going 1 step futher, is their a way to do what TaintedReality did, but using a condition. Like, damage group, but only enemies of a unit or player? Such as JASS:IsPlayerEnemy(GetOwningPlayer(GetAttackedUnitBJ()), GetOwningPlayer(GetAttacker())) == true But so it only damages units that match that condition? |
| 02-27-2006, 05:36 PM | #10 |
BTW shouldn't you be using the damage natives instead? At least they give experience/bounty correctly... |
| 02-27-2006, 06:07 PM | #11 |
Yea i should really, but by damage unit, i mean a other unit may not always damage the unit using this function. So really its damaging a unit, with no unit damaging, so no credit, just lose HP, no damage types. I should just use the natives to set unit HP less. But i just want to learn how to do it for future refrence Although it is a pain, and confusing ![]() |
| 02-27-2006, 10:45 PM | #12 |
Well when you call the function the 'who' parameter (the group to be damaged) should already take care of that condition. But yes you could do that if you wanted to do it inside the function rather than before. I think you need to assign the handles to variables first though so that doesn't leak, rather than just putting them into the functions like that (I just learned to JASS so not completely sure what leaks and what doesn't). |
| 02-28-2006, 05:33 AM | #13 |
A leak is when you fail to destroy a temporary object, so it stays in memory even after you no longer need it. Temporary objects are most often locations and unit groups. Then there's the local leak, you need to set all handle object local variables to null before the end of function. This does not apply to function parameters, only locals. |
| 02-28-2006, 03:12 PM | #14 |
Ah yes, how stupid of me. Iv tried what you said, it looks like it will work, but dosent. Il be making another stupid mistake JASS:function AreUnitsEnemy takes nothing returns boolean return ( IsPlayerEnemy(GetOwningPlayer(udg_unitVar), GetOwningPlayer(GetFilterUnit())) == true ) endfunction JASS:function DamageGroup takes group who, real amount returns nothing local group g = CreateGroup() local unit u call GroupAddGroup(who, g) loop set u = FirstOfGroup(g) exitwhen u == null call DamageUnit(u, amount) call GroupRemoveUnit(g,u) endloop call DestroyGroup(g) set g = null endfunction JASS:function PredictCounter takes unit u, integer chance returns nothing if ( chance >= GetRandomInt(1, 100) ) then call SetUnitAnimation(u, "spin") set udg_unitVar = u call DamageGroup(GetUnitsInRangeOfLocMatching(150.00, GetUnitLoc(u), Condition(AreUnitsEnemy() == true))) call TriggerSleepAction( 1.00 ) call ResetUnitAnimation( u ) call SetUnitLifeBJ( u, ( GetUnitStateSwap(UNIT_STATE_LIFE, u) + GetEventDamage() ) ) else endif endfunction Ok, my error is when i call the function DamageGroup(), it says it has invalid argument type [boolean], but.... the function AreUnitsEnemy() , returns a boolean, and the DamageGroup() checks if it is a boolean (==true) , which to me, cause im only just starting JASS, says eek. Any suggestions? |
| 02-28-2006, 04:44 PM | #15 |
You can't retun a comparsion. You need to make an if statement like: JASS:function AreUnitsEnemy takes nothing returns boolean if ( IsPlayerEnemy(GetOwningPlayer(udg_unitVar), GetOwningPlayer(GetFilterUnit())) == true ) then return true endif return false endfunction you can only return variables or other things of the type the function returns. In this function e.g. you return a boolean. And the only values of type bolean are true or false. You can ofc also return a varible of type boolean filled with the value true or false but that would be stupid in this case. Another thing that causes the error is that DamageGroup() doesn't take any booleans as parameter but you said that AreUnitsEnemy() returns a boolean for it. So you have to either let DamageGroup() take a boolean and make it like JASS:function DamageGroup takes group who, real amount, takes boolean b returns nothing local group g = CreateGroup() local unit u if (b == true) then call GroupAddGroup(who, g) loop set u = FirstOfGroup(g) exitwhen u == null call DamageUnit(u, amount) call GroupRemoveUnit(g,u) endloop call DestroyGroup(g) set g = null endif endfunction or you can include the boolean into a trigger that checks with an if statement wheter AreUnitsEnemy() is true and calls Destroy Group or whatever you want if it is. And btw, I don't think you need to set g in DamageGroup to null because if you destroy the group g it's already null. Would make more sense if you set u to null. |
