Best way to wait for user input before displaying new text messages.
Posted: Fri Jun 02, 2017 1:07 am
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.
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.
Right now my main.lua looks like this:
The diabox.lua that's required is
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.
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")
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
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
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.