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

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Locked
User avatar
Zilarrezko
Party member
Posts: 345
Joined: Mon Dec 10, 2012 5:50 am
Location: Oregon

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

Post by Zilarrezko » Fri Sep 12, 2014 12:56 pm

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

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

Post by ELFUERTE » Fri Sep 12, 2014 2:34 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.

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

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

Post by rmcode » Fri Sep 12, 2014 2:55 pm

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.

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

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

Post by Robin » Fri Sep 12, 2014 2:58 pm

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.
Help us help you: attach a .love.

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

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

Post by ELFUERTE » Fri Sep 12, 2014 3:24 pm

Here's the love file.

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

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

Post by rmcode » Fri Sep 12, 2014 3:28 pm

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.

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

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

Post by Zilarrezko » Fri Sep 12, 2014 4:27 pm

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...
Attachments
BOXSTI_Fix.zip
Have fun, don't do drugs, and all that crud.
(93.21 KiB) Downloaded 35 times

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

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

Post by ELFUERTE » Fri Sep 12, 2014 4:40 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.

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 !

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

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

Post by megalukes » Fri Sep 12, 2014 7:32 pm

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!

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

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

Post by Cryogenical » Fri Sep 12, 2014 7:36 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!
In your main, type

Code: Select all

require "game/tilemap"

Locked

Who is online

Users browsing this forum: No registered users and 13 guests