• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[vJASS] Some Limits in Arrays Obstructing Initiation

Status
Not open for further replies.
Level 2
Joined
Apr 7, 2008
Messages
19
Hi, I recently got back into WC3 mapping and decided to learn JASS/vJASS.

I decided create a Hero that can be played in a standard melee map (just another Tavern Hero).

Unfortunately, I am coming across a problem that appears to be from some sort of limitation on global arrays.

This is the initiation code I am using to set up space for the abilities of my Hero, the "Inferno Avenger." It is straight-forward. Note that when the limitation obstructs me, the actions sequence does not go to completion (i.e. write "4b" to the screen).
JASS:
function Trig_InitAbilities_Actions takes nothing returns nothing
    // Init Inferno Avenger
    //call BJDebugMsg("1a")
    call OathOfFire_Init()
    //call BJDebugMsg("1b")
    //call BJDebugMsg("2a")
    call FlameStride_Init()
    //call BJDebugMsg("2b")
    //call BJDebugMsg("3a")
    call ExplosiveStrike_Init()
    //call BJDebugMsg("3b")
    //call BJDebugMsg("4a")
    call Conflagration_Init()
    //call BJDebugMsg("4b")
endfunction

//===========================================================================
function InitTrig_InitAbilities takes nothing returns nothing
    set gg_trg_InitAbilities = CreateTrigger(  )
    call TriggerRegisterTimerEvent( gg_trg_InitAbilities, 0.00, false )
    call TriggerAddAction( gg_trg_InitAbilities, function Trig_InitAbilities_Actions )
endfunction

Presently, I am using the following code to put a limit on the array indices so that my initiation code goes to completion. I have included here my own speculation on the limitation in the comments.
JASS:
globals
    // Array limit.
    constant integer C_ARRAYLIMIT = 100
    // Should be 8190 but for some reason that causes inexplicable problems with the InitAbilities' called functions.
    // The real limit with only Inferno Avenger's abilities implemented is 2655. Anything greater prevents InitAbilities from completing.
    // When C_ARRAYLIMIT is set to 100, assuming all Heroes require only approximately that amount, then about 25 Heroes can be made.
    // This is reasoned to be because 100 is <4% of 2655.
    // Somehow, Inferno Avenger is using 5535 unit spaces across 14 arrays (variously int, real, unit, and timer). Each array averages 396 unit spaces.
    // Recalculating: Given 2655 remaining unit spaces, 2655/396 = n, 6 < n < 7. About 6 arrays can be used.
    // Thus, given that Inferno Avenger alone uses 14 arrays, there likely is not enough unit spaces for any more complex Heroes.
endglobals

The functions OathOfFire_Init, FlameStride_Init, ExplosiveStrike_Init, and Conflagration_Init all look roughly the same and they all have roughly the same globals blocks. The globals block and initiation function for OathOfFire_Init follows.
JASS:
    globals
        // properties
        private real rDuration = 8
        private real rInterval = 2
        private real array rDmgCaps // these are initialized in Init
        private real numfx = 5 // number of special effects surrounding target unit
        private real radiusfx = 100 // distance from target unit at which fx appear
        private real radius = 250 // area of effect
        // array
        private unit array uCasters
        private unit array uTargets
        private timer array tTimers // duration
        private timer array tIntervals // intervals within duration
        private integer array iLevels // spell level at moment of casting
        private real array rTargetHP // record of target's hp
        private integer iSize = 0
        // temp storage for messaging in between callbacks
        private unit cb_uCaster
        private real cb_rDmg // damage dealt
    endglobals

    function OathOfFire_Init takes nothing returns nothing
        local integer i  = 0
        // damage caps
        set rDmgCaps[1] = 32
        set rDmgCaps[2] = 64
        set rDmgCaps[3] = 96
        loop // array init
            exitwhen (i == C_ARRAYLIMIT)
            set uCasters[i] = null
            set uTargets[i] = null
            set tTimers[i] = null
            set tIntervals[i] = null
            set i = i + 1
        endloop
    endfunction

Setting C_ARRAYLIMITS to anything above 2655 prevents "4b" from printing to the screen while I debug. Why is this? Do I have too many global arrays? If so, how can I circumvent this problem?
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
Could you post all the script? I think it's hitting the limit op but the only way to make sure is to see the init scripts.
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
Operation limit: you can only do so and so many actions within a thread (here the one started by the timer) before it halts.

You do not necessarily have to pre-inialize whole arrays. Besides that arrays are already null-initialized by wc3, just keep track of what indexes you are currently using and init them when you allocate a new one.
 
Level 2
Joined
Apr 7, 2008
Messages
19
Thank you both for your responses. I removed the redundant null-initialization code and it worked perfectly.
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
You should also more that almost all variables only need to be initialized to 1 not 250.
Look at my tutorial thins you should know when using triggers. / GUI. Link is in my sig.
In the variable editor section on that tutorial will explain the limit with global variables.
There is also some valuable into in that tutorial you may or may not know.
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
I will just say all the initialization you wrote is pretty much useless(dont want to be harsh, just stating the truth) because array indicies are always initialized to default value, which is 0(.0) for integer/real, false for boolean and null for everything else
 
Status
Not open for further replies.
Top