Page 1 of 2

Problem with register[]

Posted: Sun Jan 11, 2015 12:14 am
by Gold_Car
I've been working on an experiment in LOVE which comes from a tutorial I found. I'm very new to Lua and Love, so watching the tutorial and just doing what the teacher does is the only way for me to get anything done.

The problem is, the video series is fairly old and since then, Love updated to 0.9.1, and broke a lot of the syntax. I've already had problems with require, which I have since fixed by changing the syntax. Now I've got a problem with what I believe to be this piece of code.

Code: Select all

function ents.Startup()
	register["box"] = love.filesystem.load( ents.objpath .. "box" )
end
I've set up the console to print "The entity called Box isn't real." if the game doesn't recognize the box.lua file as a real thing. Here's the thing, though. In the main.lua file I have these:

Code: Select all

if love.filesystem.isDirectory("entityobjects") then
		print("Found the entity folder.")
	end
	if love.filesystem.isFile("entityobjects/base.lua") then
		print("Found the base.lua.")
	end
	if love.filesystem.isDirectory("texturesofthings") then
		print("Found the texture folder.")
	end
	if love.filesystem.isFile("entityobjects/box.lua") then
		print("Found the box.lua.")
	end
They all evaluate to true. My guess is that I just have the syntax wrong with the register thingy. What's the correct syntax for it?

Re: Problem with register[]

Posted: Sun Jan 11, 2015 12:40 am
by davisdude
The problem is that you aren't calling ents.startup().
Because of that, the table index is never created.
Make sure to add ents.startup to you love.load function before ents.create.

Re: Problem with register[]

Posted: Sun Jan 11, 2015 1:06 am
by Gold_Car
I just tried that. I've put ents.startup() into the main lua file. Unfortunately, now the game turns into a blue screen.

This is what it says.
Error

main.lua:26: attempt to call field 'startup' (a nil value)

Traceback

main.lua:26: in function 'load'
[C]: in function 'xpcall'
I don't quite understand what it means.

Re: Problem with register[]

Posted: Sun Jan 11, 2015 1:56 am
by davisdude
I'm sorry, I meant to type "ents.Startup"

Re: Problem with register[]

Posted: Sun Jan 11, 2015 2:17 am
by Gold_Car
davisdude wrote:I'm sorry, I meant to type "ents.Startup"
I tried both of these:

Code: Select all

ents.Startup()
	local boxEnt = ents.Create( "box", 128, 128 )

Code: Select all

ents.Startup
	local boxEnt = ents.Create( "box", 128, 128 )
Neither worked. I got bluescreen again. This is very odd.

For the Startup that does have the brackets afterward, the error tells me that objpath is a nil value.

Re: Problem with register[]

Posted: Sun Jan 11, 2015 4:14 am
by davisdude
Two problems:
- When you use love.filesystem.load you need to put .lua at the end of the file.
- ents.objpath needs to have quotation marks and a backslash. In other words, do:

Code: Select all

ents.objecpath = "entityobjects/"
By the way, it's a lot more helpful to us if you post the actual errors you get.

Re: Problem with register[]

Posted: Sun Jan 11, 2015 4:50 am
by Gold_Car
davisdude wrote:Two problems:
- When you use love.filesystem.load you need to put .lua at the end of the file.
- ents.objpath needs to have quotation marks and a backslash. In other words, do:

Code: Select all

ents.objecpath = "entityobjects/"
By the way, it's a lot more helpful to us if you post the actual errors you get.
Actually, when I use ents.objpath = (entityobjects/) it makes the game crash, every time; whereas without it, the game would normally run fine.

Also, is it objecpath or objpath? I'm getting a bit of conflicting information here.

Re: Problem with register[]

Posted: Sun Jan 11, 2015 4:53 am
by davisdude
That's because you need to use quotation marks " not parenthesis (
And I'm assuming it's objpath, but I would need the tutorial you're watching to be sure.

Re: Problem with register[]

Posted: Sun Jan 11, 2015 5:20 am
by Gold_Car
davisdude wrote:That's because you need to use quotation marks " not parenthesis (
And I'm assuming it's objpath, but I would need the tutorial you're watching to be sure.
Thanks for that. I changed the punctuation and now the game doesn't crash anymore. The console log still tells me that the box isn't real, but at least the game isn't white text on a blue screen anymore.

Here's the tutorial.
https://www.youtube.com/watch?v=L9G0WyG ... B05A624D91
Sorry for being late with that one.

Goature's help really got thrown off track for me when version 0.9.1 broke his code.

Re: Problem with register[]

Posted: Sun Jan 11, 2015 2:44 pm
by davisdude
Here. This has all of the changes I showed you in the previous posts. Look at main.lua an entities.lua to see what I changed.