Starting JASS

tooltiperror

Super Moderator
Reaction score
231
Oh, I thought we were talking about coding spells inside of structs, like without any outside functions.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
And by the way I noticed "static" struct. What's the different between struct and static struct?
Globals variables in struct.

And just asking out of curiosity, what does GetHandleInt do?
GetHandleId. zz. Used for attaching. Every handle has it's own id(in integer). You will know that when you go playing with timers/triggers stuffs.
 

Ayanami

칼리
Reaction score
288
And just asking out of curiosity, what does GetHandleInt do?
GetHandleId. zz. Used for attaching. Every handle has it's own id(in integer). You will know that when you go playing with timers/triggers stuffs.

Well I've used GetHandleId before, but not GetHandleInt. Are they basically the same thing?
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Well I've used GetHandleId before, but not GetHandleInt. Are they basically the same thing?
GetHandleInt is not a native, perhaps it is defined by user.
 

Lyerae

I keep popping up on this site from time to time.
Reaction score
105
[ljass]GetHandleInt[/ljass] is a BJ, I believe.
 

tooltiperror

Super Moderator
Reaction score
231
If it was, it would be highlighted in [LJASS] with a link to the page on the wiki, as well as documentation on using it, if anyone has documented it, that is.
 

Bribe

vJass errors are legion
Reaction score
67
I have no experience with gamecache as I entered the coding arena only recently, but from what I understand hashtables brought this game out of the dark ages.
 

tooltiperror

Super Moderator
Reaction score
231
Ew, Gamecache. A slower and less efficient form of hashtables. Just use hashtables.
 

Bribe

vJass errors are legion
Reaction score
67
[ljass]StringHash[/ljass] enables hashtables to do anything gamecaches could do, anyway. Plus, hashtables have layered indexing, so you have an automatic 2-D array !
 

tooltiperror

Super Moderator
Reaction score
231
Yeah, and Table has been converted to work with hashtables and it still supports past versions, so the use of Gamecache is worthless.

You know, if you're not actually using gamecache as it's supposed to be used in campaigns.
 

Bribe

vJass errors are legion
Reaction score
67
I have no idea how gamecache works in-between campaign levels, nor how much data is saved between those levels.
 

tooltiperror

Super Moderator
Reaction score
231
I don't remember the exact stuff, but it's something like this.

Trigger:
  • Gamecache - Create or something with string "somegamecache.w3v"
    • Gamecache - Save string x in "somegamecache.w3v"
    • Gamecache - Save hero y "somegamecache.w3v"
    • // Skip to some other map.
    • Gamecache - Set somehero to y from "somegamecache.w3v"
 

Ayanami

칼리
Reaction score
288
Okay, here's another question. Let's say I want to declare some functions so that I can use the functions in the future in other triggers. How do I create functions in "map initialization"?
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
JASS:
library AAA
    function Main takes nothing returns nothing
    endfunction
endlibrary

library BBB requires AAA
//You can call the Main here.
endlibrary
 

Ayanami

칼리
Reaction score
288
So wait, I don't need to add any events or anything? So I just convert a trigger to custom script and just create a function in a library?
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Warcraft won't "create" functions for you.
You have to create it by yourself, feel free to do so.
For the function, just use it like natives.
 

Ayanami

칼리
Reaction score
288
Just made a function to set damage. The 5 abilities are "Item - Damage Bonus". 'ADa1' has these values.

Level 1: 0
Level 2: 10000
...
Level 10: 90000

Every ability decreases the damage invterval by 10.

JASS:
library DamageBonus initializer InitTrig

globals
    private constant integer ABIL_ID1 = 'ADa1'
    private constant integer ABIL_ID2 = 'ADa2'
    private constant integer ABIL_ID3 = 'ADa3'
    private constant integer ABIL_ID4 = 'ADa4'
    private constant integer ABIL_ID5 = 'ADa5'
    private constant integer DUMMY_ID = 'h003'
endglobals

globals
    private integer array ABIL_ID
    private unit dummy
endglobals
    
public function SetDamage takes real damage, unit caster returns nothing
    local real r = damage
    local integer array i
    set i[0] = 0
    if GetUnitAbilityLevel(caster, ABIL_ID[0]) == 0 then
        loop
            call UnitAddAbility(caster, ABIL_ID[i[0]])
            set i[0] = i[0] + 1
            exitwhen i[0] == 5
        endloop
    endif
    set i[0] = 0
    set i[1] = 10000
    loop
        set i[2] = R2I(r) / i[1]
        call SetUnitAbilityLevel(caster, ABIL_ID[i[0]], i[2] +1)
        set r = r - I2R(i[2] * i[1])
        set i[1] = i[1] / 10
        set i[0] = i[0] + 1
        exitwhen i[0] == 5
    endloop
endfunction

//===========================================================================
private function InitTrig takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 0
    set ABIL_ID[0] = ABIL_ID1
    set ABIL_ID[1] = ABIL_ID2
    set ABIL_ID[2] = ABIL_ID3
    set ABIL_ID[3] = ABIL_ID4
    set ABIL_ID[4] = ABIL_ID5
    set dummy = CreateUnit(Player(0), DUMMY_ID, 0, 0, 0)
    loop
        call UnitAddAbility(dummy, ABIL_ID<i>)
        set i = i + 1
        exitwhen i == 5
    endloop
    call RemoveUnit(dummy)
endfunction

endlibrary
</i>


And so, I've tested it by using a simple GUI action.

Trigger:
  • Test
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to MyAbility
    • Actions
      • Set TempReal = 500.00
      • Custom script: call DamageBonus_SetDamage(udg_TempReal, GetTriggerUnit())


Seemed like it worked, my unit gets exactly 500 damage bonus.

Now, I just want to ask, is there a further way to optimize this code? I just made this for practice.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top