Seif Posted July 24, 2010 Share Posted July 24, 2010 I encountered a few problems with getElementData and mysql_escape_string. For some odd reason, this line is giving me 2 warning/errors: local name = mysql_escape_string(serversql, getElementData(id, "name")) mysql_escape_string is from a module but it's well used. The error says "Bad Argument @ 'getElementData'". How? "id" is going through a loop under an element that I created. for id in ipairs(getElementsByType("customelement")) do And of course the element is created before the function is called(this is called when the resource stops and the element is created when the resource starts). That's how I made it: local id = createElement("customelement", row[2]) What is wrong? My other problem is pretty similar. when I try to compare getElementData, it says also bad argument. I suppose it's related. Link to comment
Mr.Hankey Posted July 24, 2010 Share Posted July 24, 2010 What does the table/array you loop through look like? When looping through arrays in lua you usually use "for key, value in ipairs [...]" I don't know if you didn't specify a variable for holding the value of the current on purpouse but in any case "id" will always hold the key(index) to an array's field. Link to comment
Seif Posted July 24, 2010 Author Share Posted July 24, 2010 Hm I fixed the problem. I had to put _, before defining the loop variable. Link to comment
Mr.Hankey Posted July 25, 2010 Share Posted July 25, 2010 I'd still sugget you to take a look at these two tutorials: http://lua-users.org/wiki/TablesTutorial http://lua-users.org/wiki/ForTutorial Link to comment
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