How to read strings from array [SOLVED]

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
User avatar
Mangescom
Newbie
Posts: 16
Joined: Sat Jul 04, 2015 1:45 pm
Deviantart: Mangescom
Contact:

How to read strings from array [SOLVED]

#1 Post by Mangescom »

Hey there

I have a array of strings

Code: Select all

$notes[]
Strings get filled into that array based on user choices.

Code: Select all

$notes.append("While talking to Person A I found out that XYZ")
No I want to read out all notes:

Code: Select all

label notes:
	foreach note in notes:
		*Read out the note*
I do have some coding background but not with python. I know there is no foreach only a for, but I am stuck. This is probably a beginner question but I couldn't manage to find anything in the cookbook forum (maybe I just don't know what to look for)

Thanks in advance
Last edited by Mangescom on Mon Oct 16, 2017 7:14 am, edited 2 times in total.

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: How to read strings from array

#2 Post by Remix »

just

Code: Select all

for note in notes:
    "[note]"
Frameworks & Scriptlets:

User avatar
Mangescom
Newbie
Posts: 16
Joined: Sat Jul 04, 2015 1:45 pm
Deviantart: Mangescom
Contact:

Re: How to read strings from array

#3 Post by Mangescom »

Code: Select all

$notes.append("Test")
python:
    for note in notes:
         "[note]"
Doesn't return anything. Any ideas on that?

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: How to read strings from array

#4 Post by Remix »

Code: Select all

default notes = []

init python:
    notes.append("test")

label start:
    for note in notes:
        "[note]"
Frameworks & Scriptlets:

User avatar
Mangescom
Newbie
Posts: 16
Joined: Sat Jul 04, 2015 1:45 pm
Deviantart: Mangescom
Contact:

Re: How to read strings from array

#5 Post by Mangescom »

I am honestly sorry but I can't get this to work. I started a new project to eliminate the rest of the script as error:
Whenever I use "for note in notes" it tells me

Code: Select all

File "game/script.rpy", line 16: expected statement.
    for note in notes:
Ren'Py Version: Ren'Py 6.99.12.4.2187
When I let it run under init python: it says "name 'notes' is not defined" after programm crashes.

I know how many entries there will be at any given point so I can use "[notes[0]]" to give out a specific entry. however it is just a workaround, not a solution.
My solution for now looks like this:

Code: Select all

	$ notes = ["","","","","",""]
	$ notes[0] = "test"
   	"[notes[0]]"
    	"[notes[1]]"
    	"[notes[2]]"
    	"[notes[3]]"
    	"[notes[4]]"
    	"[notes[5]]"
	

User avatar
Divona
Miko-Class Veteran
Posts: 678
Joined: Sun Jun 05, 2016 8:29 pm
Completed: The Falconers: Moonlight
Organization: Bionic Penguin
itch: bionicpenguin
Contact:

Re: How to read strings from array [kinda SOLVED]

#6 Post by Divona »

Code: Select all

define notes = []

init python:
    notes.append("test")

label start:

    python:
        for note in notes:
            renpy.say(None, "[note]")
Completed:
Image

User avatar
Mangescom
Newbie
Posts: 16
Joined: Sat Jul 04, 2015 1:45 pm
Deviantart: Mangescom
Contact:

Re: How to read strings from array [kinda SOLVED]

#7 Post by Mangescom »

Thank you both very much, that finally worked. :D

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: How to read strings from array [SOLVED]

#8 Post by trooper6 »

Just for some more detail, Ren’Py doesn’t have for loops in the main body. You can do for loops on screens, but not in the regular script. Ren’Py does do while loops, however.

So you can use a while loop, or you can put everything in a Python block and use for that way. But if you are in the python block you have to use Python equivalent statements for things like say, show, etc.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

Post Reply

Who is online

Users browsing this forum: Andredron