GMS 2 Accessing/Modifying values of extensions with best performance

Discussion in 'Advanced Programming Discussion' started by Mert, Jun 24, 2019.

  1. Mert

    Mert Member

    Jul 20, 2016

    As of now, I have developed my Firestore extension and it is ready to be published(Free and Open Source as usual).

    My issue is that I am not sure if it's performance efficient with the way it works, unfortunately. One example would be query operations. In Java, a programmer can simply do the following code to query the database:

    I am putting different parts together here to show it as simple as possible
    private FirebaseFirestore db;
    db = FirebaseFirestore.getInstance();
    //Query smthing
    db.collection(argument).whereGreaterThan(argument, argument).limit(argument).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() //....(and it is followed by things etc.)

    In game maker, it is a bit different. Now, I have two options:
    • I can craft a long string/JSON string in Game Maker and pass it to the extension, then I'll parse this string to fill the blanks. In this case, overhead is on actually creating the data on Game Maker and passing to to extension, parsing the data & putting them in a switch case to determine what they mean. (Also remember that I'd have to change their datatypes from string to int, double etc(If it's a plain string))
    In Game Maker, it would look like this(JSON string example):

    var a = ds_map_create();
    var b = ds_list_create();
    ds_list_add(b,"whereGreaterThan","song_length",180); //Longer than 180 seconds.
    var c = ds_list_create();
    ds_list_add(c,"whereEqualTo","song_artist","Phil Collins"); //Only query his songs.
    //Now add the lists to the map.
    ds_map_add(a,"limit",10); ///Only get 10 songs of him.
    ds_map_add(a,"collection","good_songs"); //from this collection
    var str = json_encode(a);
    • Second option is to create a global variable in extension(in this case, it's java), and fill it with functions from Game Maker (I use this one)
    query_whereEqualTo("song_artist","Phil Collins");

    In the extension, I tie this data as:
    public static Query QUERY_REF = null;
    public void query_whereGreaterThan(String arg0, double arg1) {
            QUERY_REF = QUERY_REF.whereGreaterThan(arg0, arg1);
    public void query_limit(double arg0) {
            int val = (int) arg0;
            QUERY_REF = QUERY_REF.limit(val);
    ///... etc
    Now the issue is, I don't know whether this is performance efficient. My previous Firebase extensions work exactly like the second option. I am looking for the best solution. Any strategies, any tactics are appreciated.
    Last edited: Jun 24, 2019
    chirpy likes this.
  2. Mert

    Mert Member

    Jul 20, 2016
    #Update (on HTML5 extensions)

    Passing a reference to a ds_list to Javascript actually passes its reference. You can directly access to a ds_list from Javascript. Example

    In Game Maker
    var list = ds_list_create();
    ds_list_add(list, "hello","hi","what");
    In Javascript
    function passToJavascript(list) {
    var size = GMS_API.ds_list_size(list);
    for (var i = 0; i < size; i++)
                var value = GMS_API.ds_list_find_value(list, i);
    I will check if we have more functions like GMS_API.ds_list_create, which allow us to create ds_list from Javascript and pass its reference to Game Maker.


    You can also pass ds_map to Javascript in the same way.

    In Game Maker
    var map = ds_map_create();
    map[? "hello"] = "World";
    map[? "yo"] = "Hey man!";
    In Javascript - Receive ds_map
    function passToJavascript(map) {
    //Converts it to JSON string
    var JsonString = GMS_API.json_encode( map);
    //Converts it to Javascript Object
    var JsonObj = JSON.parse( jsonString );
    //Access to a value in our (what previously was ds_map)
    var Hello = JsonObj.hello;
    In Javascript - Send ds_map (To Social Async Event)
    Below code is from my Firestore Database Extension
    var map = {};
        map["id"] = FIREWEBASYNCID;
        map["category"] = docCategory;
        map["location"] = docLocation;
        map["status"] = docStatus;

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice