Skip to content

EventListener.add(u, EVENT_PLAYER_UNIT_SELECTED) does not work in init block? #433

@peawyoyoyin

Description

@peawyoyoyin

Hello wurstscript maintainers. I'm new to wurstscript and just fiddling around at the moment. I am trying to use ClosureEvents to trigger some actions when a specific unit is selected. The trigger is active immediately upon map initialization.

I noticed that EventListener.add(u, EVENT_PLAYER_UNIT_SELECTED) does not work if the code is not wrapped under doAfter(0.5). Is this intended? Even in the Wurst item shop demo there is doAfter(0.5) for seemingly no reason.

I am completely okay with adding 0.5 second delay to the initialization. However, I could not find this behavior documented anywhere in wurstscript docs. If this is intended or caused by some limitations, then it should be in the docs. Please let me know, I am willing to help update the docs if that is better.

Simple steps to reproduce:

  1. Clone repo https://github.com/Frotty/wurst-item-shop/tree/main & use wurst setup jar to install dependencies
  2. Comment out doAfter(0.5) in ItemShopTest.wurst
  3. Run the map
  4. Select paladin

We can no longer see "set target hero2" logged as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions