Best way to wait for user input before displaying new text messages.

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
erolayer
Prole
Posts: 3
Joined: Mon May 22, 2017 7:13 pm

Best way to wait for user input before displaying new text messages.

Post by erolayer »

tl;dr I am trying to make a system that displays dialogue boxes, and am currently stuck trying to figure out how to wait between each line of dialogue so it does not proceed to the next line unless the user clicks or presses a key. Any tutorials, samples, comments, leads, whatever that can point me in the right direction are immensely welcomed. :awesome:

Hi, just recently started to learn lua in order to use Love2d. I'm currently making(trying to make, I guess) a visual novel kind of game, where I was using renpy and tyranobuilder, but I ended up trying to change too much stuff around and trying to make too many changes within the boundaries of their scripting language until I realized I could very well learn to use some other language that could be more versatile and useful in the long run.

Overall it's been a fun trip, being fun trying to make these dialogue boxes show up on screen and it's given me a lot of feeling of accomplishment, considering I do no have formal programming training, but I want to proceed to whatever is next.

Simply put I do not know how to just add something where I'm missing in the code below, in order to make scripting the dialogue cleaner instead of relying on a bunch of loops and stuff that would make it difficult to read and modify as I nest infinitely.

Code: Select all

_d("This is the first line of dialogue", "HERO NAME")
--?????????????????????
_d ("This is the second line of dialogue", "HEROINE NAME")
Right now my main.lua looks like this:

Code: Select all

function love.load()
	diabox = require "diabox"
	width, height = love.window.getMode()
	scene01 = love.graphics.newImage("cgs/plainbg.jpg", jpg)
end

function love.draw()
	love.graphics.setColor(255, 255, 255, 255)	
	love.graphics.draw(scene01, 0, 0)
	_dstyle ("def")
	_d("DIALOGUE1", "HERO NAME")
	_d("OMG", "HERO NAME")
	_dstyle ("scene")
	_d("FUCK ITS WORKING","HERO NAME")
	_d("Thing lorem etc etc.", "HERO NAME")
	_d("LOLOLOLOLOLOL")

end
The diabox.lua that's required is

Code: Select all

function _dstyle (boxstyle)
if boxstyle == "def" then
		----------------------------------------------------------------------------------------
		--Dialoguebox Configuration variables. Change to adjust appearance.
		----------------------------------------------------------------------------------------
		textboxbg = love.graphics.newImage("gui/textbox.png", png)
		nameboxbg = love.graphics.newImage("gui/namebox.png", png)
		-- Position of the Dialogue Box relating to the window
		tbox_xali = .5 		--(0 is left 	.5 is centered	 	1 is right)			[texbox = .5 ]
		tbox_yali = 1 		--(0 is top	 	.5 is middle 		1 is bottom)		[texbox = 1  ]
		tbox_fsize = 36		--														[texbox = 36 ]
		tbox_ox = 0			--														[texbox = 0 ]
		tbox_oy = 0			--														[texbox = 0 ]
		-- Position of the namebox background relating to the dialogue box
		nbox_ox =  105	-------- x position (negative value draws to the right)  	[texbox = 105]
		nbox_oy =  -51	-------- y position (positive value draws to the bottom)	[texbox = -51]
		-- Name Text position and apperance
		nbox_padr = 63	-------- padding of the name tag. Affects character limit 	[texbox = 63 ]
		nbox_padl = 55	-------- 													[texbox = 55 ]
		nbox_padt = 33 	--------													[texbox = 33 ]
		ntag_fsize = 32		-------- fontsize of the name tag 						[texbox = 32 ]
		ntag_ali = 'center'	---- text alignment of the namebox   					[texbox = 'center']
		----------------------------------------------------------------------------------------
		dbox_padl = 167		--														[texbox = 167]
		dbox_padr = 167		--														[texbox = 167]
		dbox_padt = -35		--														[texbox = 53]	
		dbox_fsize = 30		--														[texbox = 30]
		dbox_ali = 'left'	--														[texbox = 'left']
		dbox_nonampad = 90	-- dialogue top padding if there's no namebox
		----------------------------------------------------------------------------------------
		else
		----------------------------------------------------------------------------------------
		--Dialoguebox Configuration variables. Change to adjust appearance.
		----------------------------------------------------------------------------------------
		-- Position of the Dialogue Box relating to the window
		textboxbg = love.graphics.newImage("gui/textboxscene.png", png)
		nameboxbg = love.graphics.newImage("gui/nameboxscene.png", png)	
		tbox_xali = .5 		--(0 is left 	.5 is centered	 	1 is right)			[texbox = .5 ]
		tbox_yali = 1 		--(0 is top	 	.5 is middle 		1 is bottom)		[texbox = 1  ]
		tbox_fsize = 0		--														[texbox = 36 ]
		tbox_ox = 0			--														[texbox = 0 ]
		tbox_oy = 5			--														[texbox = 0 ]
		-- Position of the namebox background relating to the dialogue box
		nbox_ox =  20.5	-------- x position (negative value draws to the right)  	[texbox = 105]
		nbox_oy =  0	-------- y position (positive value draws to the bottom)	[texbox = -51]
		-- Name Text position and apperance
		nbox_padr = 0	-------- padding of the name tag. Affects character limit 	[texbox = 63 ]
		nbox_padl = 0	-------- 													[texbox = 55 ]
		nbox_padt = 18 	--------													[texbox = 33 ]
		ntag_fsize = 40		-------- fontsize of the name tag 						[texbox = 32 ]
		ntag_ali = 'center'	---- text alignment of the namebox   					[texbox = 'center']
		----------------------------------------------------------------------------------------
		dbox_padl = 40		--														[texbox = 167]
		dbox_padr = 40		--														[texbox = 167]
		dbox_padt = 20		--														[texbox = 53]	
		dbox_fsize = 32		--														[texbox = 30]
		dbox_ali = 'left'	--														[texbox = 'left']
		dbox_nonampad = 70	-- dialogue top padding if there's no namebox
		----------------------------------------------------------------------------------------
	end
	----------------------------------------------------------------------------------------
	-- Misc Variables being setup
	----------------------------------------------------------------------------------------
	namevisible = 1
	tbox_xs, tbox_ys = textboxbg:getDimensions()
	nbox_xs, nbox_ys = nameboxbg:getDimensions()
	----------------------------------------------------------------------------------------
	-- Dialogue Box position code
	----------------------------------------------------------------------------------------
	tbox_x = width-tbox_xs
	tbox_y = height-tbox_ys
	tbox_xroot = tbox_x * tbox_xali
	tbox_yroot = tbox_y * tbox_yali
	tbox_xloc = tbox_xroot - tbox_ox
	tbox_yloc = tbox_yroot - tbox_oy
	dbox_nampad = (nbox_ys*namevisible)+dbox_nonampad
	
	----------------------------------------------------------------------------------------
	-- Name Box position code
	----------------------------------------------------------------------------------------
	nbox_xroot = tbox_xloc + nbox_ox
	nbox_yroot = tbox_yloc + nbox_oy
	----------------------------------------------------------------------------------------
	-- Name Tag position code
	----------------------------------------------------------------------------------------
	ntag_xroot = nbox_xroot + nbox_padl
	ntag_yroot = nbox_yroot + nbox_padt
	nbox_size = nbox_xs - nbox_padl
	ntag_limit = nbox_size - nbox_padr
	----------------------------------------------------------------------------------------
	-- Dialogue Text position code
	----------------------------------------------------------------------------------------
	dtxt_xroot = tbox_xloc + dbox_padl
	dtxt_yroot = tbox_yloc + dbox_nampad
	dbox_size = tbox_xs - dbox_padl
	dbox_limit = dbox_size - dbox_padr
	----------------------------------------------------------------------------------------
	fontname = love.graphics.newFont("gui/berlinsans.ttf", ntag_fsize)
	fontdialogue = love.graphics.newFont("gui/berlinsans.ttf", dbox_fsize)
end

function _d(d_what, d_who)
	----------------------------------------------------------------------------------------
	-- Dialogue Box Draw
	----------------------------------------------------------------------------------------
	love.graphics.setColor(255, 255, 255, 255)
	love.graphics.draw(textboxbg, tbox_xloc, tbox_yloc)
	love.graphics.setColor(0, 0, 0, 255)
	love.graphics.setFont(fontdialogue)
	love.graphics.printf(d_what, dtxt_xroot, dtxt_yroot, dbox_limit, dbox_ali)
	----------------------------------------------------------------------------------------
	----------------------------------------------------------------------------------------
	--Namebox Draw
	----------------------------------------------------------------------------------------
	love.graphics.setColor(255, 255, 255, 255)
	if d_who ~= nil then
		dbox_nampad = (nbox_ys*namevisible)+dbox_padt
		love.graphics.draw(nameboxbg, nbox_xroot, nbox_yroot)
		love.graphics.setColor(0, 0, 0, 255)
		love.graphics.setFont(fontname)
		love.graphics.printf(d_who, ntag_xroot, ntag_yroot, ntag_limit, ntag_ali)
		love.graphics.setColor(255, 255, 255, 255)

	end
	----------------------------------------------------------------------------------------

end
My end goal here would be to have a dialogue system that:
Takes a script written with the function "_d("dialogue", "character") and having the game display them appropriately formated.
Having to trigger the next dialogue box.

In the future I want to make it so I can pause the dialogue before complety printing it and even having the dialogue show letter by letter and some other things I assume are way to complex for me to grasp if I cant manage to find the solution to my title problem right now.
User avatar
Sir_Silver
Party member
Posts: 286
Joined: Mon Aug 22, 2016 2:25 pm
Contact:

Re: Best way to wait for user input before displaying new text messages.

Post by Sir_Silver »

Well there is the

Code: Select all

function love.keypressed(key)

end
callback that you can use and have whatever relevant code happen after you press any or a specific key.

https://love2d.org/wiki/love.keypressed
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Best way to wait for user input before displaying new text messages.

Post by bartbes »

This kind of thing is always tricky, but perhaps the simplest method would be to use a separate gamestate for the dialog. Then when you switch to it, you tell it what dialog to display, and then when it switches back you can display the next one. Of course that does mean it gets more complicated than just calling a function twice. You can try to hide it using various techniques, but in the end you'll end up having to store some state between frames, that's just the way it is.
User avatar
zorg
Party member
Posts: 3470
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Best way to wait for user input before displaying new text messages.

Post by zorg »

Coding a VN is hard.
That said, what you probably want is a timer to advance the script, that also works in conjunction with the user creating input (like pressing a key or a mouse button)
There are a few timer libraries out there that you can use, if you want to.
https://github.com/love2d-community/awe ... d#tweening
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 10 guests