Arrays in Ren'Py

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
Mew151
Newbie
Posts: 10
Joined: Thu Jul 16, 2009 8:13 pm
Projects: Unbeatable Battles (Pre-production)
Contact:

Arrays in Ren'Py

#1 Post by Mew151 » Fri Jul 17, 2009 11:28 pm

Sorry if I sound like a newb, (because I am a newb to ren'py programming) but how do you make arrays in Ren'py?

I want to store information about things in an array, and, if I can (but it's not required) a multidimensional array.

Please assist; there was nothing I could find on the wiki. :|

User avatar
KimiYoriBaka
Miko-Class Veteran
Posts: 636
Joined: Thu May 14, 2009 8:15 pm
Projects: Castle of Arhannia
Contact:

Re: Arrays in Ren'Py

#2 Post by KimiYoriBaka » Sat Jul 18, 2009 1:19 am

Well, firstly you're looking in the wrong spot. Something like arrays isn't going to be part of ren'py's abilities, it would be in python (which is quite easily googled, but by far harder to read through documentation wise).

I don't know how you would use actual arrays, but you can use lists the same way. The main difference is that list don't have a set number of slots or a set type of elements. The downside however, is that they are kind of awkward if arrays are what you're used to.

Here's an example of what it would look like in ren'py:

Code: Select all

python:
   example_list = [0, 3, 2]
   example_list.append(5)
   example_list.append("string")
after this code example_list would be [0, 3, 2, 5, "string"]

For multidimensional arrays, you just add nested lists to the list like so:

Code: Select all

python:
   example_list = []
   example_list.append([2,3,4])
   example_list.append([0,1])
Here, the resulting list is [[2,3,4],[0,1]]

Then to access the elements of a list, use the name of the list followed by brackets telling which element you want (indexed starting at 0, just like arrays normally are). To access an element in a nested list, add another pair of brackets immediately after the first like so:

Code: Select all

example_list[1][2]
I hope that's easier to understand than whatever the documentation said...

chileanchimp
Newbie
Posts: 7
Joined: Fri Aug 06, 2010 5:02 pm
Contact:

Re: Arrays in Ren'Py

#3 Post by chileanchimp » Mon Apr 11, 2011 6:46 pm

and how i can eliminate one exact element? for example if i have ['1','3','2','5'] and i want to remove only '2'?

EDIT: so, i manage to find that answer in one of python tutorials.

if you have

$ places = ["house", "street", "university", "bar"]

and you want to remove one, just:

$ places.remove("street")

and it should be gone :D

Arpie
Newbie
Posts: 6
Joined: Sun Mar 27, 2011 7:58 pm
Contact:

Re: Arrays in Ren'Py

#4 Post by Arpie » Sun Sep 25, 2011 6:50 pm

This page explains a lot about lists:

http://effbot.org/zone/python-list.htm

It helped me!

User avatar
richycapy
Regular
Posts: 51
Joined: Mon May 27, 2019 8:53 pm
Organization: EN Productions
Location: Mexico
Contact:

Re: Arrays in Ren'Py

#5 Post by richycapy » Sun Oct 27, 2019 2:42 am

Hi,

Is there a way to count the number of elements inside an Array?

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: Arrays in Ren'Py

#6 Post by Per K Grok » Sun Oct 27, 2019 3:25 am

richycapy wrote:
Sun Oct 27, 2019 2:42 am
Hi,

Is there a way to count the number of elements inside an Array?
You can get the number of items in a list with len() in python
x=len(yourlist)

rayminator
Miko-Class Veteran
Posts: 754
Joined: Fri Feb 09, 2018 12:05 am
Location: Canada
Contact:

Re: Arrays in Ren'Py

#7 Post by rayminator » Sun Oct 27, 2019 3:45 pm

Array are for PHP and MySQL

Note: Python does not have built-in support for Arrays, but Python Lists can be used instead.

stated here
https://www.w3schools.com/python/python_arrays.asp

drKlauz
Veteran
Posts: 237
Joined: Mon Oct 12, 2015 3:04 pm
Contact:

Re: Arrays in Ren'Py

#8 Post by drKlauz » Sun Oct 27, 2019 6:00 pm

Not exactly true, there are bytearrays what can store bytes, and with ctypes/structure you can get proper arrays of pretty much any kind. Tho that would be un-pythonic :D
I may be available for hire, check my thread: viewtopic.php?f=66&t=51350

Post Reply

Who is online

Users browsing this forum: Bing [Bot]