1. Join other hivers in a friendly concept-art contest. The contestants have to create a genie coming out of its container. We wish you the best of luck!
    Dismiss Notice
  2. The Melee Mapping Contest #4: 2v2 - Results are out! Step by to congratulate the winners!
    Dismiss Notice
  3. We're hosting the 15th Mini-Mapping Contest with YouTuber Abelhawk! The contestants are to create a custom map that uses the hidden content within Warcraft 3 or is inspired by any of the many secrets within the game.
    Dismiss Notice
  4. The 20th iteration of the Terraining Contest is upon us! Join and create exquisite Water Structures for it.
    Dismiss Notice
  5. Check out the Staff job openings thread.
    Dismiss Notice

[Wurst] Passing this into Closure, or alternative?

Discussion in 'Triggers & Scripts' started by Taztingo, Feb 20, 2019.

  1. Taztingo

    Taztingo

    Joined:
    Aug 6, 2010
    Messages:
    7
    Resources:
    0
    Resources:
    0
    I have a class that contains a dialog. is there any way I can add a callback to it, and call a method within the class using a Trigger?


    Code (Text):
    trigger t = CreateTrigger()
                        ..registerDialogEvent(this.mode)
                        ..addAction(-> onScoreClicked(0))
    I cannot capture "this".

    Are there any examples of how to do this, or do I have to extract my trigger outside of my class? There wasn't too much documentation on triggers.
     
  2. Frotty

    Frotty

    Wurst Reviewer

    Joined:
    Jan 1, 2009
    Messages:
    1,392
    Resources:
    10
    Models:
    3
    Tools:
    1
    Maps:
    4
    Tutorials:
    1
    Wurst:
    1
    Resources:
    10
    Use package DialogBox, it's made for that.

    The reason you can't capture "this" is because there is no closure. You can use code types in lambda expressions which makes it look the same, but not function the same.
     
    Last edited: Feb 20, 2019
  3. Taztingo

    Taztingo

    Joined:
    Aug 6, 2010
    Messages:
    7
    Resources:
    0
    Resources:
    0
    That's just what I needed, thank you!