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

Gui vs calling global jass functions

Status
Not open for further replies.
Level 17
Joined
Nov 13, 2006
Messages
1,814
have any down side for useing this? or later have problem if i replace more gui place with global jass functions what i use in gui later with call?


JASS:
function AddHPMP takes boolean HP, boolean Inc, integer v, unit u returns nothing
local integer a 
local integer s
local integer i
local integer l 
local integer cv
local integer mv

if (HP == true) then
  set a = udg_Abilities2[1]
else
  set a = udg_Abilities2[2]
endif

if (Inc == true) then
  set s = 1
else
  set s = 5
endif

set cv = v

        set mv = ModuloInteger(cv, 1000)
        set l = ( ( cv - mv ) / 1000 )
        set i = 1
        loop
            exitwhen i > l
            call UnitAddAbility( u, a )
            call SetUnitAbilityLevel( u, a, 4 + s)
            call UnitRemoveAbility( u, a )
            set i = i + 1
        endloop
        set cv = mv
        set mv = ModuloInteger(cv, 100)
        set l = ( ( cv - mv ) / 100 )
        set cv = mv
        set i = 1
        loop
            exitwhen i > l
            call UnitAddAbility( u, a )
            call SetUnitAbilityLevel( u, a, 3 + s )
            call UnitRemoveAbility( u, a )
            set i = i + 1
        endloop
        set mv = ModuloInteger(cv, 10)
        set l = ( ( cv - mv ) / 10 )
        set cv = mv
        set i = 1
        loop
            exitwhen i > l
            call UnitAddAbility( u, a )
            call SetUnitAbilityLevel( u, a, 2 + s)
            call UnitRemoveAbility( u, a )
            set i = i + 1
        endloop
        set i = 1
        loop
            exitwhen i > cv
            call UnitAddAbility( u ,a )
            call SetUnitAbilityLevel( u, a, 1 + s )
            call UnitRemoveAbility( u, a )
            set i = i + 1
        endloop
set u = null
endfunction

instead this?


  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • Max_HP Less than 0
    • Then - Actions
      • Set TempNr2 = (Max_HP mod 1000)
      • Set Loop_Integer = ((Max_HP - TempNr2) / 1000)
      • For each (Integer A) from 1 to Loop_Integer, do (Actions)
        • Loop - Actions
          • Unit - Add Add HP to TempUnit
          • Unit - Set level of Add HP for TempUnit to 5
          • Unit - Remove Add HP from TempUnit
      • Set Max_HP = TempNr2
      • Set TempNr2 = (Max_HP mod 100)
      • Set Loop_Integer = ((Max_HP - TempNr2) / 100)
      • Set Max_HP = TempNr2
      • For each (Integer A) from 1 to Loop_Integer, do (Actions)
        • Loop - Actions
          • Unit - Add Add HP to TempUnit
          • Unit - Set level of Add HP for TempUnit to 4
          • Unit - Remove Add HP from TempUnit
      • Set TempNr2 = (Max_HP mod 10)
      • Set Loop_Integer = ((Max_HP - TempNr2) / 10)
      • Set Max_HP = TempNr2
      • For each (Integer A) from 1 to Loop_Integer, do (Actions)
        • Loop - Actions
          • Unit - Add Add HP to TempUnit
          • Unit - Set level of Add HP for TempUnit to 3
          • Unit - Remove Add HP from TempUnit
      • For each (Integer A) from 1 to Max_HP, do (Actions)
        • Loop - Actions
          • Unit - Add Add HP to TempUnit
          • Unit - Set level of Add HP for TempUnit to 2
          • Unit - Remove Add HP from TempUnit
    • Else - Actions
      • Set TempNr2 = (Max_HP mod 1000)
      • Set Loop_Integer = ((Max_HP - TempNr2) / 1000)
      • Set Max_HP = TempNr2
      • For each (Integer A) from 1 to Loop_Integer, do (Actions)
        • Loop - Actions
          • Unit - Add Add HP to TempUnit
          • Unit - Set level of Add HP for TempUnit to 9
          • Unit - Remove Add HP from TempUnit
      • Set TempNr2 = (Max_HP mod 100)
      • Set Loop_Integer = ((Max_HP - TempNr2) / 100)
      • Set Max_HP = TempNr2
      • For each (Integer A) from 1 to Loop_Integer, do (Actions)
        • Loop - Actions
          • Unit - Add Add HP to TempUnit
          • Unit - Set level of Add HP for TempUnit to 8
          • Unit - Remove Add HP from TempUnit
      • Set TempNr2 = (Max_HP mod 10)
      • Set Loop_Integer = ((Max_HP - TempNr2) / 10)
      • Set Max_HP = TempNr2
      • For each (Integer A) from 1 to Loop_Integer, do (Actions)
        • Loop - Actions
          • Unit - Add Add HP to TempUnit
          • Unit - Set level of Add HP for TempUnit to 7
          • Unit - Remove Add HP from TempUnit
      • For each (Integer A) from 1 to Max_HP, do (Actions)
        • Loop - Actions
          • Unit - Add Add HP to TempUnit
          • Unit - Set level of Add HP for TempUnit to 6
          • Unit - Remove Add HP from TempUnit
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
I don't see why calling a Jass function from inside a GUI trigger can cause a problem :S I guess it won't...
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
I don't see why calling a Jass function from inside a GUI trigger can cause a problem :S I guess it won't...

i mean problem if i replace alot trigger thing to global jass and will be alot global jass thing, its isnt in memory allways or something? i talk about that functions what u write into trigger editor where is ur map name example testmap.w3x
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
Incase you do not realise, GUI triggers compile in to a very inefficient JASS script when you save a map.

Converting all your GUI triggers to JASS script manually allows much better optimization than relyin on the badly made default compiler and is encouraged.
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
Incase you do not realise, GUI triggers compile in to a very inefficient JASS script when you save a map.

Converting all your GUI triggers to JASS script manually allows much better optimization than relyin on the badly made default compiler and is encouraged.

in normal truggers i understand but if no downside in global jass functions then why peoples use vjass library instead global functions?
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
Incase you do not realise, GUI triggers compile in to a very inefficient JASS script when you save a map.

Converting all your GUI triggers to JASS script manually allows much better optimization than relyin on the badly made default compiler and is encouraged.

ooooh so that's what he meant, he tries to change all the GUI triggers into Jass by converting them and then putting them in the map header.

i mean problem if i replace alot trigger thing to global jass and will be alot global jass thing, its isnt in memory allways or something? i talk about that functions what u write into trigger editor where is ur map name example testmap.w3x

Dr Super Good is correct, it's not a good idea to convert all your GUI triggers into Jass if your going to convert them into custom text and then paste the exact same code in the header. This would not make any difference since the Jass code that it compiles to is exactly the same as the original GUI. But since GUI is written in very insufficient Jass code it is advised to re-do it manually in Jass in order to optimize your triggers, if that's what you want of course. If you just want to use insufficient Jass code (or GUI), then you can go ahead but it won't make any difference in the end... And I have no idea why you would even want to do that if your unfamiliar with Jass, but it's your choice of course.
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
ooooh so that's what he meant, he tries to change all the GUI triggers into Jass by converting them and then putting them in the map header.



Dr Super Good is correct, it's not a good idea to convert all your GUI triggers into Jass if your going to convert them into custom text and then paste the exact same code in the header. This would not make any difference since the Jass code that it compiles to is exactly the same as the original GUI. But since GUI is written in very insufficient Jass code it is advised to re-do it manually in Jass in order to optimize your triggers, if that's what you want of course. If you just want to use insufficient Jass code (or GUI), then you can go ahead but it won't make any difference in the end... And I have no idea why you would even want to do that if your unfamiliar with Jass, but it's your choice of course.

example adding HPto hero with ability trick (add/level/remove,calculations) and for mana, dmg, att speed is overall enough long, in gui copying everywhere 40 row is kinda sucks since i noticed my WE lagging/slow if gui trigger is too long (example 300-500row+++ and this not hard to do), so instead 40 row i need only 1-4 row coz i call that function instead write again and again to every trigger where i need +calculation in jass is easier than in gui when u have a more complex calculation than x*y

oh and yea, header i think the best word for it (anyway a bit i optimized), just i worried about too long header
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
It all compiles into the same script file anyway. The header is above all other script you define though (position in script only).

about optimization, what better?
if i have longer code or less function call? there the 2 example (shorter with 2 row but more with 1 call)-where have a balance beetween code length and function calls?

1.
JASS:
        set cv = mv
        set mv = cv - (cv / 100) * 100
        set l = ( ( cv - mv ) / 100 )
        set cv = mv
        set i = 1
        loop
            exitwhen i > l
            call UnitAddAbility( u, a )
            call SetUnitAbilityLevel( u, a, (3 + s) )
            call UnitRemoveAbility( u, a )
            set i = i + 1
        endloop
        set mv = cv - (cv / 10) * 10
        set l = ( ( cv - mv ) / 10 )
        set cv = mv
        set i = 1
        loop
            exitwhen i > l
            call UnitAddAbility( u, a )
            call SetUnitAbilityLevel( u, a, (2 + s) )
            call UnitRemoveAbility( u, a )
            set i = i + 1
        endloop

2. jass
JASS:
        set cv = mv
        set mv = cv - (cv / 100) * 100
        set l = ( ( cv - mv ) / 100 )
        set cv = mv
        set i = 1
        loop
            exitwhen i > l
            call MyAddAbility( u, a )
            set i = i + 1
        endloop
        set mv = cv - (cv / 10) * 10
        set l = ( ( cv - mv ) / 10 )
        set cv = mv
        set i = 1
        loop
            exitwhen i > l
            call MyAddAbility( u, a )
             set i = i + 1
        endloop
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
about optimization, what better?
if i have longer code or less function call? there the 2 example (shorter with 2 row but more with 1 call)-where have a balance beetween code length and function calls?

1.
JASS:
        set cv = mv
        set mv = cv - (cv / 100) * 100
        set l = ( ( cv - mv ) / 100 )
        set cv = mv
        set i = 1
        loop
            exitwhen i > l
            call UnitAddAbility( u, a )
            call SetUnitAbilityLevel( u, a, (3 + s) )
            call UnitRemoveAbility( u, a )
            set i = i + 1
        endloop
        set mv = cv - (cv / 10) * 10
        set l = ( ( cv - mv ) / 10 )
        set cv = mv
        set i = 1
        loop
            exitwhen i > l
            call UnitAddAbility( u, a )
            call SetUnitAbilityLevel( u, a, (2 + s) )
            call UnitRemoveAbility( u, a )
            set i = i + 1
        endloop

2. jass
JASS:
        set cv = mv
        set mv = cv - (cv / 100) * 100
        set l = ( ( cv - mv ) / 100 )
        set cv = mv
        set i = 1
        loop
            exitwhen i > l
            call MyAddAbility( u, a )
            set i = i + 1
        endloop
        set mv = cv - (cv / 10) * 10
        set l = ( ( cv - mv ) / 10 )
        set cv = mv
        set i = 1
        loop
            exitwhen i > l
            call MyAddAbility( u, a )
             set i = i + 1
        endloop

if function MyAddAbility( u, a )
contains call UnitAddAbility( u, a )
call SetUnitAbilityLevel( u, a, (2 + s) )
call UnitRemoveAbility( u, a )

Then in theory the fastest one would be the first one since your calling less functions.
For readability however the second function is better. You will not see any difference in performance anyways.
I would go for option 2 IMO.
 
in normal truggers i understand but if no downside in global jass functions then why peoples use vjass library instead global functions?
You must understand how programming works. Not just jass/GUI here in wc3, but in general.

Libraries can store global or private functions. (To short story as much as I can...)
Private functions can have same name in different libraries.

Each programmer has it's own way of coding, some part of scripts can be same just like you write English using English words... But you will never write 10 pages long story same like me or any other guy even if story has same characters, same name, place where it happen etc etc.

So you must understand that vJass will allow you to code like in real program language, not simple game edited, where you use few natives and few variables.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
So you must understand that vJass will allow you to code like in real program language
Not really. It just defines a set a macros to make programming easier. The major focuse of the macros is that an object orientated approach can be used to write scripts abstracting one away from the whole allocation and deallocation problem one must normally face and to speed up scripting through use of inhertance.

The main reason to use vJASS is that it allows one greater control over the map script than the normal editor does. The global decleration tags for example allow you access to global structures normally impossible in the default editor. The library and scope fields allow you to script with shorter vairable names than if you had to manually manage names as well as allow name changes more easilly.
 
Status
Not open for further replies.
Top