Jump to content

problem with xml?


SirniNamaz

Recommended Posts

Posted (edited)

client

    if (guiGetVisible(guiEventManager) == true) then 
        local xmlElements = xmlLoadFile("elements.xml") 
        for i=0,149 do 
            local xmlOldChild = xmlFindChild(xmlElements,"element",i) 
            local attrs = xmlNodeGetAttributes(xmlOldChild) 
            if not (attrs == false) then 
                guiGridListClear(grdElementsList) 
                local newRow = guiGridListAddRow(grdElementsList) 
                for name,value in pairs(attrs) do 
                    outputChatBox(name .. " = " .. value) 
                    if (name == "item") then 
                        if (tonumber(value) == 4) then 
                            guiGridListSetItemText(grdElementsList,newRow,colElement2,"Knife",false,false) 
                        end 
                    end 
                    if (name == "x") then 
                        guiGridListSetItemText(grdElementsList,newRow,colElement2X,value,false,false) 
                    end 
                    if (name == "y") then 
                        guiGridListSetItemText(grdElementsList,newRow,colElement2Y,value,false,false) 
                    end 
                    if (name == "z") then 
                        guiGridListSetItemText(grdElementsList,newRow,colElement2Z,value,false,false) 
                    end 
                    if (name == "left") then 
                        guiGridListSetItemText(grdElementsList,newRow,colElement2Left,value,false,false) 
                    end 
                end 
            end 
        end 
    end 

xml

    "8066072" type="weapon" item="4" x="2486.3376464844" y="-1663.841796875" z="13.335947036743" left="1">
    "7858149" type="weapon" item="4" x="2469.3784179688" y="-1667.8182373047" z="13.302844047546" left="1">

  

the error is : Bad argument @ 'xmlNodeGetAttributes'

Edited by Guest
Posted

Be patient, bumping after 1-2 hours and nagging people via PM is NOT nice, really.

for i=0,149 do 
local xmlOldChild = xmlFindChild(xmlElements,"element",i) 

Why are you assuming there's always 149 elements?

With your xml example you will get 147 errors about bad argument @ xmlNodeGetAttributes, because xmlFindChild returns false for them.

Checking if xmlOldChild is false before doing next actions could be good idea, but even better idea would be to use xmlNodeGetChildren, which just gets all children so you don't have to guess how many of them exists.

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

there is one element, but it doesn't get returned in gridlist (i am currently ignoring the 149 errors or xmlFindChild command, but i get 150 of them, it cant even load the first one into gridlist)

Posted

im not suprised that some later code fails, when there's error 20 lines above. fix it first, THEN take care about any gui functions

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted
function eventFiveSec() 
    if (guiGetVisible(guiEventManager) == true) then 
        local xmlElements = xmlLoadFile("elements.xml") 
        for i=0,149 do 
            local xmlOldChild = xmlFindChild(xmlElements,"element",i) 
            local attrs = xmlNodeGetAttributes(xmlOldChild) 
            if (attrs == false) then 
                return 
            else 
                guiGridListClear(grdElementsList) 
                local newRow = guiGridListAddRow(grdElementsList) 
                for name,value in pairs(attrs) do 
                    outputChatBox(name .. " = " .. value) 
                    if (name == "item") then 
                        if (tonumber(value) == 4) then 
                            guiGridListSetItemText(grdElementsList,newRow,colElement2,"Knife",false,false) 
                        end 
                    end 
                    if (name == "x") then 
                        guiGridListSetItemText(grdElementsList,newRow,colElement2X,value,false,false) 
                    end 
                    if (name == "y") then 
                        guiGridListSetItemText(grdElementsList,newRow,colElement2Y,value,false,false) 
                    end 
                    if (name == "z") then 
                        guiGridListSetItemText(grdElementsList,newRow,colElement2Z,value,false,false) 
                    end 
                    if (name == "left") then 
                        guiGridListSetItemText(grdElementsList,newRow,colElement2Left,value,false,false) 
                    end 
                end 
            end 
        end 
    end 
end 

It now only returns one line of error, but it doesn't get exported to gridlist.

Posted

Can't you figure out?

Use the brain and interprete this knowing that "xmlOldChild" returns false:

            local xmlOldChild = xmlFindChild(xmlElements,"element",i) 
            local attrs = xmlNodeGetAttributes(xmlOldChild) 
            if (attrs == false) then 
                return 

"[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007

Posted

Show your code.

"[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007

Posted

You already showed it before, why not show again.

"[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007

Posted
This is not the full code, this is only the part which doesn't work.

I didn't ask for the full code, anyway.

"[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007

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...