[String interpolation]Inconsistent behavior?

In this forum we discuss the future of Ren'Py, both bug fixes and longer-term development. Pre-releases are announced and discussed here.
Post Reply
Message
Author
Martin
Newbie
Posts: 9
Joined: Sat Apr 13, 2024 12:50 pm
Contact:

[String interpolation]Inconsistent behavior?

#1 Post by Martin »

I'm loosing my sanity trying to understand this one! :)
I create a small script as below (complete script attached):

***********************
define Values_used = ["aaaa", "bbbb", "cccc", "dddd"] # inserted line
define Values_idx = [0, 5, 10, 20] # inserted line

# The game starts here.

label start:

$ idx = 10 # inserted line
$ idx1 = 2 # inserted line
"[Values_idx[idx1]]" # inserted line
"[Values_used[Values_idx.index(idx)]]" # inserted line
**********************
Runs perfectly fine (at least with Renpy 8.3.7)

but if I insert the 6 relevant lines in the very beginning (just after start label) of an existing (heavy) script (which runs perfectly fine without modification) I get this exception...

"TypeError: list indices must be integers or slices, not str"
Renpy exception 1.jpg
Exception 1/2
(219.1 KiB) Not downloaded yet
Renpy exception 2.jpg
Exception 2/2
(64.59 KiB) Not downloaded yet
Someone has an idea?
Please share it! :)

Thanks
script.rpy
full working script
(695 Bytes) Downloaded 1823 times

User avatar
enaielei
Miko-Class Veteran
Posts: 548
Joined: Fri Sep 17, 2021 2:09 am
Organization: enaielei
Tumblr: enaielei
Deviantart: enaielei
Github: enaielei
Skype: enaielei
Soundcloud: enaielei
itch: enaielei
Discord: enaielei#7487
Contact:

Re: [String interpolation]Inconsistent behavior?

#2 Post by enaielei »

Your idx1 value seems to be a string and not an integer as required for a list. E.g., you typed idx1 = "1" instead of idx1 = 1
You can check your idx1 value through the console just before you hit that statement/error. shift + o and type idx1.

Additionally, I think this kind of post belongs here: viewforum.php?f=8
See this for more details, if you're new: viewtopic.php?t=22090
Please consider supporting me if you like what I do :D
https://paypal.me/enaielei?country.x=PH&locale.x=en_US

Martin
Newbie
Posts: 9
Joined: Sat Apr 13, 2024 12:50 pm
Contact:

Re: [String interpolation]Inconsistent behavior?

#3 Post by Martin »

Thanks for the suggestion, but.... it's not that...
Example works (and $idx1 = 2 assign an int to idx1)
Real question is : why something working when alone doesn't work anymore (at run time) when put in a larger file...

User avatar
enaielei
Miko-Class Veteran
Posts: 548
Joined: Fri Sep 17, 2021 2:09 am
Organization: enaielei
Tumblr: enaielei
Deviantart: enaielei
Github: enaielei
Skype: enaielei
Soundcloud: enaielei
itch: enaielei
Discord: enaielei#7487
Contact:

Re: [String interpolation]Inconsistent behavior?

#4 Post by enaielei »

And how are you integrating this into that large file? I missed and just saw your script.rpy, and it works for me.
You really need to check that idx1 value so you can see what's being assigned to it.
If not before, click the Console when you see the error screen and check the value there.

Example reproduction below:
Screenshot 2025-04-26 140919.png
Screenshot 2025-04-26 140919.png (24.52 KiB) Viewed 4508 times
Screenshot 2025-04-26 141049.png
Screenshot 2025-04-26 141049.png (25.83 KiB) Viewed 4507 times
Attachments
Screenshot 2025-04-26 140840.png
(151.46 KiB) Not downloaded yet
Please consider supporting me if you like what I do :D
https://paypal.me/enaielei?country.x=PH&locale.x=en_US

Martin
Newbie
Posts: 9
Joined: Sat Apr 13, 2024 12:50 pm
Contact:

Re: [String interpolation]Inconsistent behavior?

#5 Post by Martin »

Integration in large file is just cut and paste...
To reassure you, if I add "[idx1]" in large file just after $ idx1 = 2 it correctly displays 2 before crashing on next line...

What could make this work one time (small file) and fail another time (large file)?
Anybody could try to add those 6 lines to a working large script... I would be interested to try zeroing large script conditions which gave an error...

User avatar
enaielei
Miko-Class Veteran
Posts: 548
Joined: Fri Sep 17, 2021 2:09 am
Organization: enaielei
Tumblr: enaielei
Deviantart: enaielei
Github: enaielei
Skype: enaielei
Soundcloud: enaielei
itch: enaielei
Discord: enaielei#7487
Contact:

Re: [String interpolation]Inconsistent behavior?

#6 Post by enaielei »

I'm feeling that you're not entirely sharing what's in your actual code. I'm just giving guidance based on the error that you shared.
FYI, idx1 = "2" and idx1 = 2 would appear the same when displayed as "[idx1]". You'll not get the difference, unlike in the console, where it shows you single quotes to say that it's a string value.
Please consider supporting me if you like what I do :D
https://paypal.me/enaielei?country.x=PH&locale.x=en_US

Martin
Newbie
Posts: 9
Joined: Sat Apr 13, 2024 12:50 pm
Contact:

Re: [String interpolation]Inconsistent behavior?

#7 Post by Martin »

Same code, not retyping it but pasting it...
Small script -> works
Large script -> fails
If I had made the "2" beginner's mistake you suggest it wouldn't work in small file...

What can I add?
Just try it yourself :)

User avatar
enaielei
Miko-Class Veteran
Posts: 548
Joined: Fri Sep 17, 2021 2:09 am
Organization: enaielei
Tumblr: enaielei
Deviantart: enaielei
Github: enaielei
Skype: enaielei
Soundcloud: enaielei
itch: enaielei
Discord: enaielei#7487
Contact:

Re: [String interpolation]Inconsistent behavior?

#8 Post by enaielei »

I already provided what I can on this topic. It's entirely up to you whether you'll do it or not.
Please consider supporting me if you like what I do :D
https://paypal.me/enaielei?country.x=PH&locale.x=en_US

Martin
Newbie
Posts: 9
Joined: Sat Apr 13, 2024 12:50 pm
Contact:

Re: [Solved][String interpolation]Inconsistent behavior?

#9 Post by Martin »

I finally got it!
Difference of behavior is related to file script_version.txt in the game directory.
I imagine that renpy uses this file to 'downgrade' its behavior when using a higher version that these found in this file.
Deleting this file has solved my problem.

Useful to know that it could affect the way a newer engine is used...

Martin
Newbie
Posts: 9
Joined: Sat Apr 13, 2024 12:50 pm
Contact:

[Solved][String interpolation]Inconsistent behavior?

#10 Post by Martin »

Sorry but can't find how to change the title of this topic...Could someone knowing how to pm me?

Post Reply