Jump to content

[HELP] Specify index in xmlNodeGetChildren, it returns userdata.


Kazafka

Recommended Posts

I don't rally know, how to use multiple nodes in XML files. I've tried to specify an index, but it always returns userdata.

My code:

Lua  (please don't look at the comment, it's in Polish [means: XML file that specifies, who can be policeman, and, specifies police vehicles]):

addEventHandler("onResourceStart", root, function()
	local xml = xmlLoadFile("stuff.xml") --Plik XML określający, kto może być policjantem, oraz, określający samochody policyjne
	local polmen = xmlNodeGetChildren(xml, 0)
	local polvehs = xmlNodeGetChildren(xml, 1)
	
	for i, node in ipairs(polmen) do
		policemen[i] = xmlNodeGetValue(node)
	end
	xmlUnloadFile(xml1)
	
	for i, node in ipairs(polvehs) do
		policevehs[i] = xmlNodeGetValue(node)
	end
	xmlUnloadFile(xml2)
end)

XML (polish comments [means: <!--<user>(playerName)</user>--> and <!--<vehicle>(vehicleID)</vehicle>-->]):

<policemen>
	<!--<user>(nazwaGracza)</user>-->
	<user>VaporZ</user>
	<user>maxeo11</user>
</policemen>

<policevehicles>
	<!--<vehicleicle>(idPojazdu)</vehicleicle>-->
	<vehicle>596</vehicle>
	<vehicle>523</vehicle>
	<vehicle>402</vehicle>
</policevehicles>

Any advance?

Link to comment
  • Moderators

Aren't you saving userdata instead?

Anyway, there are 2 things that I notice.

1. You are not unloading your xml file. But unloading 2 non existing files.

2. Your xml file doesn't have 1 root. It has 2 roots infact.

@VaporZ

Edited by IIYAMA
Link to comment
8 minutes ago, IIYAMA said:

Aren't you saving userdata instead?

Anyway, there are 2 things that I notice.

1. You are not unloading your xml file. But unloading 2 non existing files.

2. Your xml file doesn't have 1 root. It has 2 roots infact.

By the way, no, I want to use table.

1. YES XD

2. That's worng?

@ 2. - On MTA Reference, they told me, that I can choose what root I want to use, for specifict action.

Edited by VaporZ
Link to comment
  • Moderators
7 minutes ago, VaporZ said:

@ 2. - On MTA Reference, they told me, that I can choose what root I want to use, for specifict action.

Just try to give it a root, because I am not sure if MTA, can detect multiple items and based on that create a new file root.

(xml = fileRoot)

<fileRoot>

<policemen> 	<!--<user>(nazwaGracza)</user>--> 	<user>VaporZ</user> 	<user>maxeo11</user>
</policemen> 
<policevehicles> 	<!--<vehicleicle>(idPojazdu)</vehicleicle>--> 	<vehicle>596</vehicle> 	<vehicle>523</vehicle> 	<vehicle>402</vehicle>
</policevehicles>

</fileRoot>

 

Edited by IIYAMA
Link to comment
1 minute ago, IIYAMA said:

Just try to give it a root, because I am not sure if MTA, can detect multiple items and based on that create a new file root.

 


<fileRoot>

<policemen> 	<!--<user>(nazwaGracza)</user>--> 	<user>VaporZ</user> 	<user>maxeo11</user>
</policemen> 
<policevehicles> 	<!--<vehicleicle>(idPojazdu)</vehicleicle>--> 	<vehicle>596</vehicle> 	<vehicle>523</vehicle> 	<vehicle>402</vehicle>
</policevehicles>

</fileRoot>

 

I'll test that

12 minutes ago, IIYAMA said:

Just try to give it a root, because I am not sure if MTA, can detect multiple items and based on that create a new file root.

 


<fileRoot>

<policemen> 	<!--<user>(nazwaGracza)</user>--> 	<user>VaporZ</user> 	<user>maxeo11</user>
</policemen> 
<policevehicles> 	<!--<vehicleicle>(idPojazdu)</vehicleicle>--> 	<vehicle>596</vehicle> 	<vehicle>523</vehicle> 	<vehicle>402</vehicle>
</policevehicles>

</fileRoot>

 

Lua:

	local xml = xmlLoadFile("policja.xml")
	local polmen = xmlNodeGetChildren(xml, 0)
	local polvehs = xmlNodeGetChildren(xml, 1)
	
	for i, node in ipairs(polmen) do
		policemen[i] = xmlNodeGetValue(node)
	end
	
	for i, node in ipairs(polvehs) do
		policevehs[i] = xmlNodeGetValue(node)
	end
	xmlUnloadFile(xml)

XML:

<root>
	<policemen>
		<!--<user>(nazwaGracza)</user>-->
		<user>VaporZ</user>
		<user>maxeo11</user>
	</policemen>
	
	<policevehicles>
		<!--<user>(IDPojazdu)</user>-->
		<vehicle>596</vehicle>
		<vehicle>523</vehicle>
		<vehicle>402</vehicle>
	</policevehicles>
</root>

Still nothing, error: [...] expected table at argument 1, got userdata (ipairs error).

BTW, I've released: 

 

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...