UserToDelete Posted May 2, 2015 Share Posted May 2, 2015 (edited) <spawn> <spawn>-2463, -627, 135</spawn> <spawn>-706, 953, 15</spawn> </spawn> El problema que tengo, es que al usar la funcion "spawnPlayer" me da error en el argumento 3, dice el error que no tiene nada. Lo que quiero saber es, como convertir esa string, por ejemplo "-2463, -627, 135" en tres strings distintas; "-2463", "-627", "135", es decir, pasarlo a un "formato tabla" function dead() if fileExists("spawn.xml") then local rootFile = xmlLoadFile("spawn.xml") local node = xmlNodeGetChildren(rootFile) local spaawn = math.random(1,#node) local val = xmlNodeGetValue(node[spaawn]) spawnPlayer(source, val) end end addEventHandler("onPlayerWasted", root, dead) Edited May 3, 2015 by Guest Link to comment
Sasu Posted May 2, 2015 Share Posted May 2, 2015 · Hidden Hidden local pos = split ( val, ", " ) --> pos[1] = X ; pos[2] = Y ; pos[3] = Z Link to comment
Bc# Posted May 2, 2015 Share Posted May 2, 2015 · Hidden Hidden Creo que esto igual funciona: function dead() if fileExists("spawn.xml") then local rootFile = xmlLoadFile("spawn.xml") local node = xmlNodeGetChildren(rootFile) local spaawn = math.random(1,#node) local val = xmlNodeGetValue(node[spaawn]) local x,y,z = split ( val, ", " ) spawnPlayer(source, x,y,z) end end addEventHandler("onPlayerWasted", root, dead) Link to comment
Sasu Posted May 3, 2015 Share Posted May 3, 2015 · Hidden Hidden Creo que esto igual funciona: function dead() if fileExists("spawn.xml") then local rootFile = xmlLoadFile("spawn.xml") local node = xmlNodeGetChildren(rootFile) local spaawn = math.random(1,#node) local val = xmlNodeGetValue(node[spaawn]) local x,y,z = split ( val, ", " ) spawnPlayer(source, x,y,z) end end addEventHandler("onPlayerWasted", root, dead) split devuelve una tabla asi que tienes que usar unpack local x, y, z = unpack ( split ( val, ", " ) ) Link to comment
UserToDelete Posted May 3, 2015 Author Share Posted May 3, 2015 Osea que split servia para eso, buena informacion Gracias! Link to comment
Recommended Posts