Snoozy Posted January 8, 2011 Posted January 8, 2011 I got a problem with attempting to store data. VehicleInfo = {}; I'm currently creating a vehicle loading system but have been having problems making it work so I've debugged every single line in the loading and now I have reached a part I'm unable to fix. The location that I receive this error is: VehicleInfo[idx].VehID = row[1] There are serveral of those ofcourse but that is the first and that's where the error starts. The loading is all fine I tried outputting to chatbox the value of row[1] and it was 1 as supposed.
Antibird Posted January 8, 2011 Posted January 8, 2011 The loading is all fine I tried outputting to chatbox the value of row[1] and it was 1 as supposed. Then, by some reasons, 'VehicleInfo[idx]' is not a table even while 'VehicleInfo' is.
Snoozy Posted January 8, 2011 Author Posted January 8, 2011 Do I have to define VehicleInfo[idx] of some sort? If so mind showing me how or giving me a hint?
SDK Posted January 8, 2011 Posted January 8, 2011 Yes, VehicleInfo[idx] is nil, so you're trying to get nil["VehID"] which is impossible. You need to define a table inside the first table: VehicleInfo = {} .... VehicleInfo[idx] = {} VehicleInfo[idx].VehID = row[1] ... Learn Lua - Learn to script - GUI scripting Scripter tools - Find/fix errors yourself(!) Don't pm me for scripting help, keep it for the Scripting subforum!
Snoozy Posted January 8, 2011 Author Posted January 8, 2011 Just tried to do following, don't know if that's what you mean tho: for idx=1, maxve do VehicleInfo[idx] = {}; A bit later up in the script after a few querys and if statements VehicleInfo[idx][VehID] = row[1] Tho now I receive the error: table index is nil EDIT: and also VehicleInfo = {}; is at start of the whole function
Moderators Zango Posted January 8, 2011 Moderators Posted January 8, 2011 table index is nil > VehicleInfo[idx][VehID] = row[1]
SDK Posted January 8, 2011 Posted January 8, 2011 Yes, but now you changed your index name, that's some basic Lua table stuff. VehicleInfo[idx].VehID = row[1] -- this is the same as : VehicleInfo[idx]["VehID"] = row[1] -- but NOT the same as: VehicleInfo[idx][VehID] = row[1] Learn Lua - Learn to script - GUI scripting Scripter tools - Find/fix errors yourself(!) Don't pm me for scripting help, keep it for the Scripting subforum!
Snoozy Posted January 8, 2011 Author Posted January 8, 2011 Doh... just doh didn't notice that it was [VehID] and not ["VehID"] haha sorry. Thanks
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now