Hi all,
Having a strange problem printing variables to screen using love.graphics.print.
I want to print the current screen resolution to the screen in the settings menu,
I am getting the variables with the following
local resolutionw = love.graphics.getWidth()
local resolutionh = love.graphics.getHeight()
and am trying to print it to screen with
love.graphics.print(tostring(resolutionw)..' x '..tostring(resolutionh), WINDOW_WIDTH / 3 + BUTTON_WIDTH / 2 + margin, WINDOW_HEIGHT / 3 + (BUTTON_HEIGHT / 2 + margin) * 2)
however all I am getting is
' x '
however, just above it
local fscreen = love.window.getFullscreen()
love.graphics.print(tostring(fscreen), WINDOW_WIDTH / 3 + BUTTON_WIDTH / 2 + margin, WINDOW_HEIGHT / 3 + (BUTTON_HEIGHT / 2 + margin))
works just fine.
Printing normal text to the screen works just fine as well. It seems to be just variables.
If I start a clean project these work just fine.
If someone has ran into the same troubles, please point me in the direction of fixing it.
love.graphics.print troubles
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: love.graphics.print troubles
Are you doing something else to "resolutionw" and/or "resolutionh" in-between their declarations and their print function?
Re: love.graphics.print troubles
Try this
Instead of this.
http://lua-users.org/wiki/ScopeTutorial
Code: Select all
resolutionw = love.graphics.getWidth()
resolutionh = love.graphics.getHeight()
Code: Select all
local resolutionw = love.graphics.getWidth()
local resolutionh = love.graphics.getHeight()
Re: love.graphics.print troubles
That's very strange. The only way of obtaining that result is if resolutionw and resolutionh are both empty strings, "". If they were unassigned, you would get something like 'nil x nil' instead.
Is it possible that you're initializing them to the empty string somewhere? Where are you setting resolutionw and resolutionh? Could you provide some more context for that code?
The best explanation for that behaviour is that you're doing something like this:
Code: Select all
local resolutionw = ""
local resolutionh = ""
...
function love.load()
...
local resolutionw = love.graphics.getWidth()
local resolutionh = love.graphics.getHeight()
...
end
function love.draw()
...
love.graphics.print(tostring(resolutionw) .. " x " .. tostring(resolutionh), ...)
...
end
If not, we'll need more context in order to understand what's going on.
Re: love.graphics.print troubles
Thank you all for the replies.
You guys are awesome.
I found the problem, and it has nothing to do with love.graphics.print failing at all.
I have a custom font setup in main.lua for all my printing needs and from all the ones I downloaded and checked as possibilities, I had to go and choose the one that had no numbers indicated in the .ttf.
Just my damn luck. Oh well, lessons learned I guess. Always check your fonts.
You guys are awesome.
I found the problem, and it has nothing to do with love.graphics.print failing at all.
I have a custom font setup in main.lua for all my printing needs and from all the ones I downloaded and checked as possibilities, I had to go and choose the one that had no numbers indicated in the .ttf.
Just my damn luck. Oh well, lessons learned I guess. Always check your fonts.
Who is online
Users browsing this forum: Google [Bot], Semrush [Bot] and 3 guests