Page 19 of 91

Re: "Questions that don't deserve their own thread" thread

Posted: Fri Sep 12, 2014 12:56 pm
by Zilarrezko
rmcode wrote:
Zilarrezko wrote: Yeah, there's no mention of it in the source code

But there's a reference if you want to know the other stuff.
Is this the reference you mean? Or is there another one?
When you click the "source code" words, it will take you to Löve's graphics.lua source code (In fact I believe right to the place where it defines them) that defines lua's global shader variables, and their GLSL equivalents next to them. Along with the ones that you just linked.

Re: "Questions that don't deserve their own thread" thread

Posted: Fri Sep 12, 2014 2:34 pm
by ELFUERTE
So I got this class in my game. If I try to require the lua file that contains the class,it returns a nil value.
Here's the class I'm talking about.

Re: "Questions that don't deserve their own thread" thread

Posted: Fri Sep 12, 2014 2:55 pm
by rmcode
ELFUERTE wrote:So I got this class in my game. If I try to require the lua file that contains the class,it returns a nil value.
Here's the class I'm talking about.
<snip> Apparently I was wrong. See post below.

Re: "Questions that don't deserve their own thread" thread

Posted: Fri Sep 12, 2014 2:58 pm
by Robin
ELFUERTE wrote:So I got this class in my game. If I try to require the lua file that contains the class,it returns a nil value.
Here's the class I'm talking about.
So do you define Boy somewhere? The problem is probably that line 10 and 11 need to be in a function that is called at the start of the map.

Also, please upload the whole .love if you want a better answer than this.

EDIT: rmcode, you're wrong. They both work and in fact the notation with the dot instead of the slash is the canonical way.

Re: "Questions that don't deserve their own thread" thread

Posted: Fri Sep 12, 2014 3:24 pm
by ELFUERTE
Here's the love file.

Re: "Questions that don't deserve their own thread" thread

Posted: Fri Sep 12, 2014 3:28 pm
by rmcode
Robin wrote:
ELFUERTE wrote: EDIT: rmcode, you're wrong. They both work and in fact the notation with the dot instead of the slash is the canonical way.
Thanks for clearing that up - edited my previous post.

I come from a modding background where Lua didn't work like it does with Löve (require didn't return the module for example). I'm now trying to learn "proper" Lua.

Re: "Questions that don't deserve their own thread" thread

Posted: Fri Sep 12, 2014 4:27 pm
by Zilarrezko
ELFUERTE wrote:Here's the love file.
Alright man, so I got the map to pop up. After 24 hours up straight doing other coding my minds a bit bogged down, so I'm just going to give straight up answers rather than explaining them too much.

first, The variable scope is wrong.

Code: Select all

function love.load()
	local level = {require "DesertExample"} --carica tutti i livelli          
	local num = 0                  -- Mappa in cui siamo
	global={}                   
	global.tX = 0                  --Variabili di traslazione
	global.tY = 0
end
when you say "local", the variable/array is only visible in that function. So love.draw and love.keypressed. Just any function other than love.load can't see the "level" array, or the "num" variable

second, How you reference the index of the array level doesn't work in Lua. You must be from any other language in existence that uses base 0 for it's first index. Lua starts it's index's at 1, so changing num from 0 to 1 will fix that.

here's your code...

Re: "Questions that don't deserve their own thread" thread

Posted: Fri Sep 12, 2014 4:40 pm
by ELFUERTE
Zilarrezko wrote:
ELFUERTE wrote:Here's the love file.
Alright man, so I got the map to pop up. After 24 hours up straight doing other coding my minds a bit bogged down, so I'm just going to give straight up answers rather than explaining them too much.

first, The variable scope is wrong.

Code: Select all

function love.load()
	local level = {require "DesertExample"} --carica tutti i livelli          
	local num = 0                  -- Mappa in cui siamo
	global={}                   
	global.tX = 0                  --Variabili di traslazione
	global.tY = 0
end
when you say "local", the variable/array is only visible in that function. So love.draw and love.keypressed. Just any function other than love.load can't see the "level" array, or the "num" variable

second, How you reference the index of the array level doesn't work in Lua. You must be from any other language in existence that uses base 0 for it's first index. Lua starts it's index's at 1, so changing num from 0 to 1 will fix that.

here's your code...
Thanks a lot man. I have no idea why i made that mistake with the index. So sorry. You're great tho. Good luck with your project :o !

Re: "Questions that don't deserve their own thread" thread

Posted: Fri Sep 12, 2014 7:32 pm
by megalukes
Quick question. I have the following folders.

-editor
->main.lua
-game
->tilemap.lua

I need to make a require(tilemap) from that main.lua file, but I'm not sure how since they are in different folders. Any help would be appreciated. Thanks!

Re: "Questions that don't deserve their own thread" thread

Posted: Fri Sep 12, 2014 7:36 pm
by Cryogenical
megalukes wrote:Quick question. I have the following folders.

-editor
->main.lua
-game
->tilemap.lua

I need to make a require(tilemap) from that main.lua file, but I'm not sure how since they are in different folders. Any help would be appreciated. Thanks!
In your main, type

Code: Select all

require "game/tilemap"