Textbox Help

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
squidborne_destiny
Prole
Posts: 8
Joined: Wed May 28, 2014 8:32 pm

Textbox Help

Post 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.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Textbox Help

Post by Roland_Yonaba »

Take a look at Litearc's Navi.
And welcome to LÖVE.
User avatar
squidborne_destiny
Prole
Posts: 8
Joined: Wed May 28, 2014 8:32 pm

Re: Textbox Help

Post by squidborne_destiny »

Roland_Yonaba wrote:Take a look at Litearc's Navi.
And welcome to LÖVE.
Thanks!
User avatar
squidborne_destiny
Prole
Posts: 8
Joined: Wed May 28, 2014 8:32 pm

Re: Textbox Help

Post 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.
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: Textbox Help

Post by davisdude »

Sure.

Code: Select all

String = 'This is my string'
Part1 = String:sub( 1, 4 ) -- "This"
Part2 = String:sub( 6, 7 ) -- "is"
-- etc.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
User avatar
Jasoco
Inner party member
Posts: 3727
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Textbox Help

Post 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.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Textbox Help

Post 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
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 11 guests