[Solved] Dynamically created dictionary at runtime, but afterwards, its data will never change. Define or Default?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
henvu50
Veteran
Posts: 337
Joined: Wed Aug 22, 2018 1:22 am
Contact:

[Solved] Dynamically created dictionary at runtime, but afterwards, its data will never change. Define or Default?

#1 Post by henvu50 »

I have to dynamically create a dictionary at runtime, but afterwards, its data will never change. I'm wondering if I should use default or define?

Code: Select all

define someDict = { } 
label start:
    call functionFillDictionaryWithEntriesThatWillNeverChange(someDict)
https://www.renpy.org/doc/html/python.h ... -statement
Variables that are defined using the define statement are treated as constant, are not saved or loaded

So if a user saves their game and reloads, someDict will be empty, because it was set to define? I'm thinking I should set it to default then, that setting it to default is the correct approach, is this right?

(In case anyone is wondering why I don't fill the dictionary before the game runs, I want to avoid typing out all the dictionary data by hand, because that's prone to errors, but if I dynamically generate it, I know it will be perfect every time.)
Last edited by henvu50 on Wed Jun 16, 2021 4:21 pm, edited 1 time in total.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2400
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Dynamically created dictionary at runtime, but afterwards, its data will never change. Define or Default?

#2 Post by Ocelot »

And why wouldn'y you fill it at init time? Seems like a best approach?
define someDict = functionFillAndReturnDictionaryWithEntriesThatWillNeverChange()
< < insert Rick Cook quote here > >

Post Reply

Who is online

Users browsing this forum: Bing [Bot]