Page 1 of 1

Can Python search all say statements between two labels?

Posted: Tue Nov 21, 2023 3:31 am
by Thailandian
I'm working on a scene viewer that would, among other things, be able to list scenes that contain a word or phrase.

The idea is that every scene would start with a label; then if I could use python to search for the term between that label and the next, if the term appears, python would return that label (and therefore scene) as one that the user might wish to view.

I have read about the Dialogue History system, and it looks like it may have potential, but as far as I understand, it seems to be limited by the config.history_length variable. Also, the HistoryEntry class does not have a label field.

Anyway, as always, any ideas or suggestions (including bad ones) are most welcome!

Re: Can Python search all say statements between two labels?

Posted: Tue Nov 21, 2023 8:22 am
by m_from_space
Probably not as easily. Because you're asking about something that a Renpy interpreter is doing when executing the code.

You could provide the user with a given set of keywords manually for each label on your side of course.

One thing that *might* work though is using a translation file (without translating it). So you could create a translation file for some dummy language, then use renpy.file() to open it while in your game - I don't know if you can - and then read through that file in search for keywords and extract the label it is referring to (the label name is always part of an entry).

I'm really not sure what your goal is here, but good luck. ;)

Re: Can Python search all say statements between two labels?

Posted: Wed Nov 22, 2023 1:32 pm
by Thailandian
Actually that's an interesting idea - also the "Extract Dialogue" function has quite a few options so perhaps the tab delimited spreadsheet may give me the data I need. In any case, I suspect preparing a separate file and loading it into a variable using renpy.file() may be the way to go.

To explain my goal, say for example in a crime mystery, the detective finds a bloody pair of scissors. The user recalls someone mentioning missing scissors from an earlier chapter, and wants to search the entire novel so far for any scene in which the word 'scissors' was mentioned. A search of the database would return every scene viewed so far that fits this criteria. The user could then view those scenes to see who said it, what was the context etc.

Anyway, my next step will be to look at the various Extract Dialogue outputs and investigate renpy.file().