Syncing Sounds

Posted by Ytsim
Firstly, you will need to create a script, called like on_p2p (If you already have a p2p script, ignore this.)
Next, you will go to your GMS object's create event, and under gms_settings(), put the p2p script setting line. It should look something like this:
gms_settings(true, 1, objPlayer, objOtherPlayer);

So, that script is set. Now you will need to actually set up this p2p script.
Here was my approach:
///on_p2p(id, sender, list);

var ID     = argument0;
var sender = argument1;
var dslist = argument2;
switch(ID) {
    case P2P_SOUND: // This could be any number between 0-255, or a macro.

        var sound = ds_list_find_value(dslist, 0); // The sound

        audio_play_sound(sound, 0, false);

Lastly, you just send the p2p message anywhere you want to either a certain player ID, or all playerIDs
gms_p2p_send(P2P_SOUND, player_id, sound to play);

Replies (3)

Last message on 13 Dec 2017

Size43 (Administrator) on 12 Dec 2017, 12:20:16
The variable might be changing back to -1 too quickly, so your code never picks it up.

A better approach might be using the P2P messages. They allow you to send a few values to another player. P2P messages are guaranteed to arrive, so the sound will always play.

For example:

// p2p_play_sound is a macro/constant defined with a value between 0-255
gms_p2p_send(p2p_play_sound, some_player_id, sound_you_want_to_play)
// scr_p2p_received
// set this script using gms_script_set_p2p(scr_p2p_received) after gms_settings
var p2p_id = argument0, sender = argument1, values = argument2;
if p2p_id == p2p_play_sound
    audio_play_sound(ds_list_find_value(values, 0), 0, false)
Ytsim (Topicstarter) on 12 Dec 2017, 13:38:11
Haha, yeah I just recently got into the p2p messaging system like yesterday, this was before I knew about that. Really neat system in all honesty.
Size43 (Administrator) on 13 Dec 2017, 11:34:19