Page 1 of 1

on_tick in multiplayer

Posted: Sun Mar 05, 2017 5:44 am
by withers
How does this work? As an example I have a script running at regular intervals. If it's a multiplayer game with 4 players, would that mean this script runs 4 times every interval? Or just once?

Re: on_tick in multiplayer

Posted: Sun Mar 05, 2017 7:19 am
by Rseding91
From a mod perspective just pretend that multiplayer doesn't exist. All you care about as a mod developer is handling events and reactions to those events. If you want to do something you either do it to a specific player or all players you simply do that.

A basic example: you want to send a message to "the player" when they build something:

In the event handler the handler gives you the player_index of the player that did the building so you would then do: game.players[event.player_index] and you have the player that did the building. You don't care how many players there are - you're just reacting to events.

Now that event works for single player and multiplayer. In multiplayer the player_index will just be what ever player is doing the action at the given time.

Re: on_tick in multiplayer

Posted: Sun Mar 05, 2017 8:21 am
by withers
Okay thanks for that helpful information but my specific question involves doing something to a custom global table. (not any particular player) I am doing things with this table every 6 seconds.

The table keeps track of the age of every entity in the game of a specific type among other things. I'd like to know if, with 4 players for example, the table is getting updated 4 times per 6 seconds and not just once per 6 seconds as intended. If so, I need to adjust my on_tick function accordingly.

Mod is here.

viewtopic.php?f=94&t=41892


Thanks for the help! :)

Re: on_tick in multiplayer

Posted: Sun Mar 05, 2017 12:08 pm
by Klonan
withers wrote:Okay thanks for that helpful information but my specific question involves doing something to a custom global table. (not any particular player) I am doing things with this table every 6 seconds.

The table keeps track of the age of every entity in the game of a specific type among other things. I'd like to know if, with 4 players for example, the table is getting updated 4 times per 6 seconds and not just once per 6 seconds as intended. If so, I need to adjust my on_tick function accordingly.

Mod is here.

viewtopic.php?f=94&t=41892


Thanks for the help! :)
The tick event will only ever fire once per tick, so in this case your table will be updated properly, and not once per player per interval