Page 1 of 1

Lua Syntax and Drawing a Canvas (Solved)

Posted: Sat Dec 06, 2014 4:55 am
by NotAUsername
I'm kinda' new to both lua and love, so I don't completely know how lua syntax, or the love API, work in every situation.

I'm trying to have everything be drawn to a canvas, then the canvas drawn to the window and stretched to fit it. To do this, I draw the canvas with a scaling factor of the window's dimensions divided by the canvas' dimensions. No matter what I do, my code produces errors.

Here's the line I'm having problems with:

Code: Select all

love.graphics.draw(mainCanvas, 0, 0, 0, love.window.getWidth/mainCanvas:getWidth, love.window.getHeight/mainCanvas:getHeight)
This produces "function arguments expected near ',' " (Keep in mind, this is all one line in the actual code)

First of all, what does this mean? Can I use functions inside other functions? If I can, am I doing it right?
Even if I assign the values of the functions in question to variables first, then use the variables in the draw function, it still produces errors.

Re: Lua Syntax and Drawing a Canvas

Posted: Sat Dec 06, 2014 7:07 am
by Jasoco
Well, first off you forgot the parenthesis in all cases of getHeight and getWidth.

If you just try to call love.graphics.getWidth, it's not going to work because it's not a variable. It's a function. In order to get it to return the value you want you need to call it like a function. getWidth(). Same goes for everything that's a function.

Re: Lua Syntax and Drawing a Canvas

Posted: Sat Dec 06, 2014 3:55 pm
by NotAUsername
I fixed the parentheses problem, but I got the same result. Same error and everything.

Never mind, I fixed it!

Re: Lua Syntax and Drawing a Canvas

Posted: Sat Dec 06, 2014 4:11 pm
by Doctory
can't you just make the canvas size the same as the window size and then change the size if the window is resized?

Re: Lua Syntax and Drawing a Canvas

Posted: Sat Dec 06, 2014 4:32 pm
by NotAUsername
I don't think that'll work because then you have to resize everything as it's drawn to the canvas to get the same effect, and at that point you might as well just draw straight to the window.

Re: Lua Syntax and Drawing a Canvas (Solved)

Posted: Sun Dec 07, 2014 1:04 pm
by DaedalusYoung