Waileer Posted February 1, 2014 Posted February 1, 2014 Hello, I've problem with creating vehicle shop. Basically everything worker until I added populateGridList function. After that nothing works. Marker doesn't appear, and by that GUI doesn't appear too. All it does is that it creates ped from server script. Here's client: function createVehicleSelection() local x,y,z = 1664.0629882813,1813.0328369141,10.8203125 local sWidth, sHeight = guiGetScreenSize() local Width,Height = 328,537 local X = (sWidth/2) - (Width/2) local Y = (sHeight/2) - (Height/2) windowVehicleShop = guiCreateWindow(X,Y,Width,Height,"Vehicle Shop",false) gridlistVehicleShop = guiCreateGridList(9, 82, 308, 406, false, windowVehicleShop) local Name = guiGridListAddColumn(gridlistVehicleShop, "Name", 0.3) local Price = guiGridListAddColumn(gridlistVehicleShop, "Price", 0.3) local ID = guiGridListAddColumn(gridlistVehicleShop, "ID", 0.3) guiWindowSetSizable(windowVehicleShop, false) guiCreateStaticImage(53, 29, 223, 49, "images/vehicleshop.png", false, windowVehicleShop) buttonBuy = guiCreateButton(9, 498, 147, 29, "Buy", false, windowVehicleShop) buttonCancel = guiCreateButton(172, 498, 146, 29, "Cancel", false, windowVehicleShop) addEventHandler("onClientGUIClick",buttonBuy, createVehicleHandler,false) addEventHandler("onClientGUIClick",buttonCancel, closeVehicleShop, false) populateGridList() guiSetVisible(windowVehicleShop,false) end addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()), function() createVehicleSelection() end ) local marker = createMarker ( 1671.2398681641, 1814.2731933594, 10, "cylinder", 1.5 ) setMarkerColor ( marker, 255, 255, 255, 255 ) function showVehicleSelection( hitElement ) if getElementType(hitElement) == "player" and (hitElement == localPlayer) then if not guiGetVisible(windowVehicleShop) then guiSetVisible(windowVehicleShop, true) showCursor(true) end end end addEventHandler ( "onClientMarkerHit", marker, showVehicleSelection ) function closeVehicleShop () guiSetVisible ( windowVehicleShop, false ) showCursor( false ) end addEventHandler("onClientGUIClick", buttonCancel, closeVehicleShop, false) function populateGridList() local file = xmlLoadFile ("vehs.xml"); assert (file, "Fail to load vehs.xml"); local children = xmlNodeGetChildren (file); for _,child in ipairs (children) do if string.lower (xmlNodeGetName (child)) == "item" then local attrs = xmlNodeGetAttributes (child); local Name,Price,ID = attrs.Name, attrs.Price, attrs.ID; if not Name then outputDebugString ("name attribute not set for item", 2); end; if not Price then outputDebugString ("cash attribute not set for item", 2); end; if not ID then outputDebugString ("score attribute not set for item", 2); end; local itemRow = guiGridListAddRow (gridlistVehicleShop); guiGridListSetItemText (gridlistVehicleShop, itemRow, Name, Name, false, false); guiGridListSetItemText (gridlistVehicleShop, itemRow, Price, Price, false, true); guiGridListSetItemText (gridlistVehicleShop, itemRow, ID, ID, false, true); end; end; end; xmlUnloadFile (file); end); Regards, Waileer
Waileer Posted February 1, 2014 Author Posted February 1, 2014 I found out that if i remove whole function of populategridlist everything is working perfectly, anyone got idea what problem is happening?
Castillo Posted February 1, 2014 Posted February 1, 2014 That's because the function has few errors, you could have spotted them if you used the debugscript. function populateGridList ( ) local file = xmlLoadFile ( "vehs.xml" ) if ( not file ) then assert ( file, "Fail to load vehs.xml" ) else local children = xmlNodeGetChildren ( file ) for _,child in ipairs ( children ) do if ( string.lower ( xmlNodeGetName ( child ) ) == "item" ) then local attrs = xmlNodeGetAttributes ( child ) local Name, Price, ID = attrs.Name, attrs.Price, attrs.ID if ( not Name ) then outputDebugString ( "name attribute not set for item", 2 ) end if ( not Price ) then outputDebugString ( "cash attribute not set for item", 2 ) end if ( not ID ) then outputDebugString ( "score attribute not set for item", 2 ) end local itemRow = guiGridListAddRow ( gridlistVehicleShop ) guiGridListSetItemText ( gridlistVehicleShop, itemRow, Name, Name, false, false ) guiGridListSetItemText ( gridlistVehicleShop, itemRow, Price, Price, false, true ) guiGridListSetItemText ( gridlistVehicleShop, itemRow, ID, ID, false, true ) end end xmlUnloadFile ( file ) end end
Waileer Posted February 1, 2014 Author Posted February 1, 2014 That's because the function has few errors, you could have spotted them if you used the debugscript. function populateGridList ( ) local file = xmlLoadFile ( "vehs.xml" ) if ( not file ) then assert ( file, "Fail to load vehs.xml" ) else local children = xmlNodeGetChildren ( file ) for _,child in ipairs ( children ) do if ( string.lower ( xmlNodeGetName ( child ) ) == "item" ) then local attrs = xmlNodeGetAttributes ( child ) local Name, Price, ID = attrs.Name, attrs.Price, attrs.ID if ( not Name ) then outputDebugString ( "name attribute not set for item", 2 ) end if ( not Price ) then outputDebugString ( "cash attribute not set for item", 2 ) end if ( not ID ) then outputDebugString ( "score attribute not set for item", 2 ) end local itemRow = guiGridListAddRow ( gridlistVehicleShop ) guiGridListSetItemText ( gridlistVehicleShop, itemRow, Name, Name, false, false ) guiGridListSetItemText ( gridlistVehicleShop, itemRow, Price, Price, false, true ) guiGridListSetItemText ( gridlistVehicleShop, itemRow, ID, ID, false, true ) end end xmlUnloadFile ( file ) end end Thanks, can you tell me how to run/use debugscript?
Waileer Posted February 1, 2014 Author Posted February 1, 2014 debugscript 3 Yeah I just found that out, thanks alot.
Waileer Posted February 1, 2014 Author Posted February 1, 2014 Hey again, I've ran everything now. It all working good(better than before). And theres little problem, the XML is not loading into grid list. Anyone may help with this?
Waileer Posted February 1, 2014 Author Posted February 1, 2014 Nope, only some warnings about bad arguments(expected element and expected function).
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