ItsDeltin / Overwatch-Script-To-Workshop

Converts scripts to Overwatch workshops.
207 stars 24 forks source link

New feature of "async" action #480

Closed Erythritee closed 1 month ago

Erythritee commented 3 months ago

If you use the event player in the async subroutine called by the global rule, it looks like this:

playervar Number asd;
void test1() "test"
{
    SmallMessage(EventPlayer(), "test");
    EventPlayer().asd = 1;
}

rule: 'My Rule'
Event.OngoingGlobal
if (IsFiringPrimary(HostPlayer()))
{
    async! test1();
}

You will encounter compiler errors: The function 'test1' calls a restricted value of type 'Event Player'. But in fact, it works in the game In the game, when EventPlayer().asd = 1 is executed, it actually modifies the variable value in the global variable that has the same index as asd. In my example, the index of qwer is 9, so he will modify the global variable with index 9, which is input

Y5V4YMO51{TB_0QSSLCV)@B

In other words, the context object used by the subroutine in the global rule is Gloal

CactusPuppy commented 1 month ago

As per the wiki, in order to use player-context values, you will need to specify that your subroutine is called from player contexts:

The parameters and variables defined in subroutines will be global by default. To change it to be player variables, add the playervar keyword before the subroutine rule name.

playervar Number asd;
void test1() playervar "test"
{
SmallMessage(EventPlayer(), "test");
EventPlayer().asd = 1;
}