Problem with "if" statements [Solved-ish]

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
Sehaf
Regular
Posts: 58
Joined: Thu Feb 25, 2010 9:22 pm
Projects: Demon Lord & Yuki Academy
Deviantart: Sehad
Location: Sweden
Contact:

Problem with "if" statements [Solved-ish]

#1 Post by Sehaf »

Hi. I tried to make a Match-3 kind of enginge as I could not see one already beeing avaleble in when serching. Tried doing this myself. But Only get syntax error and cannot understand what I do wrong or what else I sohuld do to get the same restult. This was to create the seed for the grid.

Code: Select all

    while box_numb_count < 49:
        
        if box_[col_Count][row_Count] == "none":
            
            if row[row_Count]_Col_repeat != "pink2" or col_Col_repeat != "pink2":
                python:
                    collor_match_list.append("pink")
            elif row[row_Count]_Col_repeat == "pink2":
                if row_Count == 1:
                    $ row1_Col_repeat = "none"
                elif row_Count == 2:
                    $ row2_Col_repeat = "none"
                elif row_Count == 3:
                    $ row3_Col_repeat = "none"
                elif row_Count == 4:
                    $ row4_Col_repeat = "none"
                elif row_Count == 5:
                    $ row5_Col_repeat = "none"
                elif row_Count == 6:
                    $ row6_Col_repeat = "none"
                elif row_Count == 7:
                    $ row7_Col_repeat = "none"
            elif col_Col_repeat == "pink2":
                $ col_Col_repeat = "none"
                    
            if row[row_Count]_Col_repeat != "red2" or col_Col_repeat != "red2":
                python:
                    collor_match_list.append("red")
            elif row[row_Count]_Col_repeat == "red2":
                if row_Count == 1:
                    $ row1_Col_repeat = "none"
                elif row_Count == 2:
                    $ row2_Col_repeat = "none"
                elif row_Count == 3:
                    $ row3_Col_repeat = "none"
                elif row_Count == 4:
                    $ row4_Col_repeat = "none"
                elif row_Count == 5:
                    $ row5_Col_repeat = "none"
                elif row_Count == 6:
                    $ row6_Col_repeat = "none"
                elif row_Count == 7:
                    $ row7_Col_repeat = "none"
            elif col_Col_repeat == "red2":
                $ col_Col_repeat = "none"
                    
            if row[row_Count]_Col_repeat != "blue2" or col_Col_repeat != "blue2":
                python:
                    collor_match_list.append("blue")
            elif row[row_Count]_Col_repeat == "blue2":
                if row_Count == 1:
                    $ row1_Col_repeat = "none"
                elif row_Count == 2:
                    $ row2_Col_repeat = "none"
                elif row_Count == 3:
                    $ row3_Col_repeat = "none"
                elif row_Count == 4:
                    $ row4_Col_repeat = "none"
                elif row_Count == 5:
                    $ row5_Col_repeat = "none"
                elif row_Count == 6:
                    $ row6_Col_repeat = "none"
                elif row_Count == 7:
                    $ row7_Col_repeat = "none"
            elif col_Col_repeat == "blue2":
                $ col_Col_repeat = "none"
                    
            if row[row_Count]_Col_repeat != "green2" or col_Col_repeat != "green2":
                python:
                    collor_match_list.append("green")
            elif row[row_Count]_Col_repeat == "green2":
                if row_Count == 1:
                    $ row1_Col_repeat = "none"
                elif row_Count == 2:
                    $ row2_Col_repeat = "none"
                elif row_Count == 3:
                    $ row3_Col_repeat = "none"
                elif row_Count == 4:
                    $ row4_Col_repeat = "none"
                elif row_Count == 5:
                    $ row5_Col_repeat = "none"
                elif row_Count == 6:
                    $ row6_Col_repeat = "none"
                elif row_Count == 7:
                    $ row7_Col_repeat = "none"
            elif col_Col_repeat == "green2":
                $ col_Col_repeat = "none"
                    
            if row[row_Count]_Col_repeat != "yellow2" or col_Col_repeat != "yellow2":
                python:
                    collor_match_list.append("yellow")
            elif row[row_Count]_Col_repeat == "yellow2":
                if row_Count == 1:
                    $ row1_Col_repeat = "none"
                elif row_Count == 2:
                    $ row2_Col_repeat = "none"
                elif row_Count == 3:
                    $ row3_Col_repeat = "none"
                elif row_Count == 4:
                    $ row4_Col_repeat = "none"
                elif row_Count == 5:
                    $ row5_Col_repeat = "none"
                elif row_Count == 6:
                    $ row6_Col_repeat = "none"
                elif row_Count == 7:
                    $ row7_Col_repeat = "none"
            elif col_Col_repeat == "yellow2":
                $ col_Col_repeat = "none"
                    

                
                
            $ box_[col_Count][row_Count] = renpy.random.choice(['collor_match_list'])
            
            if box_[col_Count][row_Count] == row[row_Count]_Col_repeat:
                if row[row_Count]_Col_repeat == "red":
                    if row_Count == 1:
                        $ row1_Col_repeat = "red2"
                    elif row_Count == 2:
                        $ row2_Col_repeat = "red2"
                    elif row_Count == 3:
                        $ row3_Col_repeat = "red2"
                    elif row_Count == 4:
                        $ row4_Col_repeat = "red2"
                    elif row_Count == 5:
                        $ row5_Col_repeat = "red2"
                    elif row_Count == 6:
                        $ row6_Col_repeat = "red2"
                    elif row_Count == 7:
                        $ row7_Col_repeat = "red2"

                if row[row_Count]_Col_repeat == "blue":
                    if row_Count == 1:
                        $ row1_Col_repeat = "blue2"
                    elif row_Count == 2:
                        $ row2_Col_repeat = "blue2"
                    elif row_Count == 3:
                        $ row3_Col_repeat = "blue2"
                    elif row_Count == 4:
                        $ row4_Col_repeat = "blue2"
                    elif row_Count == 5:
                        $ row5_Col_repeat = "blue2"
                    elif row_Count == 6:
                        $ row6_Col_repeat = "blue2"
                    elif row_Count == 7:
                        $ row7_Col_repeat = "blue2"
                        
                if row[row_Count]_Col_repeat == "yellow":
                    if row_Count == 1:
                        $ row1_Col_repeat = "yellow2"
                    elif row_Count == 2:
                        $ row2_Col_repeat = "yellow2"
                    elif row_Count == 3:
                        $ row3_Col_repeat = "yellow2"
                    elif row_Count == 4:
                        $ row4_Col_repeat = "yellow2"
                    elif row_Count == 5:
                        $ row5_Col_repeat = "yellow2"
                    elif row_Count == 6:
                        $ row6_Col_repeat = "yellow2"
                    elif row_Count == 7:
                        $ row7_Col_repeat = "yellow2"
                        
                if row[row_Count]_Col_repeat == "pink":
                    if row_Count == 1:
                        $ row1_Col_repeat = "pink2"
                    elif row_Count == 2:
                        $ row2_Col_repeat = "pink2"
                    elif row_Count == 3:
                        $ row3_Col_repeat = "pink2"
                    elif row_Count == 4:
                        $ row4_Col_repeat = "pink2"
                    elif row_Count == 5:
                        $ row5_Col_repeat = "pink2"
                    elif row_Count == 6:
                        $ row6_Col_repeat = "pink2"
                    elif row_Count == 7:
                        $ row7_Col_repeat = "pink2"
                        
                if row[row_Count]_Col_repeat == "green":
                    if row_Count == 1:
                        $ row1_Col_repeat = "green2"
                    elif row_Count == 2:
                        $ row2_Col_repeat = "green2"
                    elif row_Count == 3:
                        $ row3_Col_repeat = "green2"
                    elif row_Count == 4:
                        $ row4_Col_repeat = "green2"
                    elif row_Count == 5:
                        $ row5_Col_repeat = "green2"
                    elif row_Count == 6:
                        $ row6_Col_repeat = "green2"
                    elif row_Count == 7:
                        $ row7_Col_repeat = "green2"

            if box_[col_Count][row_Count] == col_Col_repeat:
                if col_Col_repeat == "red":
                    $ col_Col_repeat = "red2"
                if col_Col_repeat == "blue":
                    $ col_Col_repeat = "blue2"
                if col_Col_repeat == "yellow":
                    $ col_Col_repeat = "yellow2"
                if col_Col_repeat == "pink":
                    $ col_Col_repeat = "pink2"
                if col_Col_repeat == "green":
                    $ col_Col_repeat = "green2"
                    
            
                    
            if row_Count == 1:
                $ row1_Col_repeat = box_[col_Count][row_Count]
            elif row_Count == 2:
                $ row2_Col_repeat = box_[col_Count][row_Count]
            elif row_Count == 3:
                $ row3_Col_repeat = box_[col_Count][row_Count]
            elif row_Count == 4:
                $ row4_Col_repeat = box_[col_Count][row_Count]
            elif row_Count == 5:
                $ row5_Col_repeat = box_[col_Count][row_Count]
            elif row_Count == 6:
                $ row6_Col_repeat = box_[col_Count][row_Count]
            elif row_Count == 7:
                $ row7_Col_repeat = box_[col_Count][row_Count]

            $ col_Col_repeat = box_[col_Count][row_Count]

            python:
                collor_match_list = []
            
            
        else:
            pass
        
            
        $ box_numb_count += 1
        $ row_Count += 1
            
        if row_Count < 7:
            $ row_Count = 1
            $ col_Col_repeat = "none"
            $ col_Count += 1
        

        
    $ row_Count = 1
    $ col_Count = 1
    
    $ box_numb_count = 1
    
    $ row1_Col_repeat = "none"
    $ row2_Col_repeat = "none"
    $ row3_Col_repeat = "none"
    $ row4_Col_repeat = "none"
    $ row5_Col_repeat = "none"
    $ row6_Col_repeat = "none"
    $ row7_Col_repeat = "none"
    $ col_Col_repeat = "none"

    return

EDIT: Managed to work out a working solution. Thanks for the help to those who pitched in.
Last edited by Sehaf on Mon Dec 23, 2019 7:13 pm, edited 1 time in total.
I'm a GameMaker!
My Portfolio: http://www.bluepipestudio.com

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: Problem with "if" statements

#2 Post by Per K Grok »

Sehaf wrote: Wed Nov 27, 2019 6:09 am Hi. I tried to make a Match-3 kind of enginge as I could not see one already beeing avaleble in when serching. Tried doing this myself. But Only get syntax error and cannot understand what I do wrong or what else I sohuld do to get the same restult. This was to create the seed for the grid.

Code: Select all

    while box_numb_count < 49:
        
        if box_[col_Count][row_Count] == "none":
            
            if row[row_Count]_Col_repeat != "pink2" or col_Col_repeat != "pink2":
                python:
                    collor_match_list.append("pink")
            elif row[row_Count]_Col_repeat == "pink2":
                if row_Count == 1:
                    $ row1_Col_repeat = "none"
                elif row_Count == 2:
                    $ row2_Col_repeat = "none"
                elif row_Count == 3:
                    $ row3_Col_repeat = "none"
                elif row_Count == 4:
                    $ row4_Col_repeat = "none"
                elif row_Count == 5:
                    $ row5_Col_repeat = "none"
                elif row_Count == 6:
                    $ row6_Col_repeat = "none"
                elif row_Count == 7:
                    $ row7_Col_repeat = "none"
            elif col_Col_repeat == "pink2":
                $ col_Col_repeat = "none"
                    
        ----------------

    return
I think this is your problem;

row[row_Count]_Col_repeat

it looks like you expect that to be read by the computer as

row1_Col_repeat
row2_Col_repeat
row3_Col_repeat
row4_Col_repeat
etc

You can do that in a string, but not in variable-name.

You could use a list instead
row_Col_repeat=[]

User avatar
Sehaf
Regular
Posts: 58
Joined: Thu Feb 25, 2010 9:22 pm
Projects: Demon Lord & Yuki Academy
Deviantart: Sehad
Location: Sweden
Contact:

Re: Problem with "if" statements

#3 Post by Sehaf »

So there is no equalent to do the same in a variable-name as with a string? Is it just not doable? Or is it rather making things to advanced in code?

Though I could use a list, would that not be the same thing then if I want to go through multiple lists the same way? As I cannot check for different variable-name.
I'm a GameMaker!
My Portfolio: http://www.bluepipestudio.com

User avatar
IaMe
Regular
Posts: 31
Joined: Fri Jan 11, 2013 5:27 am
Location: Australia
Contact:

Re: Problem with "if" statements

#4 Post by IaMe »

If it helps there actually is a premade match 3 code available in the forums cookbook section
here’s a direct link- viewtopic.php?p=486054#p486054
The Website for my game's development
http://fallingheartsotomegame.tumblr.com/

User avatar
Sehaf
Regular
Posts: 58
Joined: Thu Feb 25, 2010 9:22 pm
Projects: Demon Lord & Yuki Academy
Deviantart: Sehad
Location: Sweden
Contact:

Re: Problem with "if" statements

#5 Post by Sehaf »

Thanks. Though after looking through it it felt quite hard to modify to my needs. Not really beginner friendly as they say.
I'm a GameMaker!
My Portfolio: http://www.bluepipestudio.com

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Alex, Google [Bot]