• 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.

Help with MATHS

Status
Not open for further replies.
Level 14
Joined
Oct 18, 2013
Messages
709
Idk if it me or war3 that has forgotten how to do maths :S

  • Custom script:set udg_var(GetUnitAbilityLevel(udg_Unit,'AHhb')+240)/200*((GetHeroAgi(udg_Unit,true)))
  • Custom script: call DisplayTextToForce( GetPlayersAll(), R2S(udg_var) )
  • Custom script:set udg_var(GetUnitAbilityLevel(udg_Unit,'AHhb')+240)/200
  • Custom script: call SetHeroAgi(udg_Unit,R2I(udg_var),true)
  • Custom script: call DisplayTextToForce( GetPlayersAll(), R2S(udg_var) )
I set the variable twice just because I wanted to rule out whether it was the last bit that was screwing this or not. Idk, The first returns 100 (which is the units agility) while the second returns 1. Is it automatically rounding it to a whole number for some reason? I don't know why it would do that, var is a real variable.

What I was aiming for is it to increase units agility by 20% while holy light is level 1, and 21% while it is level 2.
 
Level 14
Joined
Oct 18, 2013
Messages
709
I'd have to learn how events in JASS work, which I will probably do soon anyways. Are you suggesting I do:
  • set udg_var=I2R((GetUnitAbilityLevel(udg_Unit,'AHhb')+240)/200*((GetHeroAgi(udg_Unit,true))))
i don't think the ) at the end would work, where am I supposed to put it?
 
Level 23
Joined
Feb 6, 2014
Messages
2,466
I'd have to learn how events in JASS work, which I will probably do soon anyways. Are you suggesting I do:
  • set udg_var=I2R((GetUnitAbilityLevel(udg_Unit,'AHhb')+240)/200*((GetHeroAgi(udg_Unit,true))))
i don't think the ) at the end would work, where am I supposed to put it?

Try something like I2R(GetHeroAgi()) and I2R(GetUnitAbilityLevel()).
 
JASS:
set udg_var = I2R(GetUnitAbilityLevel(udg_Unit, 'AHhb') + 240) / (200 * GetHeroAgi(udg_Unit, true))

Shadow Flux already pointed out the issue, but in case you're curious, here are the rules of math in most programming languages (JASS included):

integer / integer = integer
real / integer = real
integer / real = real
real / real = real

Even though udg_var is a real variable, individual arithmetic is done using the convention described above. To find the result of two integers being divided, you can simply truncate the decimal part of the solution: 100/200 = 0; 299/100 = 2; etc.

You can also use this convention to cast integer -> real without using I2R, e.g. this should work just as well:
JASS:
set udg_var = (GetUnitAbilityLevel(udg_Unit, 'AHhb') + 240.0) / (200 * GetHeroAgi(udg_Unit, true))

But there really isn't a difference. It is just a cool tidbit of knowledge to know, especially when you're trying to make your scripts cleaner. :)
 
Level 14
Joined
Oct 18, 2013
Messages
709
But there really isn't a difference. It is just a cool tidbit of knowledge to know, especially when you're trying to make your scripts cleaner. :)
Yeah, that happens to be the reason I'm doing this actually :D

Anyways, The way I have the equation must be wrong or something because with yours PurgeandFire, it returns 0.012 or something. I'm aiming for it to be like:
((40 + Abillvl) x Agility)/200
But I'm struggling to organize it correctly to get that :/ How's it supposed to be? :3
 
Level 14
Joined
Oct 18, 2013
Messages
709
Yep, that's correct. Thanks. I don't know why I struggle so much with making this kind of thing work :L
 
Level 24
Joined
Aug 1, 2013
Messages
4,658
Try a different point of view:
the increased value = base_value * percentage * 0.01

base_value = I2R(GetHeroAgi(udg_Unit, true))
percentage = (19+I2R(GetUnitAbilityLevel(udg_Unit, 'AHhb')))
0.01 = 0.01 :D

So:
set udg_var = I2R(GetHeroAgi(udg_Unit, true)) * (19+I2R(GetUnitAbilityLevel(udg_Unit, 'AHhb'))) * 0.01

First logic, then calculations.
I mean... + 240? /200? WHY DO YOU DO THIS TO ME?!

Be aware that this is the increased value.
When using 119 instead of 19, you will have the new value.
You can also set the agility to (current + udg_var)
 
Level 14
Joined
Oct 18, 2013
Messages
709
LOL I love that, "WHY DO YOU DO THIS TO ME?!"

[sidenote] JASS trips me up everytime I try doing anything, and this is why:
(whatever) * GetHeroAgi(udg_Unit, true) / 200 <--

To me, this seems like GetHeroAgi would return the integer and get divided by 200, because whatever is in parenthesis, so everything on the outside would do its thing, then the stuff in parenthesis would come out and work its way in. Idk why, but this is literally engrained in my mind that this is how it works, when it's not. It is a struggle xD

also stuff like:
SetHeroAgi(udg_u,(GetHeroAgi(udg_u,false)+1),true I just don't see the issue qq xD




[/sidenote]
Anyways, your formula is probably more logical than mine, and usable in more situations. I just used what came to mind first for what I needed.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,255
Let us look at it line by line... Well actually only the first line.
JASS:
set udg_var(GetUnitAbilityLevel(udg_Unit,'AHhb')+240)/200*((GetHeroAgi(udg_Unit,true)))
SYNTAX ERROR!

That is not valid JASS. If "var" is an integer/real variable try this correction.
JASS:
set udg_var = (GetUnitAbilityLevel(udg_Unit,'AHhb')+240)/200*GetHeroAgi(udg_Unit,true)

You forgot the assignment part of the statement.
 
Level 14
Joined
Oct 18, 2013
Messages
709
Assignment part? if by that, you mean the = sign, that was simply me bringing it over wrong, on the editor I had that. idk how I deleted that. Anyways, the equation you give doesn't work (Likely since you were just showing how mine was but fixing the syntax errors) Idk why it doesn't flow like, "(240+ LevelofAbil)/200. Oh well, friendly hivers have already made an equation that works so woot I suppose.


edit: also, how IS this supposed to be? SetHeroAgi(udg_u,(GetHeroAgi(udg_u,false)+1)
 
Last edited:
Level 24
Joined
Aug 1, 2013
Messages
4,658
That is right.
You add agility by one.
However, iirc, you have to have another boolean of the SetHeroAgi() function.
Make sure that that boolean is the same as in the GetHeroAgi().
If Set hasnt got one, then you have to find out wether you have to use true or false in the get.
 
Status
Not open for further replies.
Top