Rhapsy wrote: ↑Sat Mar 09, 2024 12:46 pm
It only confuses me in the part to add new text that works as another description or section for events in the character list.
I need this new text to change its content on each page like "desc".
To indicate if the player has a task to do with a character or if they no longer have events with other characters. For example
There is a good learning help for Ren'Py in its own Ren'Py Tutorial.
Run Ren'Py 8 SDK Launcher and select "Tutorial" project to run.
Another is documentation
https://renpy.org/doc/html/
See "Quickstart", and you can search too, for any Ren'Py elements you have questions about.
In case of those texts (and any other information), it's like in all programming languages.
You can keep any info you need.
The information that can change is kept in variables.
(You can also hear funny expressions like "constant variable", but that's just a variable which content doesn't change).
So that's the miracle of programming: just create a variable - which has its name and its content - and you can use it at your service.
In the case of "quest" text for every character, you keep those texts in variables, and you could do that with different approaches.
One approach is to have a separate dict of those texts:
Code: Select all
default quests = {
"cat": "Feed the cat.",
"dog": "Walk the dog.",
"bug": "Squash the bug.",
}
This means we create a variable named "quests". It is of type "dict", which means it contains pairs of
key: value, like dictionaries have article heading and article content.
Addressing elements of dict, we use keys:
Code: Select all
$ quests["cat"] = "Wash the cat."
This means we address dict `quests` with the key "cat" and assigned it a new value.
Now instead of "Feed the cat." it's "Wash the cat.".
Next time when we read
quests["cat"], we'll get "Wash the cat.".
Therefore it's easy to show a list of quests like this:
Code: Select all
screen quests():
vbox:
for q in quests:
text quests[q]
That code means "make a screen with vertical box (i.e. column) and show there every element of `quests` as a text.
Construction
for q in quests, applied to a dict, means "loop through every key of this dict, assigning this key to a temporary variable". In this case this variable is named
q.
Hence in this loop,
q first time is "cat", next time it's "dog", and so on until all dict elements are passed.
In practice, Python programmers often use a bit different construction:
Code: Select all
for key, val in quests.items():
text "[val]"
dict.items() means "transform the dict into a list of pairs of that dict's keys and values".
Therefore
for key, val in quests.items(): means "iterate through `quests`, taking pairs of
key, value".
This method is kinda convenient that instead of
quests[key] you can use just
val.
Back to your question:
If you need those "quest texts" in the character screen, you can put this somewhere in the screen:
Because
char[ID] is the identifier of the current character ("cat" or "dog" etc.),
quests[char[ID]] will be the current quest text for that character.
Then the char_list screen can look like this:
Code: Select all
screen char_list(char_n=0):
$ char = characters[char_n]
frame:
background "screens/screenlist_bg.png"
xfill True
yfill True
add f"screens/{char[ID]}.png" pos (806,200) #Custom name titles
add f"screens/photo/{char[ID]}.png" pos (0,0) #Character photo
frame:
pos (806, 300)
xysize (1000, 400)
background None
text quests[char[ID]]:
xalign 0.5
text_align 0.5
meaning that the area for quest text would be at position (806, 300) and of size 1000x400.
Or, if you want to put that text with the screen width, at maybe y=800,
Code: Select all
screen char_list(char_n=0):
$ char = characters[char_n]
frame:
background "screens/screenlist_bg.png"
xfill True
yfill True
add f"screens/{char[ID]}.png" pos (806,200) #Custom name titles
add f"screens/photo/{char[ID]}.png" pos (0,0) #Character photo
text quests[char[ID]] ypos 800 xalign 0.5 text_align 0.5
Another way to keep the quest text for every character is to add a field to that character's dict:
Code: Select all
default characters = [
{ID: "cat", ...all those fields from before, "quest": "Feed the cat."},
{ID: "dog", ...all those fields from before, "quest": "Walk the dog."},
]
Then you access that quest text the same way as "desc", only instead of key "desc" use "quest".
I mean, it's your program, and you are free to organize your data in any manner: add key-values, remove, change etc.
But for the image to change on each page of the character list I had to keep the original code and create a "photo" subfolder in "screens" (In this case for the character photos) because it would get into errors with files from other images because they are both images.png.
Maybe there was another less complicated way to solve it.
Nobody is forcing you to keep pictures in "screen" subfolder. Keep them in "images" folder or create "chars" folder right in "game" folder, whatever.