Page 1 of 1

Textbox Help

Posted: Tue Jun 03, 2014 10:38 pm
by squidborne_destiny
Hey guys, I am new to love and I was looking for a way to create textboxes similar to those in Legend of Zelda; where I can press "z" and move through pages. Right now I am spawning Npcs and giving the a string parameter, but it does not work for multiple pages. Any help is appreciated, thanks.

Re: Textbox Help

Posted: Wed Jun 04, 2014 7:44 am
by Roland_Yonaba
Take a look at Litearc's Navi.
And welcome to LÖVE.

Re: Textbox Help

Posted: Wed Jun 04, 2014 7:15 pm
by squidborne_destiny
Roland_Yonaba wrote:Take a look at Litearc's Navi.
And welcome to LÖVE.
Thanks!

Re: Textbox Help

Posted: Thu Jun 05, 2014 1:01 am
by squidborne_destiny
Hey I was wondering if there was a way to take on string of text and save it as multiple variables in a table.

Re: Textbox Help

Posted: Thu Jun 05, 2014 2:40 am
by davisdude
Sure.

Code: Select all

String = 'This is my string'
Part1 = String:sub( 1, 4 ) -- "This"
Part2 = String:sub( 6, 7 ) -- "is"
-- etc.

Re: Textbox Help

Posted: Thu Jun 05, 2014 2:52 am
by Jasoco
What you want is a Split function:

Code: Select all

 function string:split(delimiter)
	local result = { }
	local from = 1
	local delim_from, delim_to = string.find( self, delimiter, from )
	while delim_from do
		table.insert( result, string.sub( self, from , delim_from-1 ) )
		from = delim_to + 1
		delim_from, delim_to = string.find( self, delimiter, from )
	end
	table.insert( result, string.sub( self, from ) )
	return result
end
The delimiter is the character you want to split it at. In your case probably a space. The string part would be the variable you are storing the text in.

But if I were you doing a message box and you want it to type itself in use the string.sub() function instead and local value to the message box that ticks up every frame (Use dt) and grab the text from character 1 to math.floor(message_box_caret_position). This will print it in one character at a time like you see in all RPGs.

Re: Textbox Help

Posted: Thu Jun 05, 2014 10:21 am
by Roland_Yonaba
Maybe a shorter alternative ?

Code: Select all

local function split(str, delim)
  local splits = {}
  for w in str:gmatch('[^'..delim..']+') do splits[#splits+1] = w end
  return splits
end