Again, I just want to say how thankful I am that someone took the time to take what I shared using Events and make it better and more efficient. And even more significant,
@Arthran shared it in a way that everyone interested can download it, play test it, and look at exactly how it was built to see if they can learn from it.
I think that selflessness epitomizes this community and the support that it provides to anyone who wants to learn.
Now, I will just say honestly for any newer people like me. Whether you have about the same experience and background, a little more or less experience, or if you are just starting out.
Opening and reviewing Arthran's game is both awesomely amazing and horribly humbling at the same time. When I looked at the first Common Event that is doing most of the work, I was completely overwhelmed. And my first immediate thought was "this is depressing."
I thought I had learned so much and come so far. I knew there was a ton more for me to learn, but this really makes that obvious in a quantifiable way. And I will admit, it was a little disheartening and discouraging.
BUT, this is what learning is all about. And when I took a second look and tried to read and understand each line of code, I started to see things that I recognized from the Java Script course I am doing on line, self paced, in my spare time.
I am not that far along and I have to keep going back and repeating lessons because I tend to forget simple stuff within days. But the positive thing is that I can actually understand some of the scripts. And other parts I am pretty sure I know what it is doing, just not necessarily how/why it works. And each time I go back and really look, I recognize and understand a bit more. It becomes less overwhelming.
I also remind myself that only about a year ago, I knew absolutely nothing about RPG Maker or coding. And if I had looked at something like this 3 months ago, I probably wouldn't have understood anything.
So, what I am trying to say to newer folks who are still early on their journey of learning, don't be discouraged, or disheartened, and try not to get overwhelmed. Remember that this sort of learning is very technical. And it involves taking small steps. Learning the basics and building on a solid foundation.
Don't just take plugins or solutions that are kindly offered on this forum at face value and use them in your project. Actually take the time to try to understand them. And, if possible, try to figure out if you can actually achieve the same or a similar result with just Events.
Because for me, that is one HUGE takeaway from this. You can do SO MUCH with just Events. It might not be pretty or efficient. And it might take a lot of "coding," but it is EXTREMELY helpful to learn how to do it. If nothing more than to have options in the future.
And nothing I am posting here should make Arthran feel bad or anything. I am so intensely thankful that Arthran took the time to do this and openly share.
And while this has shown me that there is so much more for me to learn, it is also a small testament to what you can do within this engine with scripting (and Events).
You don't have to stick with the typical RPG Maker appearance and JRPG if you don't really want to. Learn to make what you want to make. And I am sure you will find support here if you take the time to be part of the community.
And this has also prompted me to go back and start looking at all the sample projects, Eventing Duel Projects, and "open" games/projects that have been share on this forum to take a deeper dive into how they were made. That is a lot easier the more you learn.
So newer folks, if you haven't done it, search for Eventing Duels or similar language. You will find some incredible shared projects in those threads.
Anyway, this is way too long, but I just wanted to candidly share my thoughts for newer people and once again give thanks. You might think that understanding scripts or plugins or whatever is too difficult now, but with time, practice, and diligence, I think you will be amazed with where you will eventually end up if you just keep going.
As always, enjoy what you do. Happy Game Developing!
Sorry, I wasn't trying to make you feel depressed or anything like that. Initially, I meant to just show a basic example of how loops and math can remove a lot of manual labor out of your events and allow your system to easily scale with more cards.
But then once I started planning it out, I decided that I might as well go ahead and remove the dependency on the external plugin that you were using (the ButtonPicture plugin), so that it'd be a purely evented
¹ solution. Then when I was planning that part out, I realized that it'd be a good opportunity to go ahead and make a sweet hover effect for the cards. Then when I was planning out how to implement those things, I realized that there was a way I could get the entire system working without having to use any parallel events (which seemed too nifty to resist)... and things just kinda snowballed and I wound up going a bit overboard.
I'll go ahead and point out and explain some isolated bits of code that illustrate the main concepts that I originally wanted you to take away from this:
Here are the only parts that require manual adjustment, depending on the number of cards that you want to use:
JavaScript:
// These constants need to be pre-defined by us
const numMatches = 10;
const numCols = 5;
const numRows = 4;
const cardWidth = 116;
const cardHeight = 123;
const colSpacing = 25;
const rowSpacing = 25;
As the name suggests,
numMatches is the number of matches (10 matches = 20 cards total).
numCols is the number of columns (i.e. the number of cards in each row), and
numRows is the number of rows of cards.
cardWidth and
cardHeight are the dimensions of the png files.
colSpacing and
rowSpacing are the amount of pixels that you want to have between each card.
With those values set, we can use math to automatically calculate where each card needs to go. For example:
JavaScript:
// Here we calculate the starting x and y positions
const startx = Math.floor((Graphics.width - (numCols * cardWidth + (numCols - 1) * colSpacing)) / 2);
const starty = Math.floor((Graphics.height - (numRows * cardHeight + (numRows - 1) * rowSpacing)) / 2);
startx and
starty are the x and y coordinates that we want to place our first card at. For example, if you take the number of columns and multiply it by the width of each card, you get the total number of horizontal pixels that your cards will occupy. However, you also need to account for the space between each card, so we take the
colSpacing (number of horizontal pixels between each card) and multiply it by the number of spaces that will be between each card (which is 1 less than the number of cards), and add that to our previous value... this will give you the total number of horizontal pixels that are necessary to display your cards. If you subtract that from the total width of the screen, and then divide it by 2, that'll give you the starting x coordinate that will center your cards on the screen. The
Math.floor() call is simply to remove any decimal numbers incase the division by 2 didn't work out evenly (since there's no such thing as a partial pixel). And then the
starty constant does all the same stuff, only vertically instead of horizontally.
We'll use those starting x and y coordinates for more calculations:
JavaScript:
// Calculate total number of cards
const numCards = numMatches * 2;
for (let i = 0; i < numCards; i++) {
// Display the cards
const x = startx + (i % numCols) * (cardWidth + colSpacing);
const y = starty + Math.floor(i / numCols) * (cardHeight + rowSpacing);
$gameScreen.showPicture(i + 2, "CardBack", 0, x, y, 100, 100, 255, 0);
}
Here we loop the same number of times as there are cards, with the value of the variable
i starting at 0, and incrementing by 1 each iteration of the loop. We use the value of
i, in combination with some of the previous values that we specified/calculated in order to do some fancy math and calculate the x and y coordinates of each card. We also use the value of i to calculate the picture ID of each card (the ID of the first card will be 2, since 1 is already being used by the table top graphic at this point), and show the pictures.
Now with this system in place, you can easily change the size or the amount of cards, and the only thing you need to change is the initial constants from the first code snippet.
I would guess that you are already somewhat familiar with all of the JavaScript syntax in these snippets. Rather than the JavaScript itself, I suppose that the harder part would probably be the math involved, and coming up with the idea to use the JavaScript in this manner in the first place.
As you know, there's a lot of other stuff in the script in my actual project. I simply pulled out these particular snippets because I think that they illustrate the most important concept for you to learn right now.
On a completely unrelated note, in case anyone cares, I uploaded the project to
Itch, so in the event that the previous links are dead at some point, you can grab it from there instead. You can also play the game in your browser there, if you feel like trying it out.
Footnotes
1. Personally, I consider using script commands to be part of events, so I do feel that my solution is actually an "evented" one. However, I'll be the first to admit that I took it to a level that would make it perfectly fair to argue otherwise.