I searched but no answer so I have to come here and asking this coding problem

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
Flandre
Prole
Posts: 7
Joined: Fri Oct 16, 2020 5:28 pm

I searched but no answer so I have to come here and asking this coding problem

Post by Flandre »

Hi everyone hope this is simple.....

temp1="first neko"
nn1=love.graphics.newText(font,tostring(temp1))
nn1=nn1:setf("111",500)

always report argument #3 to 'setf' (string expected, got no value)

Do I have a understanding-problem with "textstring" of "Text:setf( textstring, wraplimit, alignmode )"?

Another thing I want to know is is there a way to format (word wrap) text object directly, without replacing text-content like Text:setf does?

Sorry for my English :( Any understanding-problems just let me know.

Edit:
Nixola wrote: Sat Oct 17, 2020 8:06 am That's a quintuple post. Don't do that. If you have something to add, you can edit your own posts; please don't post several times in a row.
Ah...I didn't know that, really sorry, now I know, not again, thank you Nixola :)
Last edited by Flandre on Sat Oct 17, 2020 12:58 pm, edited 2 times in total.
Xugro
Party member
Posts: 114
Joined: Wed Sep 29, 2010 8:14 pm

Re: I searched but no answer so I have to come here and asking this coding problem

Post by Xugro »

Flandre wrote: Fri Oct 16, 2020 5:42 pm always report argument #3 to 'setf' (string expected, got no value)
If you take a look at the wiki entry for Text:setf: You need to give the function three parameters:
  1. The new text to draw
  2. The number of pixels before wrapping
  3. And the alignment of the text (left, right center or justify)
The error even says so: argument #3 (alignmode) is missing. The function expects as string (e.g. "left"), but there was no third argument.
Flandre wrote: Fri Oct 16, 2020 5:42 pm Another thing I want to know is is there a way to format (word wrap) text object directly, without replacing text-content like Text:setf does?
Personally: I do not know. Can you expand on this: What do you want to achieve?
Flandre
Prole
Posts: 7
Joined: Fri Oct 16, 2020 5:28 pm

Re: I searched but no answer so I have to come here and asking this coding problem

Post by Flandre »

Xugro wrote: Fri Oct 16, 2020 8:08 pm If you take a look at the wiki entry for Text:setf: You need to give the function three parameters:
I added 3rd parameter (I deleted it before post problem on forum because I saw it still reports same error.) I tried it again in past seconds and still reports....ok, a little difference, it reports bad argument #3 to 'setf' (string expected, got nil)

temp1="first neko"
nn1=love.graphics.newText(font,tostring(temp1))
nn1=nn1:setf("111",500,left)
Xugro wrote: Fri Oct 16, 2020 8:08 pm Personally: I do not know. Can you expand on this: What do you want to achieve?
I mean, like:
somewords=love.graphics.newText(...)
somewords=somewords:setf(wraplimit), not include using a new text to replace original text.

or just:
somewords=love.graphics.newFormatText(...)
Flandre
Prole
Posts: 7
Joined: Fri Oct 16, 2020 5:28 pm

Re: I searched but no answer so I have to come here and asking this coding problem

Post by Flandre »

Anyone could run this scrpit

font = love.graphics.getFont()
font = love.graphics.setNewFont(24)
nn1=love.graphics.newText(font,"222")
nn1=nn1:setf("111",500,left)

always reports: main.lua:4: bad argument #3 to 'setf' (string expected, got nil)
Flandre
Prole
Posts: 7
Joined: Fri Oct 16, 2020 5:28 pm

Re: I searched but no answer so I have to come here and asking this coding problem

Post by Flandre »

Ok......Thanks for Xugro, All the thanks to you, I understand, needs "left" not left, now works, thank you, thank you! now everything be fine :)
Flandre
Prole
Posts: 7
Joined: Fri Oct 16, 2020 5:28 pm

Re: I searched but no answer so I have to come here and asking this coding problem

Post by Flandre »

For others, codes still has a incorrect point, should using nn1:seft() not nn1=nn1:setf() because Text:setf() returns nothing that makes nn1 = nothing.

temp1="first neko ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss"
nn1=love.graphics.newText(font,tostring(temp1))
nn1:setf(tostring(temp1),500,"left")
function love.draw()
love.graphics.draw(nn1,0,0)
end
Last edited by Flandre on Sat Oct 17, 2020 2:30 am, edited 1 time in total.
Flandre
Prole
Posts: 7
Joined: Fri Oct 16, 2020 5:28 pm

Re: I searched but no answer so I have to come here and asking this coding problem

Post by Flandre »

Building newFormatTextObject dircetly function eg.

function love.graphics.newFText(cfont,ctext,textObjectName)
textObjectName=love.graphics.newText(cfont,tostring(ctext))
textObjectName:setf(tostring(ctext),500,"left")
return textObjectName
end

nn2=love.graphics.newFText(font,temp1,nn2)
function love.draw(...)
love.graphics.draw(nn2,0,0)
end
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: I searched but no answer so I have to come here and asking this coding problem

Post by Nixola »

That's a quintuple post. Don't do that. If you have something to add, you can edit your own posts; please don't post several times in a row.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Xugro
Party member
Posts: 114
Joined: Wed Sep 29, 2010 8:14 pm

Re: I searched but no answer so I have to come here and asking this coding problem

Post by Xugro »

Flandre wrote: Sat Oct 17, 2020 12:43 am
Xugro wrote: Fri Oct 16, 2020 8:08 pm Personally: I do not know. Can you expand on this: What do you want to achieve?
I mean, like:
somewords=love.graphics.newText(...)
somewords=somewords:setf(wraplimit), not include using a new text to replace original text.

or just:
somewords=love.graphics.newFormatText(...)
Okay, that I understand. But why do you want to do that? What effect do you want to achieve? Do you need a resizeable textbox?
Flandre
Prole
Posts: 7
Joined: Fri Oct 16, 2020 5:28 pm

Re: I searched but no answer so I have to come here and asking this coding problem

Post by Flandre »

Xugro wrote: Sat Oct 17, 2020 7:00 pm Okay, that I understand. But why do you want to do that? What effect do you want to achieve? Do you need a resizeable textbox?
Um, long text will be out of textbox(with a fixed size) if without word wrap, anyway it can build a function for the problem so doesn't matter anymore, it may be better but also may be same performance if love2D has its own function for that, so it's ok with custom function for sloving it, and, is the only way if love2d doesn't have its own function for that.

Add:What I want is a text-based game, maybe with many textboxs sametime on the screen.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 1 guest