Simple Choice logging system

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
abysswatcher
Regular
Posts: 42
Joined: Sun Apr 12, 2020 11:50 pm
Projects: To-Live:The Struggle
Organization: Youyu de Shijie(憂鬱的世界)
Github: LuYifeng112
itch: https://luyifeng.itc
Location: New Zealand
Contact:

Simple Choice logging system

#1 Post by abysswatcher »

[removed]
Last edited by abysswatcher on Wed Jul 01, 2020 8:02 am, edited 2 times in total.
The goal of the revolution is to achieve the people's rights, but during the course of the revolution, we must stress military power - and the two are mutually contradictory.
-Sun Yat-sen
"Become a Visual Novel writer they said, it will be fun" (little did they know they were right)

Human Bolt Diary
Regular
Posts: 111
Joined: Fri Oct 11, 2013 12:46 am
Contact:

Re: Simple Choice logging system (don't need to define 1000 variables)

#2 Post by Human Bolt Diary »

I would advise not to use this.

On a surface level, this implementation is just a wrapper over python's list. It does not add or modify any functionality, but anyone using it will be unable to benefit from all the python list tutorials available online. If you really want this sort of implementation, you can just use a list without the class on top.

On a deeper level, the bigger your list gets, the slower the lookup will be. Finding a value in a list is orders of magnitude slower than checking a variable. If you really want to create variables on the fly, use setattr().

There's also the inevitable typo bug to consider. Using this implementation or similar, a typo when checking if a string is in the list could easily go unnoticed without rigorous testing. Debugging it will be a huge pain. A typo in a variable will cause a crash, which is what you want.

strayerror
Regular
Posts: 159
Joined: Fri Jan 04, 2019 3:44 pm
Contact:

Re: Simple Choice logging system (don't need to define 1000 variables)

#3 Post by strayerror »

Unless I misunderstand, I think the problem being solved here is already supported by Ren'Py proper - check out the menu set functionality (link below). It's implementation (using a set rather than a list) also addresses some of the concerns raised by Human Bolt Diary.

https://www.renpy.org/doc/html/menus.html#menu-set

abysswatcher
Regular
Posts: 42
Joined: Sun Apr 12, 2020 11:50 pm
Projects: To-Live:The Struggle
Organization: Youyu de Shijie(憂鬱的世界)
Github: LuYifeng112
itch: https://luyifeng.itc
Location: New Zealand
Contact:

Re: Simple Choice logging system (don't need to define 1000 variables)

#4 Post by abysswatcher »

Human Bolt Diary wrote: Wed Jul 01, 2020 12:23 am I would advise not to use this.

On a surface level, this implementation is just a wrapper over python's list. It does not add or modify any functionality, but anyone using it will be unable to benefit from all the python list tutorials available online. If you really want this sort of implementation, you can just use a list without the class on top.

On a deeper level, the bigger your list gets, the slower the lookup will be. Finding a value in a list is orders of magnitude slower than checking a variable. If you really want to create variables on the fly, use setattr().

There's also the inevitable typo bug to consider. Using this implementation or similar, a typo when checking if a string is in the list could easily go unnoticed without rigorous testing. Debugging it will be a huge pain. A typo in a variable will cause a crash, which is what you want.
I wanted to see if there was a way to raise an error for this. This method is actually part of a custom character class which uses it for traits and special event logging I do realise that it can't be used for a lot of variables due to performance reasons.
The goal of the revolution is to achieve the people's rights, but during the course of the revolution, we must stress military power - and the two are mutually contradictory.
-Sun Yat-sen
"Become a Visual Novel writer they said, it will be fun" (little did they know they were right)

abysswatcher
Regular
Posts: 42
Joined: Sun Apr 12, 2020 11:50 pm
Projects: To-Live:The Struggle
Organization: Youyu de Shijie(憂鬱的世界)
Github: LuYifeng112
itch: https://luyifeng.itc
Location: New Zealand
Contact:

Re: Simple Choice logging system (don't need to define 1000 variables)

#5 Post by abysswatcher »

strayerror wrote: Wed Jul 01, 2020 4:43 am Unless I misunderstand, I think the problem being solved here is already supported by Ren'Py proper - check out the menu set functionality (link below). It's implementation (using a set rather than a list) also addresses some of the concerns raised by Human Bolt Diary.

https://www.renpy.org/doc/html/menus.html#menu-set
Care to elaborate on this? It doesn't explain much to me :(
How is this implemented and what does it do?
The goal of the revolution is to achieve the people's rights, but during the course of the revolution, we must stress military power - and the two are mutually contradictory.
-Sun Yat-sen
"Become a Visual Novel writer they said, it will be fun" (little did they know they were right)

Post Reply

Who is online

Users browsing this forum: No registered users