Table Reference Issue

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.
Post Reply
User avatar
hartste90
Prole
Posts: 3
Joined: Wed Jan 25, 2012 12:03 am
Location: Baltimore, MD

Table Reference Issue

Post by hartste90 »

Hey smart people -
I have attached my .love file to make my description make sense
I'm a web application developer trying my hand at game development and I stumbled upon the Love Engine for my first go at it! But I'm having some trouble - I'm trying to write a simple typing game (ignore cheezyness please) where words fall and you have to type them correctly before they reach the bottom of the screen.
The words on screen are held in an array - I'm very familiar with arrays but not with Lua. There seems to be an error popping up in the ' keypressed' function.

When the user enters the first letter of one of the activeWords it should look through the array at all the first letters and see if they match - but the errors stops the execution and I cannot figure out how to debug it by printing to the error screen.

-Can anyone tell me how to debug the code (i.e. print to a console or error page)
-See if you can figure out what the error indicates in the code? I've attached my zipped .love file to this post

-Thanks in advance for the help!
Attachments
game.love.zip
Here is the zipped .love file.
(2.22 MiB) Downloaded 170 times
----
LoL name: ADarkWind
Starcraft2: Axel
----
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Table Reference Issue

Post by Robin »

hartste90 wrote:-Can anyone tell me how to debug the code (i.e. print to a console or error page)
Start a terminal and run LÖVE from there.
hartste90 wrote:-See if you can figure out what the error indicates in the code? I've attached my zipped .love file to this post
The issue is here:

Code: Select all

			nextLetter = activeWords[i][1];
You see, you try to extract a letter from a string by indexing it. In Lua, a string is not a table, so you should replace it with:

Code: Select all

			nextLetter = activeWords[i]:sub(1,1)
(See string.sub in the Lua manual.)

There are other things in your code: lots of global variables that shouldn't be global (like nextLetter), you use table.getn(), which is deprecated, use the # operator instead:

Code: Select all

for i = 1, #activeWords do
Also, could you please zip the contents of your folder rather than the folder itself? Then you can rename it to a .love and we can run it directly instead of having to extract the contents first.
Help us help you: attach a .love.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Table Reference Issue

Post by Nixola »

Robin wrote: Start a terminal and run LÖVE from there.
Unless you're on Windows. In that case, create a file, call it "conf.lua", place it in the same folder as your main.lua and put the following code in it:

Code: Select all

love.conf = function(t)
t.console = true
end
Then, if you want to print something in the console, simply use print(something)
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Table Reference Issue

Post by Robin »

But OP is on a Mac, so that's not relevant for them. ;)
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests