Warcraft III: MapsModelsSkinsIconsSpellsToolsTutorials
WC3 JASS: Code SnippetsJASS and vJASS Spells and SystemsJass Tutorials
Chat @Discord

vJASS & Zinc Documentation
For the latest documentation about how it works vJASS and Zinc language layers for Warcraft III, please follow these links:
Jasshelper documentation - Zinc documentation - WC3 Optimizer documentation

Author Topic: the art of module interfaces  (Read 310 times)

  • Newbie - level 2
  • **
  • Posts: 23
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 20
  • User
    • View Profile
the art of module interfaces
« on: March 21, 2012, 03:44:14 AM »
This will tutorial goes over how to create an interface with a module.

When people create interfaces, they typically use function interfaces, interfaces, or if they are cool, plain old triggers. There is a way to create an interface for a struct without having to rely on dynamic code by cleverly using static ifs.

Let's say that when an event occurs in the root struct, like a unit is indexed or a player types a chat message, it calls certain methods within the derived structs. These methods are normally called via stub methods and extension, function interfaces, or plain interfaces, but they can be called by using triggers and static ifs or by a direct method call in some cases (TimerQueue for example).

Code: jass  [Select]
  1. struct ParentStruct extends array
  2.     private static trigger eventTrig = CreateTrigger()
  3.     private static trigger fireTrig = CreateTrigger()
  4.     static readonly thistype data = 0
  6.     private static method onEvent takes nothing returns boolean
  7.         local integer prevData = data
  8.         set data = 5 //event data
  9.         call TriggerEvaluate(fireTrig)
  10.         set data = prevData
  11.     endmethod
  13.     private static method onInit takes nothing returns nothing
  14.         call TriggerAddCondition(eventTrig, Condition(function thistype.onEvent))
  15.     endmethod
  17.     static method register takes boolexpr bc returns nothing
  18.         call TriggerAddCondition(fireTrig, bc)
  19.     endmethod
  20. endstruct
  22. module Mod
  23.     static if thistype.fire.exists then
  24.         private static method firerer takes nothing returns boolean
  25.             call thistype(ParentStruct.data).fire()
  26.             return false
  27.         endmethod
  29.         private static method onInit takes nothing returns nothing
  30.             call ParentStruct.register(Condition(function thistype.firerer))
  31.         endmethod
  32.     endif
  33. endmodule

And a struct
Code: jass  [Select]
  1. struct Bleh extends array
  2.     private method fire takes nothing returns nothing
  3.     endmethod
  5.     implement Mod
  6. endstruct

The trigger evaluation is not necessarily needed in all cases as sometimes the events may be run directly within the struct.
« Last Edit: December 15, 2017, 12:24:59 PM by moyack »


Blizzard Modding Information Center Wacraft III Modding Information Center WC3JASS.com - The JASS Vault Chronicles of Darkness - A Warcraft III mod Jetcraft - A Starcraft II mod Troll Smash - A Warcraft III Arena Starcraft II Modding Information Center
  Mod DB - Change the Game Power of Corruption - A Warcraft III altered melee map Chaos Realm - The world of Game modders and wc3 addicts Follow us on Facebook!!