Page 1 of 1

Need some help for dialogs, please [fixed]

Posted: Fri Oct 12, 2012 11:01 pm
by Ethmo_Lux
As I told in another topic

I'm stuck with some dialog's display. Anyone can help me ?

Thanks. :D
Ethmo_Lux wrote: I was working on dialog, and some are very long. But it's easier form me to send them in one string. How can I split it without /n (cause it's buggy) ?

Here the code, I don't think it's optimized, still working on it. ;)

Code: Select all

pnjName = "Victor"
dialog = "Oh, so you come to see Victor! Afraid of Scotia's new toy ? Ha ha!\nWhy afraid? Look at Victor. Myself could use a shapechanger! Ha ha ha!\nYou show Victor what you want to buy. Maybe you show Victor what you sell, OK ?"
secondDialog = "You again come to see Victor ?"
byeDialog = "You again come visit, no?"
fromShop = false

function pnjTell(dialog)
	hudPrint(pnjName.." : "..dialog)
end


function pnjDialog()
	if not fromShop then
		pnjTell(dialog)
		fromShop = true
	end
	dialog = secondDialog	
end

function pnjBye()
	if fromShop then
		pnjTell(byeDialog)
		fromShop = false
	end
end
Image

A trigger the door and pnjBye()
B trigger pnjDialog()

Re: Need some help for dialogs, please

Posted: Fri Oct 12, 2012 11:54 pm
by Crisim
you can wrap the text with double square brackets

Code: Select all

var verylongtext = [[
this is my story
...
...
...
and this is the end
]]
remember that with hudprint you can show a max of 4 rows

Re: Need some help for dialogs, please

Posted: Sat Oct 13, 2012 12:37 am
by Ethmo_Lux
Ok. Thank you very much. I'll try that. :D

Re: Need some help for dialogs, please

Posted: Sat Oct 13, 2012 1:03 am
by Ethmo_Lux
Hmmm... :/ Still not that.

I got some issues like text printed on previous texts and out of screen.

Image

Image

A guess there's something with the text's alignment.

Re: Need some help for dialogs, please

Posted: Sat Oct 13, 2012 9:28 am
by petri
hudPrint doesn't support linebreaks. You have to manually split the lines and call hudPrint for each line. Hope this helps!

Re: Need some help for dialogs, please

Posted: Sat Oct 13, 2012 10:53 am
by Ethmo_Lux
petri wrote:hudPrint doesn't support linebreaks. You have to manually split the lines and call hudPrint for each line. Hope this helps!
Ok. I tried with string manipulation before the squares brackets but it crashed... I don't know if it was because of the loop or the string manipulations itself.

Can I use a for to look over a string like a table, and how ?

Thanks. :)

EDIT : That was kind of simple in fact. :roll:

Code: Select all

pnjName = "Nathaniel"
dialEnd = "end of dialog"
dialog = { "Shh! Did you hear something? If Scotia does attack","they say we won't hear a thing! Quickly now, point out what you need.",dialEnd }
secondDialog = {"Did you forget something ?", dialEnd }
byeDialog = { "Farewell then.", dialEnd }
fromShop = false

function pnjTell(dialog)
	local dialNumber = 1
	hudPrint("")
	if dialog[dialNumber] ~= dialEnd then
		hudPrint(pnjName.." : "..dialog[dialNumber])
		dialNumber = dialNumber + 1
		
		while dialog[dialNumber] ~= dialEnd do
			hudPrint(dialog[dialNumber])
			dialNumber = dialNumber + 1
		end	
	end
end


function pnjDialog()
	if not fromShop then
		pnjTell(dialog)
		fromShop = true
	end
	dialog = secondDialog
		
end

function pnjBye()
	if fromShop then
		pnjTell(byeDialog)
		fromShop = false
	end
end