Page 1 of 1
[Solved] Logic functions
Posted: Thu Nov 22, 2018 10:03 am
by Shiron
Hi, I've tried to find anything about it with google, but nothing relevant has showen up.
How can I do logic functions with renpy? Let's say I would want to write something like this:
Code: Select all
if (option1 OR option2 OR option3) == True:
jump LabelA
else:
jump LabelB
(option1, option2 and option3 are booleans, of course.)
Is it even possible?
My current metod is written below, but I can't really use it for more complex functions:
Code: Select all
if option1 == False:
if option2 == False:
if option3 == False:
jump LabelB
else:
jump LabelA
else:
jump LabelA
else:
jump LabelA
Thank you for the answer.

Re: Logic functions
Posted: Thu Nov 22, 2018 10:41 am
by mikolajspy
Code: Select all
if option1 or option2 or option 3:
#Do stuff
else:
#Do other stuff
Or in second example:
Code: Select all
if not option1 and not option2 and not option 3:
#Do stuff
else:
#Do other stuff
If you have boolean values, you don't have to specify their state by '=='.
Re: Logic functions
Posted: Thu Nov 22, 2018 12:26 pm
by Chekhov
My current metod is written below, but I can't really use it for more complex functions:
More complex like what?
Re: Logic functions
Posted: Thu Nov 22, 2018 4:45 pm
by Shiron
mikolajspy: Thank you, that worked.

By the way, both of my "examples" actually do the same. XD
Chekhov: I don't know, like
(not(A and notB)) and (not(B and notA)) or any logic function using even more booleans. You can't use them without brackets anymore. :/
Re: Logic functions
Posted: Fri Nov 23, 2018 7:35 am
by Shiron
I don't know if it is clear from the discussion, but this problem is still not solved yet.
Is there nobody who knows how to imput more complex logic functions into code?
Re: Logic functions
Posted: Fri Nov 23, 2018 12:46 pm
by Remix
The only valid answer is, Learn Python more...
We could teach you how to do "a number between 60 and 90 that is prime and not one higher than a multiple of three or a number between 90 and 100 not prime and not 92" except it simply would not teach you how to solve your own particular conditionals.
I'd suggest finding out about Python's any(), all(), map(), reduce() and filter() functions and maybe learn about tuple conditionals too
Code: Select all
if any( [
all( [ var1, var2, var3 ] ),
all( list(filter(lambda x: x < 0, reduce((lambda x, y: y-x), [1, 2, 3, 4]))) ) ] ):
# pass
Re: Logic functions
Posted: Fri Nov 23, 2018 3:09 pm
by trooper6
Also can you give a real use example of the most complicated thing you would need to do? Not using variables that don’t make sense like a, b, notA, and notB, but put the example in an actual example that you’d really use in your VN.
I find just taking through the logic step by step makes it obvious how to put it together. But if you give us an actual example—and what you are trying to accomplish with it—maybe we can teach you logic.
Though I do also recommend taking a tutorial in Python. Codeacademy.com has a good one.
Re: Logic functions
Posted: Fri Nov 23, 2018 5:08 pm
by Shiron
Thank you for the answers!
It's definitely true that I'm just beginner with Python and I need to learn it more, but I just had no idea where to find what I'm currently interested in. That's why I've asked here.
I'm going to read more about that
any(),
all(),
map(),
reduce() and
filter() functions, but from the quick glimpse they seem very handy to me. Thank you again.
----
Thing is that I have moved to Ren'Py from my old engine that had stopped developing in 2012. It hasn't even support more than 256 colors, heh.
But I was on an expert level there. It means that I have a very clear idea what game I want to make and what variables and functions I'll need.
Unfortunately, Ren'Py is way too different, so currently I'm writing a long part of code expecting that I'll figure it out eventually... And noticing that the basic of the basics – logic functions – isn't directly here kind of scares me. What else is not there? Original functions? Procedures?
I guess there is always a way around, but my current code is already quite messy.

Re: Logic functions
Posted: Fri Nov 23, 2018 9:28 pm
by Remix
I hope my reply didn't come across too harshly, mostly it comes down to the old programming idiom that there is not just one correct answer because there are multiple ways to do the same thing within a language. Even amongst those correct answer there is often not just one best answer.
On a plus, as no doubt you have gathered, Ren'Py is built on Python (version 2.7 to be exact) and that language is widespread enough and versatile enough to be worth learning anyway.
Re: Logic functions
Posted: Fri Nov 23, 2018 9:36 pm
by Shiron
Nah, I just find out that I actually CAN use brackets in statements, if I omit to specify their state by '=='. (It's basicaly a form of method mikolajspy mentioned.)
I don't even know why I thought I can't... Whatever, thanks for help, everyone.
