Carpet

Carpet

2M Downloads

Player events run for all players online

Xendergo opened this issue ยท 4 comments

commented

If you paste this code into a .sc file:

__on_player_clicks_block(player, block, face)->(
    print(player, player);
    print(player, player());
);

Then spawn a fake player and load the script, you'll see that the event runs twice. Both times the player who did the action was passed to the function, but player() returned a different player.

I've also noticed that if you don't include who to send the print statement to, the print statements don't work when the player argument doesn't match player()

commented

Is your app a global scoped app or a player scoped one?

Also, if player scoped, could you check whether the event is running those two times under a same player scope or once per scope (e.g. try adding +1 to a variable each time and check result)? And does it run three times if having three players?

(this is an issue in any of those configurations)

commented

The app is player scoped, and the issue doesn't occur when loading the script as global

It does run 3 times when there are 3 players

I'm not sure what you mean by add 1 to a variable, but running this prints 0, 0, 1, 1 for every player online, as if the variable isn't being saved properly:

v = 0;
global_x = 0;

__on_player_clicks_block(player, block, face)->(
    print(player, v);
    print(player, global_x);
    v += 1;
    print(player, v);
    global_x += 1;
    print(player, global_x);
);

Also, the issue doesn't happen when running the code using /script run, but the event also doesn't occur for any other players

Also, I've found that doing if (player ~ 'name' == player() ~ 'name', ...) seems to fix the issue

commented

hmm, player events have changed fairly recently - there might be some artifacts of that.

commented

Yeah, its a recent bug - the player specific events target all player scoped instances of the app, not just the app for that player. Will need to fix that.