[Solved] Logic functions

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
Shiron
Newbie
Posts: 18
Joined: Fri Sep 28, 2018 8:10 am
Contact:

[Solved] Logic functions

#1 Post 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. :)
Last edited by Shiron on Fri Nov 23, 2018 9:38 pm, edited 1 time in total.

mikolajspy
Regular
Posts: 169
Joined: Sun Jun 04, 2017 12:05 pm
Completed: Too many, check signature
Deviantart: mikolajspy
Location: Wrocław, Poland
Contact:

Re: Logic functions

#2 Post 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 '=='.

User avatar
Chekhov
Regular
Posts: 113
Joined: Tue Jun 26, 2018 9:19 am
Projects: Pluton
Contact:

Re: Logic functions

#3 Post by Chekhov »

My current metod is written below, but I can't really use it for more complex functions:
More complex like what?

Shiron
Newbie
Posts: 18
Joined: Fri Sep 28, 2018 8:10 am
Contact:

Re: Logic functions

#4 Post 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. :/

Shiron
Newbie
Posts: 18
Joined: Fri Sep 28, 2018 8:10 am
Contact:

Re: Logic functions

#5 Post 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?

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: Logic functions

#6 Post 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
Frameworks & Scriptlets:

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: Logic functions

#7 Post 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.
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

Shiron
Newbie
Posts: 18
Joined: Fri Sep 28, 2018 8:10 am
Contact:

Re: Logic functions

#8 Post 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. :(

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: Logic functions

#9 Post 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.
Frameworks & Scriptlets:

Shiron
Newbie
Posts: 18
Joined: Fri Sep 28, 2018 8:10 am
Contact:

Re: Logic functions

#10 Post 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. :)

Post Reply

Who is online

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