MANUAL for GMnet ENGINE and GMnet CORE

mp_map_syncIn and mp_map_syncOut

Whenever you use mp_add, you need to do 2 things for each variable you sync with it:

  1. Add the following to the end step event:

    self.VARIABLENAME = mp_map_syncOut("VARIABLENAME", self.VARIABLENAME);

    Where you replace "VARIABLENAME" with the name of your variable.

  2. Run the following code whenever you change that variable, we recommend doing this in the begin step event:
    mp_map_syncIn("VARIABLENAME",self.VARIABLENAME);

    This also needs to be done at least once after you set up the engine if you don't put it in begin step.

THIS DOES NOT TO BE DONE FOR ANY OTHER FUNCTION STARTING WITH mp_add. ONLY WITH mp_add ITSELF!

Technical explanation

The engine needs to know what variables it needs to sync. So if you execute this code:

mp_add("message","message",buffer_string,5);

Then we know you want to sync the variable message. The problem/limitation in Game Maker is, that we can't get the value of the message variable of this instance now. Why?

Well let me have an example. This works:

var instance; //Some valid instance
var test = (instance).x;
//Test will now have the x position of the instance as value

Now in that case we are directly accessing the x-Position of the instance. That's what all other mp_add* functions besides mp_add itself do, because they can be hardcoded. When writing the code we already know what to sync and in what order.

We don't know how your variables are called while coding, so we have to get them dynamically. Let's take the following exmaple:

var instance; //Some valid instance
var variable = "x";
//What now???
var test = (instance).variable; //? Doesn't work!
var test = (instance).(variable); //? Doesn't work!
var test = (instance)[variable]; //? Doesn't work!

There's no way in Game Maker Studio of doing that. That's why we use a ds_map to cache your instances variables. Because with a ds_map, that does work!

var map; //Some valid ds_map that belongs to your instance; That's what you change when using the syncIn and syncOut command
var variable = "x";

var test = ds_map_find_value(map,variable); //Yay! Works!

Back to index.


Creative Commons License

All pages in this manual are licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Manuals / GMnet ENGINE Manual

GameMaker: Studio is owned by YoYoGames. GMnet is not affiliated with YoYoGames.
The GMnet logos use icons from Entypo (http://entypo.com/) and Open Iconic (https://useiconic.com/open/). They are licensed under CC BY-SA 4.0.