If anyone knows an easier, more efficient way to achieve the same results I would be very happy to learn how to do it!
Whenever I am using a parallel event/common event, I try to avoid any other types of loops unless I have to. For the most part, how your event is set up would work great for a single script call.
If I am using a bit more lines than usual in a script call, I rewrite it as a function (plugin) and call the function instead to help with performance, troubleshooting, debugging, and reading.
Feel free to use it and modify as you see fit.
Video:
Code:
Spoiler
JavaScript:
/* zombiePicture Notes:
- Declare variables:
str: string of input keys
arr: picture X coordinates
key: previous button triggered
ix1: index for string/array
ix2: index for pictures
scr: reference to $gameScreen
pic: create an array for the first 5 entries
of $gameScreen._pictures; filter out
any empty (null/undefined) entries
- Check if the player's input matches string in str
- If picture ix2 (index) is present, delete it
- If the length of the array of pictures is less than 1,
show the specific picture
- This prevents other pictures being shown (only 1 can
be shown at a time and must be removed before any
other pictures in that range can be shown)
- Console log for testing only - please remove when ready
to avoid performance hit with console.
*/
function zombiePicture() {
const str = 'fprc',
arr = [5, 170, 335, 500],
key = Input._latestButton,
ix1 = str.indexOf(key),
ix2 = ix1 + 1,
scr = $gameScreen,
pic = scr._pictures.slice(0, 5).filter(x => x);
if (Input.isTriggered(str[ix1])) {
if (scr.picture(ix2)) {
scr.erasePicture(ix2);
}
if (pic.length < 1) {
scr.showPicture(ix2, `D${ix2}`, 0, arr[ix1], 0, 100, 100, 255, 0);
}
console.log(`Key: ${str[ix1]}, Picture: ${ix2} - ${!!scr.picture(ix2)}`);
}
};
Photos:
I did not use a wait frame here because the timing is very important since it depends upon user input (a 1 wait frame caused some delay issues that didn't really pick up the key input properly) - if you want to use a higher frame wait, I would recommend changing Input.isTriggered() to Input.isPressed() with a wait frame of at least 6 frames.
Also, when key inputs are important on every frame, I usually defer it to an eventlistener instead and go from there. It is a bit more complicated to set up, though. I believe Poryg had a good tutorial on something like it.
In your case, you would rename `D${ix2}` to simply `${ix2}` since your pictures are named 1, 2, 3, and 4. Hope this helps!