[SOLVED]What's the most efficient way to store variables?

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.
Message
Author
User avatar
m_from_space
Eileen-Class Veteran
Posts: 1057
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: What's the most efficient way to store variables?

#16 Post by m_from_space »

Adabelitoo wrote: Thu May 23, 2024 5:01 pm If I do this and later I ask if tea or coffee, then "likes_coffee" would be added to the list, right? It wouldn't replace "like_apples", did I get it right?
It's just an endless list of strings you add and that you then can check for when you need to. Nothing gets replaced. What I like about this method is that it's very easy to read when coding.

RewindTheGame
Regular
Posts: 80
Joined: Thu Dec 31, 2020 3:37 pm
Contact:

Re: What's the most efficient way to store variables?

#17 Post by RewindTheGame »

Ocelot wrote: Thu May 23, 2024 5:29 pm
RewindTheGame wrote: Thu May 23, 2024 2:07 pm This is why I've never understood why people choose to code in things like C which are almost impossible to understand without a degree in computer science and a manual the size of War and Peace, when there's no reason code written in any other simpler language couldn't compile down to exactly the same finished executable.
For some reason people don't like when their pacemaker skips a beat because Python decides to do a garbage collection.
Afraid that's far too deep for me. Are those two things connected?

jeffster
Miko-Class Veteran
Posts: 520
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: What's the most efficient way to store variables?

#18 Post by jeffster »

RewindTheGame wrote: Fri May 24, 2024 9:47 am
Ocelot wrote: Thu May 23, 2024 5:29 pm
RewindTheGame wrote: Thu May 23, 2024 2:07 pm This is why I've never understood why people choose to code in things like C which are almost impossible to understand without a degree in computer science and a manual the size of War and Peace, when there's no reason code written in any other simpler language couldn't compile down to exactly the same finished executable.
For some reason people don't like when their pacemaker skips a beat because Python decides to do a garbage collection.
Afraid that's far too deep for me. Are those two things connected?
I think Ocelot says that for some tasks (highly demanding for speed, reaction time & small memory footprint) we still need languages like C or assembler.

They are compiled to processor commands code, which runs at least 20 times faster than Python. Python runs through interpreter, i.e. its "translation for CPU" runs every time you run the program.

(That's a simplified explanation, as after the first run Python normally uses cache with already compiled bytecode, and for most purposes Python is better, due to faster and easier development; but still there are very technical areas like OS kernel etc., where it wouldn't work).
If the problem is solved, please edit the original post and add [SOLVED] to the title. 8)

RewindTheGame
Regular
Posts: 80
Joined: Thu Dec 31, 2020 3:37 pm
Contact:

Re: What's the most efficient way to store variables?

#19 Post by RewindTheGame »

jeffster wrote: Fri May 24, 2024 11:28 am
RewindTheGame wrote: Fri May 24, 2024 9:47 am
Ocelot wrote: Thu May 23, 2024 5:29 pm
For some reason people don't like when their pacemaker skips a beat because Python decides to do a garbage collection.
Afraid that's far too deep for me. Are those two things connected?
I think Ocelot says that for some tasks (highly demanding for speed, reaction time & small memory footprint) we still need languages like C or assembler.

They are compiled to processor commands code, which runs at least 20 times faster than Python. Python runs through interpreter, i.e. its "translation for CPU" runs every time you run the program.

(That's a simplified explanation, as after the first run Python normally uses cache with already compiled bytecode, and for most purposes Python is better, due to faster and easier development; but still there are very technical areas like OS kernel etc., where it wouldn't work).
Ah, I understand that. But what I'm saying is that a good language designer could make ANY language compile to exactly the same machine language. Somebody could, for example, write a version of BASIC which first converted the sourcecode into the equivalent C code and then compiled that. Since there's no connection between the finished .EXE and the human readable text format, it just seems strange to me that we live in a world with both simple and complex languages instead of just inventing one that everyone can code in.

By the way, the last time I actually wrote anything in Assembly Language was back in the 80s on a TI99/4A and I remember thoroughly enjoying it despite the complexity, so I'm not saying I don't enjoy learning new things. Heck, I've coded in everything from bloody LOGO to Clipper to Pascal to Forth in my time and I've enjoyed writing in them all. It just seems like language designers love to make things far more complex than anyone needs them to be.

jeffster
Miko-Class Veteran
Posts: 520
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: What's the most efficient way to store variables?

#20 Post by jeffster »

RewindTheGame wrote: Sat May 25, 2024 12:40 pm Ah, I understand that. But what I'm saying is that a good language designer could make ANY language compile to exactly the same machine language. Somebody could, for example, write a version of BASIC which first converted the sourcecode into the equivalent C code and then compiled that. Since there's no connection between the finished .EXE and the human readable text format, it just seems strange to me that we live in a world with both simple and complex languages instead of just inventing one that everyone can code in.

By the way, the last time I actually wrote anything in Assembly Language was back in the 80s on a TI99/4A and I remember thoroughly enjoying it despite the complexity, so I'm not saying I don't enjoy learning new things. Heck, I've coded in everything from bloody LOGO to Clipper to Pascal to Forth in my time and I've enjoyed writing in them all. It just seems like language designers love to make things far more complex than anyone needs them to be.
Assembler is not complex, it just requires more work. For me, it's often harder to read programs in "more advanced" Object C.

> a good language designer could make ANY language compile to exactly the same

Theoretically. But in practice compilers don't create perfectly optimized code. E.g. the fastest way to execute some algorithm would be to keep all values in CPU registers, but a C compiler typically puts those values in much slower RAM. (Well optimized assembler code can run about 10 times faster than the same program in C!)

Compilers just make assumptions (like "that value might be needed later"), so they use more memory etc. High level programming languages like Python hide even more details than C, and for the sake of convenience they use even more resources.

Theoretically, some day we might have super-optimized compilers which would let us program everything in simplest languages and achieve best theoretically possible performances. But for now life is imperfect, species die, air gets polluted and greedy politicians kill people.

So if even "sentient" humans aren't that sentient, what do you want from poor silicon bastards?
If the problem is solved, please edit the original post and add [SOLVED] to the title. 8)

Post Reply

Who is online

Users browsing this forum: DewyNebula