I am trying tomake a visual novel prototype, the problem i have and the documentation does not help me much with is the imput to pass to the next bit of dialogue, if I use this bit of code:

for dindex in range(scriptpath.final):
		if Input.is_action_just_pressed("ui_accept"):
			$character.texture = load(scriptpath.dialogues[dindex]["sprite"])
			$nametag.text = scriptpath.dialogues[dindex]["name"]
			$dialogue.text = scriptpath.dialogues[dindex]["dialogue"]

it does compile however, pressing the space or enter keys has no effect, I have tried removing the input so i know that the loop does work as intended, so i would like to know what is it that i am doing wrong with this input and if that is even a good way to pause the loop to wait for user input.

I had a similar issue when adding instruction text boxes to my last project.

How I solved it is by writing the code something to this effect:

func _ready():
	visibility = visible
	
	$SlideOne.visible = visibility
	$SlideTwo.visible = not visibility
	$SlideThree.visible = not visibility

var slide = 1

if Input.is_action_just_released("ui_accept"):
	slide = slide + 1

if input.is_action_just_pressed("ui_accept") and slide == 1:
	$SlideOne.visible = not visibility
	$SlideTwo.visible = visibility
if input.is_action_just_pressed("ui_accept") and slide == 2:
	$SlideTwo.visible = not visibility
	$SlideThree.visible = visibility

The slide variable indicates which slide, or which bit of dialogue, you're on. So when you push whatever you have for ui_accept, it changes the next slide by making the current one hidden and the next slide visible. It's only when you release the ui_accept button that the slide button is updated, meeting the requirements of the next if statement and letting you progress.

I've noticed, at least in my last project, that some methods either don't move on or skip all the dialogue in one button press. I don't know if this method here will work or even help, but I really hope it does! Good luck!

@Chamuk0 From a programming view your code doesn't seem to make sense. It's a problem of timing. If you're going through a for loop, you're choosing what time to check for input events, but input events don't care about what time you want to check for them, input events are triggered when the user feels like it. Functionality that needs to be tied to input events should be waiting for an event to happen, not waiting for you (the programmer) to loop around and check.

Put your if Input.is_action_just_pressed("ui_accept"): lines of code inside a func _input(_event): function and try that. The _input() function is going to be called when there's input.

Yeah, checking input in a loop doesn't make sense to me. Not even sure what the code would be doing, but I don't think the logic works. Best to use _input for input events. Maybe explain what you are trying to accomplish and I can give you some sample code.

a year later