Advertisement

Lua: Attempt to index a string value

Started by July 25, 2004 10:51 AM
1 comment, last by GameDev.net 20 years, 4 months ago
This is the most obscure error message I have ever had... Google turns up nothing on it. Here's the deal:

World = { 
  Room = { file = "thing.lua" }, 
} 

So, a table World contains a table Room which contains a string 'file'. At some point, I want to do this:

dofile(World.Room.file) 

But alas, no. I get the wondrous "Attempt to index a string value" message. The bizarre thing is that I can change the string's name to various other things, and then it -does- work. So with some names it works, with some names it doesn't. And these names aren't already defined, I used countless bizarre unique names to try it out. For instance, World.Room.scr, World.Room.BLARGH, World.Room.IWillNotBeDenied work, and the file gets loaded, while when I name it World.Room.DAMN, World.Room.test, World.Room.Scri or other various names, it doesn't work. What in the name of Lua is going on here? And what the hell does "Attempt to index a string value" mean?
Nein heer du smign. ah open up the nine im heer du shmine
Not sure why you're getting that error...because it works fine for me:
C:\src\lua-5.0.2\bin>copy con thing.luaprint "thing.lua successfully ran!"^Z        1 file(s) copied.C:\src\lua-5.0.2\bin>luaLua 5.0.2  Copyright (C) 1994-2004 Tecgraf, PUC-Rio> World = {>>   Room = { file = "thing.lua" },>> }> dofile(World.Room.file)thing.lua successfully ran!>

Maybe if you gave us some more context we could help find what's going on.
Advertisement
dofile(World.Room.file)

should probably be

dofile(World.Room["file"])

This topic is closed to new replies.

Advertisement