Hallo,
ich wollte eben für ein kleines Script ein paar Koordinaten in einem XML-File abspeichern.
Das Erstellen und Abspeichern funktioniert ja auch prima, aber wenn ich nun die Datei laden will, funktioniert es nicht.
Dies ist mein momentaner Code:
Lua
function createCamFlightXML ()
if fileExists ('Properties/Positions.xml') then
outputChatBox("Exist")
return xmlLoadFile('Properties/Positions.xml')
end
outputChatBox("or not")
local camFlight_Positions = xmlCreateFile('Properties/Positions.xml','Positions')
for i = 1, 10, 1 do
pos = xmlCreateChild (camFlight_Positions, i..'.Position' )
xmlNodeSetAttribute(pos, "X", "0")
xmlNodeSetAttribute(pos, "Y", "0")
xmlNodeSetAttribute(pos, "Z", "0")
xmlNodeSetAttribute(pos, "ViewX", "0")
xmlNodeSetAttribute(pos, "ViewY", "0")
xmlNodeSetAttribute(pos, "ViewZ", "0")
end
xmlSaveFile(camFlight_Positions)
return camFlight_Positions
end
addEventHandler("onResourceStart", getRootElement (), createCamFlightXML)
function getCamFlight_Position ()
local xml = loadproperties ()
local nChilds = 0
local positions = {}
repeat
nChilds = nChilds + 1
state = xmlFindChild (xml, nChilds..".Position", 0)
until state == false
for i = 1 , nChilds , 1 do
local pos = {}
local child = xmlFindChild (xml, i, i..".Position", 0)
local pos = xmlNodeGetAttributes(child)
position[i] = pos
end
end
addEvent("getCamFlight_Position")
addEventHandler("getCamFlight_Position", getRootElement(), getCamFlight_Position)
addCommandHandler("load", getCamFlight_Position)
function loadproperties ()
if fileExists ('Properties/Positions.xml') then
outputChatBox("File Exists")
xmlFile = xmlLoadFile('Properties/Positions.xml')
if xmlFile then
outputChatBox("File was loaded successfully")
return xmlFile
else
outputChatBox("File was not loaded successfully")
end
end
end
Alles anzeigen
Und das ist die Ausgabe im Chat:
Ich habe keine Ahnung warum das nicht funktioniert, er erkennt, das die Datei existiert, ist aber nicht dazu in der Lage sie ins Spiel zu laden.
Ich hoffe ihr könnt mir weiterhelfen.
Edit:
Das ist die Xml-Datei die geladen werden soll. Ich ging bisher nicht davon aus, das dort ein Fehler drinne sein könnte, da ich diese Datei auch durch das Script erstellt habe.
Code
<Positions>
<1.Position X="0" Y="0" Z="0" ViewX="0" ViewY="0" ViewZ="0"></1.Position>
<2.Position X="0" Y="0" Z="0" ViewX="0" ViewY="0" ViewZ="0"></2.Position>
<3.Position X="0" Y="0" Z="0" ViewX="0" ViewY="0" ViewZ="0"></3.Position>
<4.Position X="0" Y="0" Z="0" ViewX="0" ViewY="0" ViewZ="0"></4.Position>
<5.Position X="0" Y="0" Z="0" ViewX="0" ViewY="0" ViewZ="0"></5.Position>
<6.Position X="0" Y="0" Z="0" ViewX="0" ViewY="0" ViewZ="0"></6.Position>
<7.Position X="0" Y="0" Z="0" ViewX="0" ViewY="0" ViewZ="0"></7.Position>
<8.Position X="0" Y="0" Z="0" ViewX="0" ViewY="0" ViewZ="0"></8.Position>
<9.Position X="0" Y="0" Z="0" ViewX="0" ViewY="0" ViewZ="0"></9.Position>
<10.Position X="0" Y="0" Z="0" ViewX="0" ViewY="0" ViewZ="0"></10.Position>
</Positions>
Alles anzeigen
Mit freundlichen Grüßen
Haushund