• 🏆 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!

[JASS] Is this code wise?

Status
Not open for further replies.
Level 3
Joined
Feb 20, 2007
Messages
32
Hello there, just me and my optimization attempts at work. Previously I've been using a loop to determine if something is part of an array, however it recently occured to me that the tag '####' is really an integer id.

That in mind;
JASS:
struct CASTING_EVENT
    integer sid
    trigger use
    boolean override = false
endstruct

globals
    CASTING_EVENT array CASTING_EVENTS
    unit CASTING_EVENT_CASTER
endglobals

constant function MINIMUM_SPELL_HANDLE_ID takes nothing returns integer
    return 'A000'
endfunction

function ENGINE_REGISTER_CASTING_EVENT takes CASTING_EVENT cs returns nothing
   set CASTING_EVENTS[cs.sid - MINIMUM_SPELL_HANDLE_ID] = cs
endfunction

function IsSpellRegistered takes integer sid returns trigger
    local integer I = sid -  MINIMUM_SPELL_HANDLE_ID
    if(CASTING_EVENTS[I] != 0)then
        return CASTING_EVENTS[I].use
    endif
    return null
endfunction

However, I'm not entirely sure if this is an advisible idea. I'm aware the maximum array value is 8190, which I would hope would not be surpassed. This seems almost to good to be true, could anyone confirm/deny if this is a valid way to handle this code?

(If so, does anyone happen to know the minimum possible handle for a trackable?)
 
Status
Not open for further replies.
Top