If statement if value is NOT in list [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
Exiscoming
Regular
Posts: 127
Joined: Tue Apr 29, 2014 5:37 pm
Contact:

If statement if value is NOT in list [SOLVED]

#1 Post by Exiscoming » Tue Jun 02, 2020 5:24 am

How do I run code if a value is not inside a list?
Example:

Code: Select all

default list = [1,2,3,4]

label start:
	$ list.remove(4)
	if list.index(4) == False:			# <- this doesn't work
		"Four is not in the list."
Last edited by Exiscoming on Tue Jun 02, 2020 12:46 pm, edited 2 times in total.

philat
Eileen-Class Veteran
Posts: 1853
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: If statement is value is NOT in list

#2 Post by philat » Tue Jun 02, 2020 5:25 am

Like... besides if 4 not in list? (Btw, don't call it list.)

Exiscoming
Regular
Posts: 127
Joined: Tue Apr 29, 2014 5:37 pm
Contact:

Re: If statement is value is NOT in list

#3 Post by Exiscoming » Tue Jun 02, 2020 5:43 am

What should I call it? I was gonna call it an array, but python uses lists instead.
Basically I need to see if a number is inside an array. If it's not, then have something happens.
If that number 'is' inside the array, something else happens.

philat
Eileen-Class Veteran
Posts: 1853
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: If statement is value is NOT in list

#4 Post by philat » Tue Jun 02, 2020 6:12 am

I meant don't call the variable list. list() is an internal function of python and it's best to avoid.

Also, I meant literally if 4 not in list.

Exiscoming
Regular
Posts: 127
Joined: Tue Apr 29, 2014 5:37 pm
Contact:

Re: If statement is value is NOT in list

#5 Post by Exiscoming » Tue Jun 02, 2020 6:40 am

Oh God, I'm stupid.

Code: Select all

if 4 not in list
Is code. haha, now I get it. Thank you!

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]