Sunday, May 7, 2017

Renpy: The Difference Between Jump and Call

I'm sure that there's a learning curve to any particular programming language. I wouldn't really know - I'm barely fluent in HTML, and I have a very loose grasp on Python as it is.

That said, I've started to get pretty good with using Ren'Py, and recently came across this little tidbit that makes my life so much easier now that I understand it correctly.

Today, I'm talking about the difference between a jump and a call.

When making any project in Ren'Py, you could theoretically place everything into a single file... but doing so is a nightmare in practice, especially when it comes to finding particular scenes. So you split the script up into different files. Not every Visual Novel (or game in general) needs to have a linear progression, but it's usually nice to allow some amount of player agency, or to offer branching paths. Even if it's just something as simple as letting the player choose which scene plays out next, you need to be able to make that happen in the code somehow.

So, you use the jump command to go over to a label. This is telling the code "look for this thing I defined and run it immediately". Most of the time, this works really well, but then sometimes, you need something just a little bit more complex.

Let's pretend that you're like me, and you want a game with some kind of a day planner. Or has a hub menu that you make choices from. You make selections and scenes play out. But how do you get to return to the hub? Well, you could jump to it, but that's not always the ideal way to go about matters - especially if you've got a previously-running script that needs to keep executing (like a day planner). You need some way to return to where you were when executing your code, and a jump command just won't do.

In these cases, you use the call command instead. One way to think of it is putting a bookmark where you just were, so that at the end of your scene you can use the return command to take you right back to where you came from. You could think of it as inserting a new block - whatever is inside runs, and then returns to the previous block (unless you make a new block inside of that one).

So, what happens if you use the jump command, and then end your scene with return? Well, if you do that, you go back to the main menu. This is not the ideal way of doing things, especially not if there's more game planned after that!

The reason is because, as I mentioned above, using the jump command treats everything as though it were running in the same block of code. If you're in the main block, then when you return, there's nothing left to go back to except the start of the game - meaning your main menu.

In a lot of simpler games, jump is more than enough to get you where you want to go. But if you need something a little more involved, call will become your best friend.

Hopefully this helps someone better understand these tools. It's taken me awhile to get this far, but I've got to say it's really rewarding to finally understand these things.

Monday, April 17, 2017

April 2017 Progress Report: Project Cranberry Jam

It has been several months since I last gave any indication as to where we stand for Project Cranberry Jam. This is unacceptable so here goes.

All of the character and background artwork has been completed, though not all of the assets have been converted just yet. Being a one man operation in a lot of respects slows some of that progress down. (Not to mention the attending hardware/OS failures that initially delayed progress, combined with a rather troublesome bug... ugh.)

In what time I've been able to find, work has been slowly progressing on getting the scenes into the engine so that work in other areas can finally begin. The scenes for the demo itself are about 60% completed at this point - the scenes required for Week 3 are about 30% finished by now. A number of them are fairly short, so that shouldn't be too difficult to deal with, provided I have the time.

UI design still hasn't been touched. Again, one man operation, UI work will come after I get the scenes taken care of. Also, no audio has been completed yet - though work has commenced on some of the music. If the stars align, this is something that can be taken care of within another month or so.

There's still a good amount of editing which needs to be done as well. For now, my focus is on getting the scripts into the engine, so that they can be more easily adjusted - I'll have to go through them all again anyways when it comes time to put in the audio.

So as it stands, we're at about 50% completion for the demo, I feel. Getting the scenes all put in is the biggest part of the game - it's the core of the experience, really. Once those are all finished, the demo can be considered about 75% complete - the rest is getting in the audio, fixing any other weird bugs that might pop up, and finishing the UI (and assembling some credits? That's probably important for a full release!).

All told, still a lot of work to be done, and while it's not where I hoped it would be by now, having all of the artwork finished is a huge step forward.

This has been your not-regularly-scheduled break in silence. Back to work.

Sunday, January 8, 2017

Jan 8 2017 - Displaying images sanely

I think one of the most difficult challenges I face with not having a strong programming background is not knowing exactly how syntax is set up for different languages.

Case in point: Renpy. You would think flipping an image is a simple thing. Spoiler alert: It is. But figuring out how the heck the engine expects you to do it with the spaghetti documentation that exists is kind of a nightmare in my experience.

I have a picture, and I want to be able to display it facing left or right. This isn't a difficult thing to ask. But there are a lot of ways to do this, some of which are more trouble than others. It's possible to declare the image transforms upon initialization, but when you could potentially be flipping thousands of images, you need a much better solution. Same with exporting duplicates of every image that could be flipped and hoping you remember the naming conventions.

It's a nightmare, and while it might work for a one-off instance, it DOESN'T work for my project at all (or most projects, I'd wager).

Fortunately, there's a much easier solution, one that isn't covered in ANY of the documentation at all.

I present to you the xzoom command.

    scene black
    "This here is just a test scene meant to play around."
    "We're going to play around with some images right now."
    show tzania happy at right:
          xzoom -1.0

 The gist here is pretty simple: By declaring a show command with a colon, you can apply transformations such as scale, zoom, rotate, whatever. It does NOT work like the following:

                 show tzania happy at right with xflip
Despite the fact that the documentation seems to indicate this should work. (It doesn't because it has no idea what xflip is. Or xzoom. Or a lot of other things for that matter.)

So lessons learned once again, and if you ever need to flip an image in renpy quickly, this is how you do it. (You can also use yzoom -1.0, that works just as well but with the other axis.)

I'm sure I'll figure out other ways I can use this to my advantage in the future.

Tuesday, December 13, 2016

Dec 13 2016 Devlog: Cracking the code

Tonight I'm going back to the usual tone I've set lately, and delve into some of the programming issues I've been wrestling with. It comes with a surprising revelation: I'm actually sort of okay at this thing it seems.

I still feel like a hack when assembling things, but tonight was one of those nights where I made a plan, followed it through, then came up with a better way to do it immediately after. So I'm going to be talking about that.

Monday, December 12, 2016

How do you make a game?

Today I'm going to take a break from what I've been writing about lately to talk about new lessons I've learned as an indie game developer (and why it feels weird to call myself that). While I won't be talking about programming issues (at least not directly), I'm going to instead discuss some of the other lessons I've learned the last couple of months.

So hopefully someone out there finds this useful. I need a break from the usual thing anyways.

Monday, November 28, 2016

Ren'Py, the DSE, and How Events Work

So, I have mentioned in the past that programming is hard.

What a surprise, right?

Well, today's bit of weirdness comes from the way the DSE framework in Ren'Py handles events, the way it processes those events, and the way that it determines when to execute an event.

So here was my issue: When setting up the core events for my game, I came across a truly strange interaction where the game began to execute a specific event, despite the fact that it was in neither the correct location, nor the correct time, or even the correct day within the game.

My first instinct was that maybe it was a typo. I was visiting the laboratory, but for some reason one of the character's generic events was playing out that occurred in the library! So maybe I'd just made a spelling error in the event.

Turns out it wasn't so simple. Or rather, it was simple, but not in the way I had expected.

After turning it over and over, I finally managed to hammer down what was going on, and in the process learned something about how it processes variables.

See, here's what the event code looked like:  

$ event("cyn_base_library", "act == 'library', tod == '3', dow == '3'", event.only(), priority=175)

$ event("cyn_base_library", "act == 'library', tod == '1', dow == '1'", event.only(), priority=175)

$ event("cyn_base_library", "act == 'library', tod == '1', dow == '7'", event.only(), priority=175)

$ event("cyn_base_garden", "act == 'garden', tod == '3', dow == '2', day >= '5', cyn_rel >= '1'", event.only(), priority=175)

$ event("cyn_base_garden", "act == 'garden', tod == '3', dow == '6', cyn_rel >= '1'", event.only(), priority=175)

$ event("cyn_base_lab", "act == 'laboratory', tod == '4', dow == '4', cyn_rel >= '1'", event.only(), priority=175)

Turns out, what I was doing was totally wrong, because none of those conditions was actually causing the event to play. What I should have typed was this:


$ event("cyn_base_library", "act == 'library' and tod == '3' and dow == '3'", event.only(), priority=175)
$ event("cyn_base_library", "act == 'library' and tod == '1' and dow == '1'", event.only(), priority=175)
$ event("cyn_base_library", "act == 'library' and tod == '1' and dow == '7'", event.only(), priority=175)
$ event("cyn_base_garden", "act == 'garden' and tod == '3' and dow == '2' and day >= '5' and cyn_rel >= '1'", event.only(), priority=175)
$ event("cyn_base_garden", "act == 'garden' and tod == '3' and dow == '6' and cyn_rel >= '1'", event.only(), priority=175)
$ event("cyn_base_lab", "act == 'laboratory' and tod == '4' and dow == '4' and cyn_rel >= '1'", event.only(), priority=175)

Instead of triggering the events when all of the conditions were met, it seemed more than happy to select the events based on their priority, totally ignoring the variable block.

All because I didn't use the word 'and' to separate my variables.

Hopefully someone finds this useful someday. In the meantime, it's back to the grind with me. There's so much work left to do, but this seemed like one of those major things that was really just a minor thing. Really though, I felt proud when I figured it out on my own, and without needing to consult the Internet for help.

**EDIT**

I AM AN IDIOT AND YOU SHOULD IGNORE THAT STUFF ABOVE BECAUSE IT'S STILL WRONG.

So after spending almost literally my entire night, here's the way the code blocks should really look:

    

$ event("cyn_base_library", "act == 'library'", event.only(), "tod == 3", "dow == 3", priority=175)
$ event("cyn_base_library", "act == 'library'", event.only(), "tod == 1", "dow == 1", priority=175)
$ event("cyn_base_library", "act == 'library'", event.only(), "tod == 1", "dow == 7", priority=175)
$ event("cyn_base_garden", "act == 'garden'", event.only(), "tod == 3", "dow == 2", "day >= 5", "cyn_rel >= 1", priority=175)
$ event("cyn_base_garden", "act == 'garden'", event.only(), "tod == 3", "dow == 6", "cyn_rel >= 1", priority=175)
$ event("cyn_base_lab", "act == 'laboratory'", event.only(), "tod == 4", "dow == 4", "cyn_rel >= 1", priority=175)

You will note that the variables have been moved outside of the second block. It's because the 'and' statement may or may not work. But it probably won't, so don't use it in that context.

LESSONS CONTINUE TO BE LEARNED!

Wednesday, June 29, 2016

Programming is Hard

Been awhile since I updated. There's a reason for that: My actual job has been keeping me busy. And by busy I mean working the crap out of me. I've been putting in overtime hours for the last few months.

I've kept plugging away at this programming thing, and understanding how DSE works. The original intention was to use this as a precursor for a gamedev blog - so people could get updates on progress. This is difficult to do when the most I can do is poke at the coding for a couple hours at most, and compounded by my working every day of the week.

Still, not an insurmountable task. I've learned quite a lot about many things, a great many deal regarding the DSE (and just how friggin' powerful it can be!).

Speaking to others about my not-so-secret project, I describe myself as less a programmer and more of a hacker. I don't come up with a lot of code myself, mostly I appropriate from others until I get it to do what I want it to. This has mixed amounts of success, but I'm really proud of how far I've come these last few months.

When last I left off, I was dealing with syntax issues, and understanding why the code wasn't recognizing my Day variables. Given tonight's little project, I think this is a nice time to review.

So, anything that occurs during the init line is not set in stone - those are the default values set in when the game launches. Any variables changed during the course of the game should be saved as a state when Ren'Py saves the game - meaning even if Day = 0 on launching the game, it will still be Day 39 when you load your game (rigorous testing concluded this functioned properly).

After much hacking, I've accomplished not merely setting up additional time slots for events to occur, but I've also locked choices during specific days of the week, removed them from the planning menus, and also set aside an option for these things to be overridden should the need arise (say, a holiday for example). The scope of the game is pretty large, perhaps too large to be reasonably accomplished, but I'm not one to let something like that keep me from progressing.

Today's project (or the project I started a few days ago really) involved a very simple thing: How do we make sure that events play out only in a specific location, at a specific time? For reference, the events are structured like so:

    $ event("library", "act == 'library'", event.only(), priority=200)
    $ event("garden", "act == 'garden'", event.only(), priority=200)
    $ event("cemetery", "act == 'cemetery'", event.only(), priority=200)
    $ event("dojo", "act == 'dojo'", event.only(), priority=200)
    $ event("workshop", "act == 'workshop'", event.only(), priority=200)
    $ event("laboratory", "act == 'laboratory'", event.only(), priority=200)
    $ event("office", "act == 'office'", event.only(), priority=200)

These are some of the placeholders I'm using for now, but they illustrate what I'm working with. Let me break down the code for you: The first part of the string is the event that is occurring (so I have for example an event named 'office'). The second part, the 'act', tells us that this event plays out when the current act is the 'office' option from the planning menu. So when you go to the office, the office event plays out. The 'only' descriptor states that this is the only event that should play out, and any other possible options should be pushed aside regardless of whether they are eligible to play out. Lastly, we have the priority, which tells us how important this event is in relation to the others. In this case, all of my events here are set at a priority of 200, which isn't too terribly important since 100 is the recommended default.

So I set up some testing events to play out, to make sure they occurred properly.

    $ event("tzan_intro", "act == 'cemetery'", event.only(), event.once(), priority=190)
    $ event("tzan_ar01", "act == 'cemetery' and period == 'late_eve'", event.only(), event.once(), event.depends('tzan_intro'), priority=200)
Once again, let's  break down what's going here. You can see that the event "tzan_intro" has a higher priority (lower numbers are higher priority) than the normal cemetery event up above. We can also see here that it only plays once. This plays out any time you visit the cemetery, but only the first time.

It worked just fine. The second one though, that took a bit of doing. Because for some reason, it just would. Not. Trigger.

I spent the last few days pounding my head against the wall figuring out why. Was it not tracking the period name? Or was it not referring to the variable correctly? After much running in circles, I realized the error of my ways, and also learned about something very cool I could do.

The problem... was the priority of the second event. Because it is lower on the list than cemetery, which as I noted has an event.only tag, it was being disregarded every time. As soon as it was placed on a lower priority, like with the first event, it played out correctly the next time I visited the cemetery in the late evening.

This revelation however opened my mind to how powerful this events system can be. Because you see, I can have multiple events play out, in order, so long as they are not pushing one another out.

So for example, I can have the normal cemetery event play, where a player arrives at the location and gets a brief description, and then it can load the next event, where they meet a character.

Needless to say, this is a pretty powerful revelation to have, and I really look forward to the day when I can openly share more about what the game is intended to be. But for now, I have to keep playing with code until the framework is solid. And also cobble together some art assets.

But so far, I'm rather proud of the improvements I've made so far, and the amount I've learned about how DSE, and Ren'Py in general, work.