[SOLVED] how to define the hierarchy of variables

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
deltadidirac
Regular
Posts: 123
Joined: Fri Nov 30, 2018 5:00 am
Projects: Artworks and Comics
Tumblr: deltadidirac
Deviantart: Deltadidirac67
Location: Europe
Contact:

[SOLVED] how to define the hierarchy of variables

#1 Post by deltadidirac » Fri Nov 29, 2019 8:43 am

hi all

I would like to know if it is possible define a hierarchy of some variables.

example:
if i have this 4 variables

Code: Select all

default lval = 0
default kval = 0 
default dval = 0
default mval = 0
can I define this way?

Code: Select all

define mval >lval>kval>dval
(for sure it will be wrote in a different way) but the sense is that when I use the if statment and I have same values or possible chooses, renpy can decide by itself at witch variable give the priority and consequently jump to the related lable.
Perhaps is not so simple and must I create a personal function?

thanks to all
Last edited by deltadidirac on Sat Nov 30, 2019 8:41 am, edited 1 time in total.

User avatar
gas
Miko-Class Veteran
Posts: 838
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: how to define the hierarchy of variables

#2 Post by gas » Sat Nov 30, 2019 12:58 am

Mmmh... you mean, renpy should check the first variable. If the higher one, do something. If not, check the second vs third, then third vs fourth...
First thing: using default types such way make the job hellish, that's the main reason objects are there.
There's nothing like your suggested hierarchy in Python, so you should make progressive conditionals. If there's just one case, you can hardcode it (and if that similar check repeat, call/ return a label or use a function).
One idea could be use a list instead of single variables, but you should memorize their meaning by index position (like mylist[0] is always the first variable).
This horrible solution let you use python advanced sorting modules, hopefully you'll understand a single word of it.
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

User avatar
deltadidirac
Regular
Posts: 123
Joined: Fri Nov 30, 2018 5:00 am
Projects: Artworks and Comics
Tumblr: deltadidirac
Deviantart: Deltadidirac67
Location: Europe
Contact:

Re: how to define the hierarchy of variables

#3 Post by deltadidirac » Sat Nov 30, 2019 4:28 am

gas wrote:
Sat Nov 30, 2019 12:58 am
Mmmh... you mean, renpy should check the first variable. If the higher one, do something. If not, check the second vs third, then third vs fourth...
First thing: using default types such way make the job hellish, that's the main reason objects are there.
There's nothing like your suggested hierarchy in Python, so you should make progressive conditionals. If there's just one case, you can hardcode it (and if that similar check repeat, call/ return a label or use a function).
One idea could be use a list instead of single variables, but you should memorize their meaning by index position (like mylist[0] is always the first variable).
This horrible solution let you use python advanced sorting modules, hopefully you'll understand a single word of it.
thanks for the suggest...

mhmmm.... as you wrote, what I'm searching to do in a simple way don't exist, and I'm not good to enter in a deep complex system code of phyton...
I must find a different solution so..

This problem born for the reason that I'm creating a repeatible activies in the same location... so in the kitchen you can find (during the same time), your mom that clean the dishes or anther character that is studing and so on...
this activities appear in the normal dayly routine of the family when no new scene or event are unblock...

The only easy solution that I'm seeing now is to define every routine scene with different hour and day to not create overlays, but this solution greatly limits the number of options I can create.

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: how to define the hierarchy of variables

#4 Post by Per K Grok » Sat Nov 30, 2019 7:25 am

deltadidirac wrote:
Sat Nov 30, 2019 4:28 am
what I'm searching to do in a simple way don't exist, and I'm not good to enter in a deep complex system code of phyton...
I must find a different solution so..

Could this work for you?

Code: Select all

init python:

    def pickChoice(a,b,c,d):
        if a>=b and a>=c and a>=d:
            return 1
        elif b>=a and b>=c and b>=d:
            return 2
        elif c>=a and c>=b and c>=d:
            return 3
        else:
            return 4



label start:

    if pickChoice(mval, lval, kval, dval)==1:
        "mval"
    elif pickChoice(mval, lval, kval, dval)==2:
        "lval"
    elif pickChoice(mval, lval, kval, dval)==3:
        "kval"
    else:
        "dval"


User avatar
deltadidirac
Regular
Posts: 123
Joined: Fri Nov 30, 2018 5:00 am
Projects: Artworks and Comics
Tumblr: deltadidirac
Deviantart: Deltadidirac67
Location: Europe
Contact:

Re: how to define the hierarchy of variables

#5 Post by deltadidirac » Sat Nov 30, 2019 7:45 am

Per K Grok wrote:
Sat Nov 30, 2019 7:25 am
deltadidirac wrote:
Sat Nov 30, 2019 4:28 am
what I'm searching to do in a simple way don't exist, and I'm not good to enter in a deep complex system code of phyton...
I must find a different solution so..

Could this work for you?

Code: Select all

init python:

    def pickChoice(a,b,c,d):
        if a>=b and a>=c and a>=d:
            return 1
        elif b>=a and b>=c and b>=d:
            return 2
        elif c>=a and c>=b and c>=d:
            return 3
        else:
            return 4



label start:

    if pickChoice(mval, lval, kval, dval)==1:
        "mval"
    elif pickChoice(mval, lval, kval, dval)==2:
        "lval"
    elif pickChoice(mval, lval, kval, dval)==3:
        "kval"
    else:
        "dval"

Mhmm... seems really simple, and I could use it for some situations....

one thing I didn't understand, the "return 1/2/3/4" at what referred are?
The variable value?

If yes this mean that your example is only the way to define the priority...
defined this, you build your label normally with the if stament, right?

I must test it a little...
Thanks anyway

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: how to define the hierarchy of variables

#6 Post by Per K Grok » Sat Nov 30, 2019 8:27 am

deltadidirac wrote:
Sat Nov 30, 2019 7:45 am


Mhmm... seems really simple, and I could use it for some situations....

one thing I didn't understand, the "return 1/2/3/4" at what referred are?
The variable value?

If yes this mean that your example is only the way to define the priority...
defined this, you build your label normally with the if stament, right?

I must test it a little...
Thanks anyway


pickChoice(a,b,c,d) is a function that takes four parameters, that should have numerical values, and compares them.

The function returns an answer that is 1, 2, 3 or 4. If the answer is 1 then the variable entered as the first parameter (a) has the highest value [or the highest value that also an other variable has] . If the answer is 2 then the same thing goes for the the second parameter, and so on.

The if/elif construction makes it so that at a tie 'a' will be chosen before 'b' and so on.



When you want to use the function you call it and have the program doing different things depending on what number the function returns.

Code: Select all

if pickChoice(mval, lval, kval, dval)==1:
    --- do mval stuff ---

User avatar
deltadidirac
Regular
Posts: 123
Joined: Fri Nov 30, 2018 5:00 am
Projects: Artworks and Comics
Tumblr: deltadidirac
Deviantart: Deltadidirac67
Location: Europe
Contact:

Re: how to define the hierarchy of variables

#7 Post by deltadidirac » Sat Nov 30, 2019 8:41 am

Per K Grok wrote:
Sat Nov 30, 2019 8:27 am
deltadidirac wrote:
Sat Nov 30, 2019 7:45 am


Mhmm... seems really simple, and I could use it for some situations....

one thing I didn't understand, the "return 1/2/3/4" at what referred are?
The variable value?

If yes this mean that your example is only the way to define the priority...
defined this, you build your label normally with the if stament, right?

I must test it a little...
Thanks anyway


pickChoice(a,b,c,d) is a function that takes four parameters, that should have numerical values, and compares them.

The function returns an answer that is 1, 2, 3 or 4. If the answer is 1 then the variable entered as the first parameter (a) has the highest value [or the highest value that also an other variable has] . If the answer is 2 then the same thing goes for the the second parameter, and so on.

The if/elif construction makes it so that at a tie 'a' will be chosen before 'b' and so on.



When you want to use the function you call it and have the program doing different things depending on what number the function returns.

Code: Select all

if pickChoice(mval, lval, kval, dval)==1:
    --- do mval stuff ---
More clear, very kind thanks...

Post Reply

Who is online

Users browsing this forum: Ocelot