Possibly hit the nesting limit for statements?

Alright, so I’m trying to implement a dialogue system that can be edited easily on the fly. I want to be able to edit text for dozens of NPCs using the same properties, which I’ve got in place. Those properties are as follows:
NearNPC – This is an integer. The number indicates the NPC that the player is near.
isInDialogueMenu - This is also an integer. This indicates whether the player is free roaming, has entered dialogue, or exited dialogue. It ranges from 0 for no, 1, for yes, and 3 for exited.
dialogueNumber – This is yet another integer. It determines, along with NearNPC, what line of text the text box should be displaying.
dialogueChoice – This is an integer that handles multiple choice dialogue menus. It starts at 0 and never goes above 2.

So… with that done the code is as follows:

import bge
import math    #this is for other functions like lotteries and random item drops
import Rasterizer     #this is for use later down, for certain visual effects
import random     #also for use in lotteries and item drops
from bge import logic    #this is for use in controlling the camera's ortho scale later down

def full (cont):
    cont = bge.logic.getCurrentController()
    scene = bge.logic.getCurrentScene()
    own = cont.owner
    keyboard = bge.logic.keyboard
    JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED
    JUST_RELEASED = bge.logic.KX_INPUT_JUST_RELEASED
    ACTIVE = bge.logic.KX_INPUT_ACTIVE
    NONE = bge.logic.KX_INPUT_NONE

#### List objects and meshes ####  
    PlayerHitbox = scene.objects['PlayerHitbox']
    PlayerCam = logic.getCurrentScene().active_camera
    Ground = scene.objects['Ground']
    Dialogue = scene.objects['Dialogue']     #This is a text object
    DialogueTextBackground = scene.objects['DialogueTextBackground']
    DialogueChoiceArrow = scene.objects['DialogueChoiceArrow']
    NPC1 = scene.objects['NPC1']
    NPC2 = scene.objects['NPC2']

#### List of sensors, to be replaced later #### 
    npc1Near = cont.sensors["npc1Near"]
    npc2Near = cont.sensors["npc2Near"]


#### The code that do the thing and the whatnot #### 

   if npc1Near.positive:
        if own['isInDialogueMenu'] == 3:
            own['isInDialogueMenu'] = 0
        own['nearNPC'] = 1

        if own['isInDialogueMenu'] == 0:
            own['dialogueNumber'] = 0

            if keyboard.events[bge.events.EKEY] == JUST_RELEASED:
                own['isInDialogueMenu'] = 1
                Dialogue.color = 1, 1, 1, 1
                DialogueTextBackground.color = 0, 0, 0, 1
                Dialogue.text = "Oh I'm just a test. \nJust a little 'ole test. Just \nsittin' here with my little vest."
                
        if own['isInDialogueMenu'] == 1:
            if keyboard.events[bge.events.EKEY] == JUST_RELEASED:
                if own['nearNPC'] == 1:
                    own['dialogueNumber'] +=1

                    if own['dialogueNumber'] == 6:
                        own['dialogueNumber'] = 5

                    if own['dialogueNumber'] == 2:
                        Dialogue.text = "You wanna take a quiz? I test \nbranching dialogue trees!"

                    if own['dialogueNumber'] == 3:
                        Dialogue.text = "If you answer my questions \nright, I'll give you a nice item!"

                    if own['dialogueNumber'] == 4:
                        Dialogue.text = "What year was the Ford Mustang \nfirst introduced?"

                    if own['dialogueNumber'] == 5:

                        DialogueChoiceArrow.color = 1, 1, 1, 1

                        if own['dialogueChoice'] == -1:
                            own['dialogueChoice'] = 2

                        if own['dialogueChoice'] == 3:
                            own['dialogueChoice'] = 0

                        if own['dialogueChoice'] == 0:
                            DialogueChoiceArrow.localPosition = -6, 0, 1
                            if keyboard.events[bge.events.SKEY] == JUST_RELEASED:
                                print("Shifting to dialogueChoice1")
                                own['dialogueChoice'] = 1
                            if keyboard.events[bge.events.SKEY] == NONE:  #These two lines were added to test
                                print("Not shifting to dialogueChoice1") #This, oddly enough, prints to the console while "Shifting to dialogueChoice1" does not
                                
                        if own['dialogueChoice'] == 1:
                            DialogueChoiceArrow.localPosition = -6, 0, 0
                            if keyboard.events[bge.events.SKEY] == JUST_RELEASED:
                                print("Shifting to DialogueChoice2")
                                own['dialogueChoice'] = 2

                        if own['dialogueChoice'] == 2:
                            DialogueChoiceArrow.localPosition = -6, 0, -1
                            if keyboard.events[bge.events.SKEY] == JUST_ACTIVATED:
                                print("Shift to DialogueChoice0")
                                own['dialogueChoice'] = 0
                        
                        Dialogue.text = "    1964 \n    1968 \n    1979"

    else:
        own['nearNPC'] = 0
                       
    if own['isInDialogueMenu'] == 3 or own['isInDialogueMenu'] == 0:
        Dialogue.color = 0, 0, 0, 0
        DialogueTextBackground.color = 0, 0, 0, 0

Something’s wrong, and the line that should print “Shifting to dialogueChoice1” isn’t printing to the console. Like it’s not detecting the keyboard input. The input isn’t mapped to any other commands further up or later down, so it’s not being interfered with. It’s just an oddity that won’t throw any errors in the console, but also won’t work. I know Python 3 and 2.7 have a nesting limit of 20 statements, but does Blender have a lower limit? The number of nested statements here is only 6. I’m puzzled. Everything but that line works, even the other dialogue choices if I force a keyboard command to manually increase dialogueChoice by 1 without regarding to dialogueNumber or isInDialogue.

most likely never trigger.

What would cause it to not trigger though? I’ve tried switching it to ACTIVE and JUST_ACTIVATED and neither of those work either. Here’s the console output, for reference:

Place a print before every if condition in order to see what are the values and where is your mistake.

If it were a max nesting Python error you would see a SyntaxError being raised, which is not the case.

I tried adding

if own['dialogueChoice'] == 0:
    print("Dialogue choice is zero.")

And that is the last line that prints. So it’s definitely the keyboard.

if keyboard.events[bge.events.EKEY] == JUST_RELEASED:
     if keyboard.events[bge.events.SKEY] == JUST_RELEASED:

both need to be true before “print(“Shifting to dialogueChoice1”)” gets executed.
nesting key.events like that is where you problem are.

Ahhhhh, thanks. I overlooked that. I’ll reformat it so that doesn’t happen. Thanks for the help.

Good luck with that :slight_smile:

It seems like you tried to write some kind of state system where you first press E, and later S.

You cannot exactly write it like you did.