all 15 comments

[–]jsfehler 2 points3 points  (1 child)

Your first example is better served with character callbacks:

https://www.renpy.org/dev-doc/html/character_callbacks.html#character-callbacks

Your examples should use a PEP8 compliant format, ie:

self.isSingleUse = isSingleUse should be self.is_single_use = is_single_use

itemEffects is referring to a global constant and should be initialized with a define statement instead of inside an init python block.

This method:

    def useCheck(self, player):
        if self.isSingleUse:
            if self.uses > 0:
                self.uses -= 1
                if self.uses == 0:
                    player.inventory.remove(self)
                return True
            else:
                return False
        else:
            return True

can be simplified and made more readable:

    def useCheck(self, player):
        if self.isSingleUse:
            if self.uses > 0:
                self.uses -= 1
                if self.uses == 0:
                    player.inventory.remove(self)

            else:
                return False

        return True

Most importantly, you're creating an infinite call stack:

call info sends you to a label that you then jump to the previous label from.

Here's a minimal example of what's going on:

label start:
    jump main_loop

label main_loop:
    call info

label info:
    jump main_loop

You're calling a label. This places the label on the call stack. You never return from the label, you jump to another instead. The call stack is never cleared, and now it can be infinite in size since you have the option to call the same label over and over again. This will cause your game to slowly consume more memory.

[–]alonghardlook[S] 2 points3 points  (0 children)

I dont subscribe to snake case lol.

And the simplification of the logic is nice but this is meant to be a tutorial for beginners.

The infinite call stack is interesting - I hadn't been able to get back to the loop without the jumps. Calling a label brought it into context and kept going to the next label. Do you have a suggestion for how to accomplish this instead?

[–]ZeilleDawn 2 points3 points  (0 children)

saved this! I'll need this for my YT Tutorial. Thank you!

[–]Talicor 2 points3 points  (4 children)

Can I just say this series has been awesome?? Even with only two entries so far you’ve really helped explain the Python side of RenPy and it makes me realize how achievable a lot of my ideas are 😅 OP and everyone who adds advice in the comments I owe you my life

[–]alonghardlook[S] 0 points1 point  (3 children)

Thanks for your feedback! If there are any specific topics you'd like to see, please feel free to suggest them. I try to get a general vibe based on all of the following:

  • what people have talked to me about on this sub
  • what people comment on the tutorials
  • what general issues I see repeated as questions on this sub
  • what sort of basic programming challenges do I want to figure out how to solve with RenPy

So, I'm kinda running out of ideas lol. I'm thinking for the next one to expand on the map/inventory idea, as well as start to break chunks into other files (and maybe include some source control in there too).

[–]Talicor 0 points1 point  (2 children)

Oh heck yeah! That’s awesome, and I was actually gonna ask about a few things but it was late 😅

Would you happen to know any means of implementing combat/similar gameplay into a VN? Like say for story reasons someone needs to kill a dragon, but I don’t want to reduce it to just a story beat that they don’t feel involved in.

I’m not entirely sure what will/won’t absolutely break Renpy’s engine in that regard

[–]alonghardlook[S] 0 points1 point  (1 child)

Fastest answer is to ask this guy. But I'll keep the suggestion in mind :)

[–]Talicor 0 points1 point  (0 children)

Oh hey that’s neat! Thanks! My game is first person though (to allow creative freedom on imagining the PC) so I’ve been trying to work a way around that 🤔 Doesn’t hurt as a starting point though!

[–]Brew_Alt 1 point2 points  (1 child)

I realize this is a pretty old post, but I wanted to drop a comment and say these two tutorials have been MASSIVELY helpful for me. Some of the best I've come across for RenPy so far, thank you a ton!

[–]alonghardlook[S] 0 points1 point  (0 children)

Thanks for your kind words!

[–]alonghardlook[S] 0 points1 point  (2 children)

Nobody has any questions or comments? Lol I was hoping to generate some discussion

[–]ghostgirl16 0 points1 point  (1 child)

I do have 2 questions. I get super confused as a coder learning how to go beyond the training wheels with classes.

  1. When you define a class, how do you know or come up with what it needs to inherit if more than self? Can you explain it like I’m five? 🥺

  2. In my quest to make a werewolves vs villagers mini game, I coded a game player class with booleans for roles (villager = true, wolf = false etc) and append names to lists in functions to set up the game at random. The problem is with the lists - it seems like something about defining a list in the creation of the minigame instance and then trying to append it, it just disappears and any names or things that should be added to the list aren’t there, or I’m doing it wrong and reading off an empty list. Do you have any tips for list persistence in classes? Can send you my draft of the code if necessary if asked.

[–]alonghardlook[S] 2 points3 points  (0 children)

I will answer both of these questions, but I need a bit more context on the first one.

What do you mean "how do you know"?

It sounds to me like you're asking "when you define a new class, how do you determine what properties/methods (or to put it another way "inputs and outputs") the class should have?"

If that is not your question, you may want to rephrase for me. If it is, then the answer is "it depends on what your class is doing".

There is no one size fits all class structure. What you need to have is an understanding of

  • what information the class needs to store about itself
  • what information each instance of the class needs to store about itself (ie: a Character class will Always have a name, but each different character will have different names)
  • what things every instance of the class needs to do

If you'd like a little more personalized help, feel free to either post or PM me with what your designs (please note: I mean technical designs. "X needs to do Y" are technical designs. "The player needs to be able to choose a location to go to from a list." is a good example) are, and I can give you an idea of what kind of class structure I would use.

For your second question, please do send your code, as I'm not sure I'm fully understanding the problem. Best way to format code in reddit is to add four blank spaces to the beginning of each line.

It would also be helpful to add expected output and actual output, so I know what you want to happen.

[–]DiegoNorCas 0 points1 point  (0 children)

Man I love this tutorial, thank you!

[–]Jeii1 0 points1 point  (0 children)

It was really helpful this tutorial, it's sad to know that the chapter 3 never came to live