Arrays/Lists - How to add and change stored data (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
Llunet1
Regular
Posts: 55
Joined: Mon Oct 21, 2013 8:56 pm
Projects: Reminiscence, Blood
Deviantart: llunet1
Location: USA
Contact:

Arrays/Lists - How to add and change stored data (Solved)

#1 Post by Llunet1 »

I used to work with Java (for a bit, I'm not an advanced programmer or anything like that, but I do know quite a bit) and there was a "variable" of sorts called arrays. I know I can make them on ren'py, however I can't figure out how to change what is stored in the "compartments" or add new ones. I'm fine with not being able to add new sections (I can deal with that) however I need to be able to change what it stored.

If you know how, please tell me! I would love to be able to use this feature properly (because I have long lists of variables, and having it stored in one place would be much easier for me)!
If you know this cannot be done, also tell me.

Thank you!
-Llunet
Last edited by Llunet1 on Tue Jun 24, 2014 2:46 am, edited 1 time in total.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Arrays/Lists - How to add and change stored data (Unsolv

#2 Post by xela »

Like what we're doing? Support us at:
Image

User avatar
Llunet1
Regular
Posts: 55
Joined: Mon Oct 21, 2013 8:56 pm
Projects: Reminiscence, Blood
Deviantart: llunet1
Location: USA
Contact:

Re: Arrays/Lists - How to add and change stored data (Unsolv

#3 Post by Llunet1 »

That link is only for sorting data... (Unless I'm totally blind and missing something)
I want to be able to change what is written in my list.

Just like:

Code: Select all

$ x = "Something"
$ x = "Something Else"
I am able to change the variable later on... however I can't seem to be able to change for example...

Code: Select all

$ list = ["1", "2", "3"]
$ list[0] = "3"
Or something like that. (I thought it would be changed by doing that, which it didn't work.)

^^; However, thank you for replying.
Last edited by Llunet1 on Tue Jun 24, 2014 2:47 am, edited 1 time in total.

User avatar
Llunet1
Regular
Posts: 55
Joined: Mon Oct 21, 2013 8:56 pm
Projects: Reminiscence, Blood
Deviantart: llunet1
Location: USA
Contact:

Re: Arrays/Lists - How to add and change stored data (Unsolv

#4 Post by Llunet1 »

Wait. WHOOPS.
I realized my mistake in the code.

I put two equal signs instead of one. WOW.
It works now.
Sorry ^^;

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Arrays/Lists - How to add and change stored data (Unsolv

#5 Post by xela »

Glad you figured it out but if you ever get stuck again:

Code: Select all

>>> l = list()
>>> l.append(1)
>>> l.append(2)
>>> l
[1, 2]
>>> l[0] = 100
>>> l
[100, 2]
>>> for i, v in enumerate(l):
	if v == 2:
		l[i] = 200

		
>>> l
[100, 200]
>>> 
You can read everything about lists in Python documentation or tutorials.
Like what we're doing? Support us at:
Image

User avatar
netravelr
Miko-Class Veteran
Posts: 504
Joined: Thu Jan 28, 2010 2:31 am
Completed: Culina: Hands in the Kitchen, Culina: The Spirit of Cooking, Saving Zoey
Projects: Love at the Laundromat
Organization: Lakeview Interactive
Deviantart: netravelr
Location: USA
Contact:

Re: Arrays/Lists - How to add and change stored data (Unsolv

#6 Post by netravelr »

Glad to hear everything's better! If your problem is solved, I think it'd be a good idea to change the subject line. :-)
Image
Technical Designer/Programmer
Game Design Portfolio - Project updates on my Twitter
Experienced in: C/C++/C#, Python, Unreal, Unity, and Flash
_________________
"Space can be very lonely. The greatest adventure is having someone share it with you."

User avatar
Llunet1
Regular
Posts: 55
Joined: Mon Oct 21, 2013 8:56 pm
Projects: Reminiscence, Blood
Deviantart: llunet1
Location: USA
Contact:

Re: Arrays/Lists - How to add and change stored data (Unsolv

#7 Post by Llunet1 »

netravelr wrote:Glad to hear everything's better! If your problem is solved, I think it'd be a good idea to change the subject line. :-)
Yes, sorry. I forgot about that and just changed it now ^^;

Post Reply

Who is online

Users browsing this forum: Google [Bot]