First Dev thread - can't get a python function to call in Ren'py

Delambo

Member
Jan 10, 2018
107
92
So I'm a total noob to both Python and Ren'Py but I've got a grand idea and I love banging my head against walls so I'm going for it.

In the current section I have a list of 3 subjects, each with 6 brief lectures associated with them. and each lecture has two knowledge check questions. I'm trying to present two random lectures for each subject, then one of the possible four knowledge check questions. I've created a couple of dictionaries for the lectures and the knowledge checks, then created (that word in this situation is a bit strong) a function to call up the lectures and knowledge checks from them. I haven't been able to test the function yet, because of my syntax when trying to call it.

Function (inside a Python block)
Code:
    def present_teaching_moment(category):
        """
        Presents two randomly selected teachable moments from the given category
        and then presents a randomly selected knowledge check for one of them.
        
        Args:
            category: The name of the category.
        """
        
        import random

        # Select two random teachable moments from the category
        selected_moments = random.sample(list(teachable_moments[category].keys()), 2)

        # Present the selected teachable moments
        for moment in selected_moments:
            renpy.say(teachable_moments[category][moment])

        # Select a random teachable moment for the knowledge check
        selected_moment = random.choice(selected_moments)

        # Randomly select a question from the knowledge check
        selected_question = random.choice(list(knowledge_checks[category][selected_moment].keys()))
Ren'py scene
Code:
    label military_equipment_scene:
    $ current_category = "Equipment"  # Store the current category
    call present_teaching_moment(current_category) 
    jump military_strategy_scene  # Proceed to the next scene
I'm getting an error that "The call is to nonexistent label 'present_teaching_moment'." I'm sure this isn't the only error I will get, but I've managed to troubleshoot a lot on my own so far, just can't get around this or figure out how to get more detail on it. Any help hugely appreciated.
 

GetOutOfMyLab

Conversation Conqueror
Modder
Aug 13, 2021
7,823
21,835
That's not the appropriate use of call.

You can use your function like this: $ present_teaching_moment(current_category)
 
  • Heart
Reactions: Delambo

GamesMtP

Well-Known Member
Game Developer
Jul 2, 2017
1,315
3,535
I'm getting an error that "The call is to nonexistent label 'present_teaching_moment'." I'm sure this isn't the only error I will get, but I've managed to troubleshoot a lot on my own so far, just can't get around this or figure out how to get more detail on it. Any help hugely appreciated.
The main use for both jump and call is to go to a label. The difference is that jump is a oneway while call remembers where it came from and can go back there with the return command. If you call but don't return you'll build up a call stack. Try not to.
 
  • Like
Reactions: Delambo

osanaiko

Engaged Member
Modder
Jul 4, 2017
2,787
5,195
It can be tough coming to Renpy as an experienced Python dev... it looks so similar!

But you need to break out of thinking about it like a python project. Renpy Script is a different beast, and you need to learn it as a new language.
Yes, you can make python functions and classes and access them from the script. Yes, the internals are Python. But the game framework is not intended to be used in a way that has you messing around with the system at the pythonic level. There's average (at best) documentation about the internals, and unless you have a lot of skill/experience/patience/tolerance it remains better to avoid.

It's also important to understand that "renpy" actually has three independent domain specific languages that are all able to intermixed:
- Renpy script - specialised language originally created for making basic japanese VN style games, that has since expanded to make more complex games but still has limitations that prevent it from doing a good job at some game types
- Animation Transform Language - for manipulating images and making them into timelined animations that can be treated as single "displayable" objects in the rest of the codebase
- Screen Language - plays a role somewhat similar to CSS with regards to layout, but also has plumbing for UI event handling
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
11,423
17,386
Renpy Script is a different beast, and you need to learn it as a new language.
And for this, reading the doc, that come with the SDK, is an obvious mandatory starting point.