• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[vJASS] A custom filter function for each struct instance

Status
Not open for further replies.
Level 1
Joined
Apr 8, 2020
Messages
110
How would I go about doing something like the following?
JASS:
struct Example
      Requirement requirement
      method whatever takes nothing returns nothing
            //Calling the custom filter function
            if requirement.filter() then
            endif
      endmethod

       method addCondition takes Requirement requirement returns thistype
            set this.requirement = requirement
       endmethod
endstruct
 
Any variation of the following:

JASS:
globals
    trigger EvalTrig = CreateTrigger()
endglobals

function Eval takes boolexpr func returns boolean
    call TriggerClearConditions(EvalTrig)
    call TriggerAddCondition(EvalTrig, func)
    return TriggerEvaluate(EvalTrig)
endfunction

struct Example
    boolexpr requirement

    method whatever takes nothing returns nothing
        //Calling the custom filter function
        if Eval(requirement) then
        endif
    endmethod

    method addCondition takes boolexpr requirement returns thistype
        set this.requirement = requirement
    endmethod
endstruct
You can also use function interfaces but I remember them being inefficient and generating a lot of code.

JassHelper 0.A.0.0
 
Level 1
Joined
Apr 8, 2020
Messages
110
Hmmm.... Your solution is clear cut enough. However, I wonder if there is a way for me to assign a struct member to another struct created by a user and then use the methods of that second struct within my own struct.

The second struct can be unique with its own methods for each instance of my struct.

For instance, the user can code different variations of the struct Requirement ---> overriding methods of the parent struct.

How can I assign a struct member to any one of these child structs? Is this even possible?
 
Last edited:
Status
Not open for further replies.
Top