EDIT: Y'all can close this, I figured it out. 🙂
Alright, the things I'm trying to do are getting a bit complex for me, [longtime RM user, still amatuer at JS] and I'll try to provide plenty of context and screenshots of exactly what I've gotten set up and what the heck it's doing.
This one is for someone who's in the mood to read a bunch of information and solve a really complicated problem for me. It's gonna be annoyingly huge and if any of you even bother to read it all, thank you so much.
This game is a Maps-only Puzzle game. I'm having a few puzzles involving Blocks that can be pushed into water and become platforms. I was able to do this via eventing pretty easily, using Terrain Tags to check whether the block was being pushed into water or against some other impassable tile.
This is just a test room. The yellow blocks are just normal blocks that can be pushed around. The Grey block can be pushed into water and form a bridge. The Blue blocks work just like the grey, except they sink after about 3 seconds. The Red Block is the player, Clinky. The greyish blue stuff is water. But we aren't here to talk about my art style.
[I set the Terrain Tag for my Water to 2 using regular methods.]
Then, to make the tiles walkable and able to have another block pushed over them, I used a script I found by Shaz that gives us the ability to comment on an Event page and have the map treat that event as if it had whatever Terrain Tag we write.
Using that script, I was able to make it so that the movement of the Blocks checks whether or not the Terrain ID is 2 or higher, and if it is, the Block activates THROUGH and allows the player to move it onto the usually unpassable tile. If the Terrain ID check is 2, it's Water, so the Block activates Self Switch A and becomes a bridge. I use Shaz's script to set that Bridge as a new Terrain ID: The regular (Grey) Block Bridges are 3, which can be pushed over by any other item that runs the Terrain ID check from before [because the other items pass the >2 check, but aren't exactly two so they don't ding anything], and they stay that way because. So far that's working beautifully.
Below is the Common Event that my Blocks call on Player Touch. The first two lines get the Map XY of the event being moved, the 4 Player facing checks add +1 to the direction the Block is moving to check for Terrain IDs, then the system I explained above is implemented, and finally there's an Else handler that makes the Blocks move like normal if they're just on regular old 0 Terrain tiles.
Where the regular Blocks' Self Switch A turns on a second event page where they just sit there being perfect little Terrain 3 bridges, the sinking blocks have a Second and Third page where they sit for a few frames being a Bridge, then they sink.
The comments on each page create a Terrain ID for that tile as per Shaz's script above. Sinking blocks as temporary bridges are Terrain 4, which makes it so that Blocks can be pushed over it [I'll explain in a minute why I used a different TID than the other bridges], and then after they sink they become Terrain 2 again, so that the water behaves like normal water.
The 3rd page check about Maps just resets the block if you leave or die [Dying in this game uses a quick warp to and from a blank map to reset rooms.]
All of this is working just fine.
Here's the Common Event that's called by Page 2 of the sinking Block. It plays the splash sound of the boulder going in the water, it runs that same Map check just in case the player dies or leaves during this phase, it waits 180 frames of free use bridge time, and then it plays a sinking noise. Then you've got a quick check whether the player is on Terrain ID 4, which kills him if he is. This is why I chose TID 4 for the sinking bridges, so that a sinking Block doesn't randomly murder you if you're across the map on a regular grey Block Bridge. Then it activates Self Switch B to take it to the page where the Block is sunk and the Water tile is good old TID 2 again.
So then I got to thinking, which is what normally causes trouble in the middle of a complicated project like this.
When you're pushing a block over a Sinking Bridge, and the Bridge sinks, the Block is just stuck in that spot. You can't push it because you can't walk on the tile, and it can't move on its own. This is a puzzle game, so there's a mapped Room Reset button anyway, which I count on the player using if stuck in this way. [It was good enough for Lolo, it's good enough for me.]
But I wanted something that looked a little less careless:
1. I want Blocks (or enemies, once I make them able to walk over the tiles too) that are on a Sinking Bridge to be lost, more than likely using Event Erase somehow.
2. I want Sinking Blocks that are left on top of a Sinking Bridge when it sinks, to become a new Bridge. They fall into Terrain 2 water after all, they should become a bridge like they would if you pushed them. The existing system only checked whether they should turn into a bridge when they were being moved, but I needed something that worked in a more static fashion.
I told you ALL OF THAT so that I could show you this one single event with two script calls, so that I can get help figuring out what's wrong.
Therefore, I created this event, which, if I can make it work, will be placed on every map that has pushable blocks and have all the Event IDs updated per map. But these numbers apply to the Test Map pictured above.
The scripts inside read as follows.
The first one erases Blocks that happen to be on a bridge when it collapses by checking whether they're on Terrain ID 2. The forEach numbers there, 3,4, and 7, are the event IDs of all those regular Yellow pushable blocks.
This second one should turn all my pushable blocks into bridges, either when they fall into water through a Sinking Bridge [or, frankly, this should take care of it the regular way too and eliminate the need for half the event stuff I did up at the start of this post]. Again the forEach are the IDs of the Blocks that can become bridges, 1 being the Grey block and 6, 9, and 11 being the blue Sinking blocks.
Now, as far as I can tell, all of this should be set up correctly, but here's the bizarre thing that's happening: the Bridge dropping concept [2nd script] works correctly ONLY IF I push the Blue blocks into the water in ascending order of the Event IDs.
The blocks are Copy/Pasted. They should work exactly the same way. However, the Blocks only wait to become bridges if I push them into the water in the order 6, 9, 11. Otherwise, if I push one of the other ones first, it acts as though the Terrain ID of the Bridge is 2, and goes ahead and turns the second block into a bridge without waiting for the first one to collapse.
Likewise, since it's reading them as TID 2 for whatever reason, regular yellow blocks [1st Script] disappear instantly when pushed onto Bridges made by Blocks 9 and 11, because they think it's time to Sink already.
Block 6 works flawlessly exactly how I want it to; it can hold any of the other blocks, including Block 1, until the Bridge sinks, and then the Block on top acts correctly. Block 9 can correctly hold Block 11 until it drops, but no others. 11 can hold nothing.
I tried re-arranging the list of numbers in the forEach function, that didn't seem to have any bearing on which of them works right. The only consistency I can find in which one works and which one doesn't is the order of the Event IDs.
So basically, is there some massive thing I'm missing here? Am I overlooking a gross error in my scripts? Am I making all of this WAY MORE COMPLICATED than it should be? Please, any amount of help would be so appreciated.
Thank you so much even if all you did was read this. Let me know if there's any other information I should show to make this problem clearer.
Alright, the things I'm trying to do are getting a bit complex for me, [longtime RM user, still amatuer at JS] and I'll try to provide plenty of context and screenshots of exactly what I've gotten set up and what the heck it's doing.
This one is for someone who's in the mood to read a bunch of information and solve a really complicated problem for me. It's gonna be annoyingly huge and if any of you even bother to read it all, thank you so much.
This game is a Maps-only Puzzle game. I'm having a few puzzles involving Blocks that can be pushed into water and become platforms. I was able to do this via eventing pretty easily, using Terrain Tags to check whether the block was being pushed into water or against some other impassable tile.
This is just a test room. The yellow blocks are just normal blocks that can be pushed around. The Grey block can be pushed into water and form a bridge. The Blue blocks work just like the grey, except they sink after about 3 seconds. The Red Block is the player, Clinky. The greyish blue stuff is water. But we aren't here to talk about my art style.
[I set the Terrain Tag for my Water to 2 using regular methods.]
Then, to make the tiles walkable and able to have another block pushed over them, I used a script I found by Shaz that gives us the ability to comment on an Event page and have the map treat that event as if it had whatever Terrain Tag we write.
/*:
* Event Terrain by Shaz
* Ver 1.00 2019.01.17
* Shaz_EventTerrain.js
*
*
* @plugindesc Allow an event page to override the map's terrain.
* @Author Shaz
*
* @Help This plugin allows you to give a terrain id to an event, so any
* calls to check the terrain on an X/Y coordinate will return the terrain
* specified on the event rather than the terrain on the map tile. If there
* is no event on that tile, or the event doesn't have a terrain override
* on that page, the map tile will be used.
*
* USAGE:
* Add <terrain:x> as a comment to an event page, where x is a number, to have
* that event page mimic that terrain ID.
*
* This will allow you to use more terrains than the 7 available in the
* editor.
*
* Example:
* <terrain:1> in a comment on an event will override any tile that event is
* on to have terrain 1 instead of what is specified by the map.
*
* NOTE:
* This plugin has no plugin commands.
*
*/
var Imported = Imported || {};
Imported.Shaz_EventTerrain = true;
var Shaz = Shaz || {};
Shaz.ET = Shaz.ET || {};
Shaz.ET.Version = 1.00;
(function() {
var _Shaz_ET_Game_Event_initMembers = Game_Event.prototype.initMembers;
Game_Event.prototype.initMembers = function() {
_Shaz_ET_Game_Event_initMembers.call(this);
this._terrainId = null;
};
var _Shaz_ET_Game_Event_clearPageSettings = Game_Event.prototype.clearPageSettings;
Game_Event.prototype.clearPageSettings = function() {
_Shaz_ET_Game_Event_clearPageSettings.call(this)
this._terrainId = null;
};
var _Shaz_ET_Game_Event_setupPageSettings = Game_Event.prototype.setupPageSettings;
Game_Event.prototype.setupPageSettings = function() {
_Shaz_ET_Game_Event_setupPageSettings.call(this);
this._terrainId = null;
if (this.page() && this.list()) {
this.list().filter(function(cmd) {
if ((cmd.code === 108 || cmd.code === 408) &&
cmd.parameters[0].match(/<terrain:\2*(\d+)>/)) {
this._terrainId = parseInt(RegExp.$1);
}
}.bind(this));
}
};
Game_Event.prototype.terrainId = function() {
return this._terrainId;
}
var _Shaz_ET_Game_Map_terrainTag = Game_Map.prototype.terrainTag;
Game_Map.prototype.terrainTag = function(x, y) {
var event = this.eventsXy(x, y)[0];
if (event && event.terrainId()) {
return event.terrainId();
} else {
return _Shaz_ET_Game_Map_terrainTag.call(this, x, y);
}
}
})();
* Event Terrain by Shaz
* Ver 1.00 2019.01.17
* Shaz_EventTerrain.js
*
*
* @plugindesc Allow an event page to override the map's terrain.
* @Author Shaz
*
* @Help This plugin allows you to give a terrain id to an event, so any
* calls to check the terrain on an X/Y coordinate will return the terrain
* specified on the event rather than the terrain on the map tile. If there
* is no event on that tile, or the event doesn't have a terrain override
* on that page, the map tile will be used.
*
* USAGE:
* Add <terrain:x> as a comment to an event page, where x is a number, to have
* that event page mimic that terrain ID.
*
* This will allow you to use more terrains than the 7 available in the
* editor.
*
* Example:
* <terrain:1> in a comment on an event will override any tile that event is
* on to have terrain 1 instead of what is specified by the map.
*
* NOTE:
* This plugin has no plugin commands.
*
*/
var Imported = Imported || {};
Imported.Shaz_EventTerrain = true;
var Shaz = Shaz || {};
Shaz.ET = Shaz.ET || {};
Shaz.ET.Version = 1.00;
(function() {
var _Shaz_ET_Game_Event_initMembers = Game_Event.prototype.initMembers;
Game_Event.prototype.initMembers = function() {
_Shaz_ET_Game_Event_initMembers.call(this);
this._terrainId = null;
};
var _Shaz_ET_Game_Event_clearPageSettings = Game_Event.prototype.clearPageSettings;
Game_Event.prototype.clearPageSettings = function() {
_Shaz_ET_Game_Event_clearPageSettings.call(this)
this._terrainId = null;
};
var _Shaz_ET_Game_Event_setupPageSettings = Game_Event.prototype.setupPageSettings;
Game_Event.prototype.setupPageSettings = function() {
_Shaz_ET_Game_Event_setupPageSettings.call(this);
this._terrainId = null;
if (this.page() && this.list()) {
this.list().filter(function(cmd) {
if ((cmd.code === 108 || cmd.code === 408) &&
cmd.parameters[0].match(/<terrain:\2*(\d+)>/)) {
this._terrainId = parseInt(RegExp.$1);
}
}.bind(this));
}
};
Game_Event.prototype.terrainId = function() {
return this._terrainId;
}
var _Shaz_ET_Game_Map_terrainTag = Game_Map.prototype.terrainTag;
Game_Map.prototype.terrainTag = function(x, y) {
var event = this.eventsXy(x, y)[0];
if (event && event.terrainId()) {
return event.terrainId();
} else {
return _Shaz_ET_Game_Map_terrainTag.call(this, x, y);
}
}
})();
Using that script, I was able to make it so that the movement of the Blocks checks whether or not the Terrain ID is 2 or higher, and if it is, the Block activates THROUGH and allows the player to move it onto the usually unpassable tile. If the Terrain ID check is 2, it's Water, so the Block activates Self Switch A and becomes a bridge. I use Shaz's script to set that Bridge as a new Terrain ID: The regular (Grey) Block Bridges are 3, which can be pushed over by any other item that runs the Terrain ID check from before [because the other items pass the >2 check, but aren't exactly two so they don't ding anything], and they stay that way because. So far that's working beautifully.
Below is the Common Event that my Blocks call on Player Touch. The first two lines get the Map XY of the event being moved, the 4 Player facing checks add +1 to the direction the Block is moving to check for Terrain IDs, then the system I explained above is implemented, and finally there's an Else handler that makes the Blocks move like normal if they're just on regular old 0 Terrain tiles.
Where the regular Blocks' Self Switch A turns on a second event page where they just sit there being perfect little Terrain 3 bridges, the sinking blocks have a Second and Third page where they sit for a few frames being a Bridge, then they sink.
The comments on each page create a Terrain ID for that tile as per Shaz's script above. Sinking blocks as temporary bridges are Terrain 4, which makes it so that Blocks can be pushed over it [I'll explain in a minute why I used a different TID than the other bridges], and then after they sink they become Terrain 2 again, so that the water behaves like normal water.
The 3rd page check about Maps just resets the block if you leave or die [Dying in this game uses a quick warp to and from a blank map to reset rooms.]
All of this is working just fine.
Here's the Common Event that's called by Page 2 of the sinking Block. It plays the splash sound of the boulder going in the water, it runs that same Map check just in case the player dies or leaves during this phase, it waits 180 frames of free use bridge time, and then it plays a sinking noise. Then you've got a quick check whether the player is on Terrain ID 4, which kills him if he is. This is why I chose TID 4 for the sinking bridges, so that a sinking Block doesn't randomly murder you if you're across the map on a regular grey Block Bridge. Then it activates Self Switch B to take it to the page where the Block is sunk and the Water tile is good old TID 2 again.
So then I got to thinking, which is what normally causes trouble in the middle of a complicated project like this.
When you're pushing a block over a Sinking Bridge, and the Bridge sinks, the Block is just stuck in that spot. You can't push it because you can't walk on the tile, and it can't move on its own. This is a puzzle game, so there's a mapped Room Reset button anyway, which I count on the player using if stuck in this way. [It was good enough for Lolo, it's good enough for me.]
But I wanted something that looked a little less careless:
1. I want Blocks (or enemies, once I make them able to walk over the tiles too) that are on a Sinking Bridge to be lost, more than likely using Event Erase somehow.
2. I want Sinking Blocks that are left on top of a Sinking Bridge when it sinks, to become a new Bridge. They fall into Terrain 2 water after all, they should become a bridge like they would if you pushed them. The existing system only checked whether they should turn into a bridge when they were being moved, but I needed something that worked in a more static fashion.
I told you ALL OF THAT so that I could show you this one single event with two script calls, so that I can get help figuring out what's wrong.
Therefore, I created this event, which, if I can make it work, will be placed on every map that has pushable blocks and have all the Event IDs updated per map. But these numbers apply to the Test Map pictured above.
The scripts inside read as follows.
The first one erases Blocks that happen to be on a bridge when it collapses by checking whether they're on Terrain ID 2. The forEach numbers there, 3,4, and 7, are the event IDs of all those regular Yellow pushable blocks.
Script: [3,4,7].forEach(function(e) {if ($gameMap.event(e).terrainTag() === 2) {$gameMap.event(e).erase()}});
This second one should turn all my pushable blocks into bridges, either when they fall into water through a Sinking Bridge [or, frankly, this should take care of it the regular way too and eliminate the need for half the event stuff I did up at the start of this post]. Again the forEach are the IDs of the Blocks that can become bridges, 1 being the Grey block and 6, 9, and 11 being the blue Sinking blocks.
Script: [1,6,9,11].forEach(function(e) {if ($gameMap.event(e).terrainTag() === 2) {$gameSelfSwitches.setValue([$gameVariables.value(18), e, 'A'], true)}});
Now, as far as I can tell, all of this should be set up correctly, but here's the bizarre thing that's happening: the Bridge dropping concept [2nd script] works correctly ONLY IF I push the Blue blocks into the water in ascending order of the Event IDs.
The blocks are Copy/Pasted. They should work exactly the same way. However, the Blocks only wait to become bridges if I push them into the water in the order 6, 9, 11. Otherwise, if I push one of the other ones first, it acts as though the Terrain ID of the Bridge is 2, and goes ahead and turns the second block into a bridge without waiting for the first one to collapse.
Likewise, since it's reading them as TID 2 for whatever reason, regular yellow blocks [1st Script] disappear instantly when pushed onto Bridges made by Blocks 9 and 11, because they think it's time to Sink already.
Block 6 works flawlessly exactly how I want it to; it can hold any of the other blocks, including Block 1, until the Bridge sinks, and then the Block on top acts correctly. Block 9 can correctly hold Block 11 until it drops, but no others. 11 can hold nothing.
I tried re-arranging the list of numbers in the forEach function, that didn't seem to have any bearing on which of them works right. The only consistency I can find in which one works and which one doesn't is the order of the Event IDs.
So basically, is there some massive thing I'm missing here? Am I overlooking a gross error in my scripts? Am I making all of this WAY MORE COMPLICATED than it should be? Please, any amount of help would be so appreciated.
Thank you so much even if all you did was read this. Let me know if there's any other information I should show to make this problem clearer.