🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Lua: Attempt to index a string value

Started by
1 comment, last by GameDev.net 19 years, 11 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
Advertisement
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.
dofile(World.Room.file)

should probably be

dofile(World.Room["file"])

This topic is closed to new replies.

Advertisement