Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Zilarrezko
Party member
Posts: 345
Joined: Mon Dec 10, 2012 5:50 am
Location: Oregon

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.

ELFUERTE
Prole
Posts: 7
Joined: Fri Sep 12, 2014 2:29 pm

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.

rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

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.
Last edited by rmcode on Fri Sep 12, 2014 3:26 pm, edited 1 time in total.

Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

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.

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

ELFUERTE
Prole
Posts: 7
Joined: Fri Sep 12, 2014 2:29 pm

Here's the love file.

rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

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.

Zilarrezko
Party member
Posts: 345
Joined: Mon Dec 10, 2012 5:50 am
Location: Oregon

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.

Attachments
BOXSTI_Fix.zip
Have fun, don't do drugs, and all that crud.

ELFUERTE
Prole
Posts: 7
Joined: Fri Sep 12, 2014 2:29 pm

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.

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 !

megalukes
Citizen
Posts: 91
Joined: Fri Jun 27, 2014 11:29 pm
Location: Brazil

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!

Cryogenical
Prole
Posts: 49
Joined: Mon Apr 28, 2014 5:23 pm

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!
require "game/tilemap"