This is where my familiarity with other languages causes me trouble: making copies of objects in JS. I'm used to being able to make pretty clean, independent, copies of something, and JS handles a lot of things by reference and it causes me no end of stress...
I'm using the Sanshiro MapGenerator (https://forums.rpgmakerweb.com/index.php?threads/map-generator.51808/) and arleq1n's Tactics system (https://forums.rpgmakerweb.com/index.php?threads/tactics-system-1-2-1-tactical-battle-system.117600/) for significant elements in my game. The following script borrows some concepts for the Sanshiro MapGenerator to copy template events for placing party members (and enemies) onto the map in various locales so we can run the battle.
My issue right now comes from JS and how it handles objects and references, IE that JS doesn't copy things all the time, it REFERENCES them, so that doing something to a "copy" affects the referenced object. In this particular case, we're setting up our party members. Everything works perfectly when we setup a single enemy and a single party member; the events are copied, details updated, events placed, battle goes on without a hitch.
Now, if we add a second party member, we have an issue.
We lay down our first party member, things are fine.
When we lay down our second party member, updates to portions of the event are applied to the first instance as well. The TBS uses the notetag/meta value <Party:X> or <Enemy:X> to designate what the unit is. When we update the party event so the meta tag is "2" for the second party member, the first event is updated as well, giving me two instances of party member 2.
Any thoughts on how to make an INDEPENDENT copy of the event, so things aren't passed around the copies by reference? Unless its not a JS thing but an unforeseen interaction in RPGM?
Note: "dataMapEventsXy" is a function to ID an event at the coordinates and return that template for the new Game_Event.
I'm using the Sanshiro MapGenerator (https://forums.rpgmakerweb.com/index.php?threads/map-generator.51808/) and arleq1n's Tactics system (https://forums.rpgmakerweb.com/index.php?threads/tactics-system-1-2-1-tactical-battle-system.117600/) for significant elements in my game. The following script borrows some concepts for the Sanshiro MapGenerator to copy template events for placing party members (and enemies) onto the map in various locales so we can run the battle.
My issue right now comes from JS and how it handles objects and references, IE that JS doesn't copy things all the time, it REFERENCES them, so that doing something to a "copy" affects the referenced object. In this particular case, we're setting up our party members. Everything works perfectly when we setup a single enemy and a single party member; the events are copied, details updated, events placed, battle goes on without a hitch.
Now, if we add a second party member, we have an issue.
We lay down our first party member, things are fine.
When we lay down our second party member, updates to portions of the event are applied to the first instance as well. The TBS uses the notetag/meta value <Party:X> or <Enemy:X> to designate what the unit is. When we update the party event so the meta tag is "2" for the second party member, the first event is updated as well, giving me two instances of party member 2.
Any thoughts on how to make an INDEPENDENT copy of the event, so things aren't passed around the copies by reference? Unless its not a JS thing but an unforeseen interaction in RPGM?
Note: "dataMapEventsXy" is a function to ID an event at the coordinates and return that template for the new Game_Event.
JavaScript:
// Setup the party...
setParty = function() {
var refXY = {x:0,y:2};
for(i=1;i<=$gameParty._actors.length;i++) {
var event = new Game_Event($gameMap.mapId(), dataMapEventsXy(refXY.x, refXY.y)[0].id);
let dataEvent = $dataMap.events[event._eventId];
let actor = $gameActors.actor($gameParty._actors[i-1]);
event.meta = dataEvent.meta;
event.name = dataEvent.name + i;
event.setImage(actor._characterName,actor._characterIndex);
event.meta.Party = i;
console.log("Event party member ID is..." + event.meta.Party);
$gameMap._events.push(event);
event._eventId = $gameMap._events.indexOf(event);
var newLocationX = (Math.floor($dataMap.width/2)-Math.floor($gameParty._actors.length/2)) + (i-1);
var newLocationY = $dataMap.height-3;
event.setPosition(newLocationX, newLocationY);
console.log("Set Player " + i + "...");
}
//Move the player...
$gamePlayer.locate(newLocationX, newLocationY);
$gamePlayer.reserveTransfer($gameMap.mapId(), $gamePlayer.x, $gamePlayer.y);
}