Xyphien Forums

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

Event Creation in JS

Hello, everybody-

I am working on a script where I am trying to create a new Event during gameplay:

JavaScript:
$._bago = function() {

        var template_id = 0; // default- blank event template
        if (arguments.length != 0) template_id = Number(arguments[0]);
   
        // get event template from json and (1) load it as an object, (2) create blank page object.
        var json_fn = "EventTemplates.json";
        var data_folder = $._root() + "/data/";
        var template_json_fn = data_folder + json_fn;
   
        var json_data = $._load_text_file(template_json_fn);
   
        var x_obj = JSON.parse(json_data);
        var y_obj = JSON.parse(json_data);
   
        var json_obj = x_obj.events[template_id];
        var json_page = y_obj.events[template_id].pages[0];
   
        // new event settings

        var events_on_map = $dataMap.events.length;

        json_obj.id = events_on_map - 1;
        json_obj.x = 3;
        json_obj.y = 4;

        json_obj.pages[0].conditions.selfSwitchCh = "D";
        json_obj.pages[0].conditions.selfSwitchValid = true;    
        json_obj.pages[0].image.characterName = "!coin";
        json_obj.pages[0].image.pattern = 1;
        json_obj.pages[0].priorityType = 1;

        $gameVariables.setValue(2,"kaganap.an._pasaya(2,\x22d,l,r,u,b:0,d:1,d,u,r,l,d:1,h:12,d,u,r,l,d:1,d,l,r,u,d:1,d,i:!coin*1,d,l,r,u,i:!coin*2,d,l,r,u,i:!coin*0,b:1,v:e2*1,d:1\x22);");
        var move_commands_x = "b:0,z:2";
        var m_c_i = $._isalin(move_commands_x);

        json_obj.pages[0].moveRoute = m_c_i;

        // add blank page
        json_obj.pages.unshift(json_page);


        // create event on map
        $dataMap.events[events_on_map] = json_obj;
        $gameMap._events[events_on_map] = new Game_Event($gameMap._mapId, events_on_map);
   
        SceneManager._scene.children[0]._tilemap.addChild(new Sprite_Character($gameMap._events[events_on_map]));
   
        // turn on new event's self switch d
        var xkey = [$gameMap._mapId, json_obj.id, "D"];
        $gameSelfSwitches.setValue(xkey,true);

        $gameMap.refresh();

    };
This isn't the final function, just something I threw together to test the process.

I am able to get the object to appear on the map, however, I am not able to get it to react to the final commands in the script which turn on its self switch D so that I can get the Custom route on its second page to execute.

Any insights on what I am doing wrong / hints about what I should be doing instead?

Thank you in advance for your help!
 
Last edited:
Top