Winstrol Posted April 28, 2020 Share Posted April 28, 2020 (edited) Hello everyone! I'm 100% newbie in Lua coding, I'm trying to learn Lua language. To the point.. I'm trying connect my gamemode to MySQL, but data to connect with database, I want to get from file, or meta.xml. dbname = get("start.dbname") host = get("start.host") charset = get("start.charset") user = get("start.username") pass = get("start.password") share = get("start.share") batch = get("start.batch") autorec = get("start.autoreconnect") logs = get("start.logs") db = dbConnect("mysql", "dbname="..dbname..";host="..host..";charset="..charset.."", ""..user.."", ""..pass.."", "share="..share.."", "batch="..batch.."", "autoreconnect="..autorec.."", "log="..logs.."") Server console shows me an error. Quote start.Lua:13: attempt to concatenate global 'charset' (a boolean value) My meta.xml <settings> <setting name="dbname" value="database" /> <setting name="host" value="127.0.0.1" /> <setting name="charset" value="utf8" /> <setting name="username" value="root" /> <setting name="password" value="" /> <setting name="share" value="1" /> <setting name="batch" value="0" /> <setting name="autoreconnect" value="1" /> <setting name="log" value="1" /> </settings> I don't have any idea for do this thing. Only one way is xmlFindChild/xmlLoadString, etc.? Edited April 28, 2020 by Winstrol Link to comment
aka Blue Posted April 28, 2020 Share Posted April 28, 2020 For settings you can use get without any problem. Take a look here: https://wiki.multitheftauto.com/wiki/Settings_system Link to comment
Winstrol Posted April 29, 2020 Author Share Posted April 29, 2020 My mistake. Not in the meta.xml file, but in the settings.xml file. Quote attempt to concatenate global 'charset' (a boolean value) Link to comment
Moderators IIYAMA Posted April 29, 2020 Moderators Share Posted April 29, 2020 2 hours ago, Winstrol said: Not in the meta.xml file, but in the settings.xml file Then you will need xml functions. If you added the file as a config file in the meta.xml, then you can get the file like this: https://wiki.multitheftauto.com/wiki/GetResourceConfig Else you will need this function https://wiki.multitheftauto.com/wiki/XmlLoadFile All of them -> https://wiki.multitheftauto.com/wiki/Xmlnode Link to comment
Winstrol Posted April 30, 2020 Author Share Posted April 30, 2020 (edited) local loadConfig = xmlLoadFile(":startup/dbconfig.xml", true) local findGroup = xmlFindChild(loadConfig, "config", 0) 7: local dbname = xmlFindChild(findGroup, "dbname", 0) 8: local host = xmlFindChild(findGroup, "host", 0) 9: local charset = xmlFindChild(findGroup, "charset", 0) 10: local user = xmlFindChild(findGroup, "username", 0) 11: local pass = xmlFindChild(findGroup, "password", 0) 12: local share = xmlFindChild(findGroup, "share", 0) 13: local batch = xmlFindChild(findGroup, "batch", 0) 14: local autorec = xmlFindChild(findGroup, "autoreconnect", 0) 15: local logs = xmlFindChild(findGroup, "log", 0) 17: xmlUnloadFile(loadConfig) 19: db = dbConnect("mysql", "dbname="..xmlNodeGetValue(dbname)..";host="..xmlNodeGetValue(host)..";charset="..xmlNodeGetValue(charset).."", ""..xmlNodeGetValue(user).."", ""..xmlNodeGetValue(pass).."", "share="..xmlNodeGetValue(share).."", "batch="..xmlNodeGetValue(batch).."", "autoreconnect="..xmlNodeGetValue(autorec).."", "log="..xmlNodeGetValue(logs).."") Quote [2020-04-30 08:28:03] WARNING: startup\start.Lua:7: Bad argument @ 'xmlFindChild' [Expected xml-node at argument 1, got boolean] [2020-04-30 08:28:03] WARNING: startup\start.Lua:8: Bad argument @ 'xmlFindChild' [Expected xml-node at argument 1, got boolean] [2020-04-30 08:28:03] WARNING: startup\start.Lua:9: Bad argument @ 'xmlFindChild' [Expected xml-node at argument 1, got boolean] [2020-04-30 08:28:03] WARNING: startup\start.Lua:10: Bad argument @ 'xmlFindChild' [Expected xml-node at argument 1, got boolean] [2020-04-30 08:28:03] WARNING: startup\start.Lua:11: Bad argument @ 'xmlFindChild' [Expected xml-node at argument 1, got boolean] [2020-04-30 08:28:03] WARNING: startup\start.Lua:12: Bad argument @ 'xmlFindChild' [Expected xml-node at argument 1, got boolean] [2020-04-30 08:28:03] WARNING: startup\start.Lua:13: Bad argument @ 'xmlFindChild' [Expected xml-node at argument 1, got boolean] [2020-04-30 08:28:03] WARNING: startup\start.Lua:14: Bad argument @ 'xmlFindChild' [Expected xml-node at argument 1, got boolean] [2020-04-30 08:28:03] WARNING: startup\start.Lua:15: Bad argument @ 'xmlFindChild' [Expected xml-node at argument 1, got boolean] [2020-04-30 08:28:03] WARNING: startup\start.Lua:19: Bad argument @ 'xmlNodeGetValue' [Expected xml-node at argument 1, got boolean] [2020-04-30 08:28:03] WARNING: startup\start.Lua:19: Bad argument @ 'xmlNodeGetValue' [Expected xml-node at argument 1, got boolean] [DUP x2] [2020-04-30 08:28:03] ERROR: startup\start.Lua:19: attempt to concatenate a boolean value My brain explodes Edited April 30, 2020 by Winstrol Link to comment
Moderators IIYAMA Posted April 30, 2020 Moderators Share Posted April 30, 2020 (edited) 3 hours ago, Winstrol said: local findGroup = xmlFindChild(loadConfig, "config", 0) How does your xml file looks like? local loadConfig = xmlLoadFile(":startup/dbconfig.xml", true) btw this will give you already the rootNode. (it doesn't matter what tagname you gave it) <rootNode> <child></child> </rootNode> Edited April 30, 2020 by IIYAMA Link to comment
Winstrol Posted April 30, 2020 Author Share Posted April 30, 2020 <config> <dbname>mydb</dbname> <host>127.0.0.1</host> <charset>utf8</charset> <username>root</username> <password></password> <share>1</share> <batch>0</batch> <autoreconnect>1</autoreconnect> <log>1</log> </config> Link to comment
Moderators IIYAMA Posted April 30, 2020 Moderators Share Posted April 30, 2020 1 minute ago, Winstrol said: <config> <dbname>mydb</dbname> <host>127.0.0.1</host> <charset>utf8</charset> <username>root</username> <password></password> <share>1</share> <batch>0</batch> <autoreconnect>1</autoreconnect> <log>1</log> </config> local findGroup = xmlLoadFile(":startup/dbconfig.xml", true) local findGroup = xmlFindChild(loadConfig, "config", 0) Link to comment
Winstrol Posted April 30, 2020 Author Share Posted April 30, 2020 Quote WARNING: startup\start.Lua:18: Bad argument @ 'xmlNodeGetValue' [Expected xml-node at argument 1] WARNING: startup\start.Lua:18: Bad argument @ 'xmlNodeGetValue' [Expected xml-node at argument 1] [DUP x2] ERROR: startup\start.Lua:18: attempt to concatenate a boolean value db = dbConnect("mysql", "dbname="..xmlNodeGetValue(dbname)..";host="..xmlNodeGetValue(host)..";charset="..xmlNodeGetValue(charset).."", ""..xmlNodeGetValue(user).."", ""..xmlNodeGetValue(pass).."", "share="..xmlNodeGetValue(share).."", "batch="..xmlNodeGetValue(batch).."", "autoreconnect="..xmlNodeGetValue(autorec).."", "log="..xmlNodeGetValue(logs).."") Link to comment
Moderators IIYAMA Posted April 30, 2020 Moderators Share Posted April 30, 2020 17 minutes ago, Winstrol said: db = dbConnect("mysql", "dbname="..xmlNodeGetValue(dbname)..";host="..xmlNodeGetValue(host)..";charset="..xmlNodeGetValue(charset).."", ""..xmlNodeGetValue(user).."", ""..xmlNodeGetValue(pass).."", "share="..xmlNodeGetValue(share).."", "batch="..xmlNodeGetValue(batch).."", "autoreconnect="..xmlNodeGetValue(autorec).."", "log="..xmlNodeGetValue(logs).."") You have more debugging to do with debuglines. 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