Page 1 of 1
I searched but no answer so I have to come here and asking this coding problem
Posted: Fri Oct 16, 2020 5:42 pm
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
Re: I searched but no answer so I have to come here and asking this coding problem
Posted: Fri Oct 16, 2020 8:08 pm
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:
- The new text to draw
- The number of pixels before wrapping
- 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?
Re: I searched but no answer so I have to come here and asking this coding problem
Posted: Sat Oct 17, 2020 12:43 am
by Flandre
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(...)
Re: I searched but no answer so I have to come here and asking this coding problem
Posted: Sat Oct 17, 2020 1:20 am
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)
Re: I searched but no answer so I have to come here and asking this coding problem
Posted: Sat Oct 17, 2020 1:35 am
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
Re: I searched but no answer so I have to come here and asking this coding problem
Posted: Sat Oct 17, 2020 1:59 am
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
Re: I searched but no answer so I have to come here and asking this coding problem
Posted: Sat Oct 17, 2020 2:19 am
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
Re: I searched but no answer so I have to come here and asking this coding problem
Posted: Sat Oct 17, 2020 8:06 am
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.
Re: I searched but no answer so I have to come here and asking this coding problem
Posted: Sat Oct 17, 2020 7:00 pm
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?
Re: I searched but no answer so I have to come here and asking this coding problem
Posted: Mon Oct 19, 2020 7:19 am
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.