SpecT Posted April 8, 2015 Author Share Posted April 8, 2015 function updatePlayed (songName) local file = xmlLoadFile ( "songs.xml" ) for _, v in ipairs ( xmlNodeGetChildren ( file ) ) do if ( xmlNodeGetAttribute ( v, "name" ) == songName ) then xmlNodeSetAttribute ( v, "played", xmlNodeGetAttribute ( v, "played" ) + 1 ) end xmlSaveFile ( file ) xmlUnloadFile ( file ) end end That's in the server-side. Client side: song = getSongName ... callServerFunction("updatePlayed ",songName) I have used the callServerFunction which is in the code. Link to comment
WhoAmI Posted April 8, 2015 Share Posted April 8, 2015 function updatePlayed (songName) local file = xmlLoadFile ( "songs.xml" ) if ( not file ) then outputChatBox ( "ERROR" ); return; end for _, v in ipairs ( xmlNodeGetChildren ( file ) ) do if ( xmlNodeGetAttribute ( v, "name" ) == songName ) then xmlNodeSetAttribute ( v, "played", xmlNodeGetAttribute ( v, "played" ) + 1 ) end end xmlSaveFile ( file ) xmlUnloadFile ( file ) end Check if in chatbox won't be any error. Link to comment
SpecT Posted April 8, 2015 Author Share Posted April 8, 2015 function updatePlayed (songName) local file = xmlLoadFile ( "songs.xml" ) if ( not file ) then outputChatBox ( "ERROR" ); return; end for _, v in ipairs ( xmlNodeGetChildren ( file ) ) do if ( xmlNodeGetAttribute ( v, "name" ) == songName ) then xmlNodeSetAttribute ( v, "played", xmlNodeGetAttribute ( v, "played" ) + 1 ) end end xmlSaveFile ( file ) xmlUnloadFile ( file ) end Check if in chatbox won't be any error. Nope ... there is no message. Link to comment
WhoAmI Posted April 8, 2015 Share Posted April 8, 2015 Copy my code again. I changed it. You can't have this xmlSave/xmlUnload functions inside loop. Link to comment
SpecT Posted April 8, 2015 Author Share Posted April 8, 2015 Copy my code again. I changed it. You can't have this xmlSave/xmlUnload functions inside loop. The same ... Again errors in the debugscript. Link to comment
WhoAmI Posted April 8, 2015 Share Posted April 8, 2015 Same errors? Show me your code you have in file again. Link to comment
SpecT Posted April 8, 2015 Author Share Posted April 8, 2015 (edited) Ops .. my mistake. Didn't save the file. Okay now there are no errors but actually it doesn't update the played value. It's still 0. The info about the songs.xml shows that it was changed seconds ago but when I check the song the played value is still 0. Edited April 8, 2015 by Guest Link to comment
WhoAmI Posted April 8, 2015 Share Posted April 8, 2015 function updatePlayed (songName) local file = xmlLoadFile ( "songs.xml" ) for _, v in ipairs ( xmlNodeGetChildren ( file ) ) do if ( xmlNodeGetAttribute ( v, "name" ) == songName ) then xmlNodeSetAttribute ( v, "played", tonumber ( xmlNodeGetAttribute ( v, "played" ) ) + 1 ) end end xmlSaveFile ( file ) xmlUnloadFile ( file ) end Link to comment
SpecT Posted April 8, 2015 Author Share Posted April 8, 2015 function updatePlayed (songName) local file = xmlLoadFile ( "songs.xml" ) for _, v in ipairs ( xmlNodeGetChildren ( file ) ) do if ( xmlNodeGetAttribute ( v, "name" ) == songName ) then xmlNodeSetAttribute ( v, "played", tonumber ( xmlNodeGetAttribute ( v, "played" ) ) + 1 ) end end xmlSaveFile ( file ) xmlUnloadFile ( file ) end Oh GAWD ... seriously It worked ... Thanks man again for the great help! Link to comment
WhoAmI Posted April 8, 2015 Share Posted April 8, 2015 Add 'break' line after changing value so it won't loop for other songs. Like that function updatePlayed (songName) local file = xmlLoadFile ( "songs.xml" ) for _, v in ipairs ( xmlNodeGetChildren ( file ) ) do if ( xmlNodeGetAttribute ( v, "name" ) == songName ) then xmlNodeSetAttribute ( v, "played", tonumber ( xmlNodeGetAttribute ( v, "played" ) ) + 1 ) break; end end xmlSaveFile ( file ) xmlUnloadFile ( file ) end Link to comment
SpecT Posted April 8, 2015 Author Share Posted April 8, 2015 Add 'break' line after changing value so it won't loop for other songs.Like that function updatePlayed (songName) local file = xmlLoadFile ( "songs.xml" ) for _, v in ipairs ( xmlNodeGetChildren ( file ) ) do if ( xmlNodeGetAttribute ( v, "name" ) == songName ) then xmlNodeSetAttribute ( v, "played", tonumber ( xmlNodeGetAttribute ( v, "played" ) ) + 1 ) break; end end xmlSaveFile ( file ) xmlUnloadFile ( file ) end Oh okay. Link to comment
SpecT Posted April 8, 2015 Author Share Posted April 8, 2015 Oh .. really. That pisses me off. Now for every song it tells me that it's played 0 times which is wrong. There is problem with the played value .. Tried to fix it with tonumber but didn't help. Link to comment
SpecT Posted April 8, 2015 Author Share Posted April 8, 2015 (edited) Give me code you have. Client side ? --on click event local songName = get the song name local length = songList[songName][1] local played = songList[songName][2] musicStore.length = length musicStore.played = played outputChatBox(""..songName.."|"..played.."") It gives me the song name and 0 Load part (client): songList = { } function updateSongs ( ) local file = xmlLoadFile ( "songs.xml" ) for _, v in ipairs ( xmlNodeGetChildren ( file ) ) do local name, length, played = xmlNodeGetAttribute ( v, "name" ), xmlNodeGetAttribute ( v, "length" ), tonumber ( xmlNodeGetAttribute ( v, "played" )) songList[name] = {length, played} end xmlUnloadFile ( file ) end function loadSongsInGridlist() updateSongs ( ) for name, v in pairs ( songList ) do table.insert(musicStore.songName,name) table.insert(musicStore.songCache,name) end end Edited April 8, 2015 by Guest Link to comment
WhoAmI Posted April 8, 2015 Share Posted April 8, 2015 So there is an error with loadng the file? You are loading it clientside? Link to comment
SpecT Posted April 8, 2015 Author Share Posted April 8, 2015 So there is an error with loadng the file? You are loading it clientside? Ye I load it clientside. When click the button it calls the server to edit the played value. And when click on a song it loads the length and played times. EDIT:So if it shows 0 then probably something sets it to be 0. Link to comment
WhoAmI Posted April 8, 2015 Share Posted April 8, 2015 I have no idea when the error can be. Link to comment
SpecT Posted April 8, 2015 Author Share Posted April 8, 2015 I have no idea when the error can be. Is it a problem that that it's used by clientside and serverside? Maybe I should move the whole load part to serverside and then to send the data to client ... I don't know. Link to comment
WhoAmI Posted April 8, 2015 Share Posted April 8, 2015 You can try that. That may be causing a problem. Whole file should be opened servisde I guess. Just get 'xmlNodeGetChrildren' serverside, trigger it to client and loop it there. Link to comment
SpecT Posted April 8, 2015 Author Share Posted April 8, 2015 You can try that. That may be causing a problem. Whole file should be opened servisde I guess. Just get 'xmlNodeGetChrildren' serverside, trigger it to client and loop it there. I'm trying to trigger from serverside to clientside but it tells me that there is no such event .. Tried so much things and again the same Link to comment
SpecT Posted April 8, 2015 Author Share Posted April 8, 2015 Clientside: songList = { } function loadTable(table) local name, length, played = xmlNodeGetAttribute ( table, "name" ), xmlNodeGetAttribute ( table, "length" ), tonumber ( xmlNodeGetAttribute ( table, "played" )) songList[name] = {length, played} end addEvent("onLoadTable",true) addEventHandler("onLoadTable",localPlayer,loadTable) Serverside: songList = { } function updateSongs ( ) local file = xmlLoadFile ( "songs.xml" ) for _, v in ipairs ( xmlNodeGetChildren ( file ) ) do triggerClientEvent("onLoadTable",getRootElement(),v) end xmlUnloadFile ( file ) end addEventHandler("onResourceStart",getRootElement(),updateSongs) I'm sure that it's wrong but I don't know what. Link to comment
WhoAmI Posted April 8, 2015 Share Posted April 8, 2015 Serverside scripts are loading much faster than clientside script. You are triggering event which doesn't really exist. Do like that: s-side addEvent ( "requestUpdating", true ); function updateSongs ( ) local file = xmlLoadFile ( "songs.xml" ) if ( file ) then triggerClientEvent ( source, "onLoadTable", source, xmlNodeGetChildren ( file ) ) end xmlUnloadFile ( file ) end addEventHandler ( "requestUpdating", root, updateSongs ) c-side songList = { } addEventHandler ( "onClientResourceStart", resourceRoot, function ( ) triggerServerEvent ( "requestUpdating", localPlayer ); end ); function loadTable ( table ) if ( type ( table ) == "table" ) then for _, v in pairs ( table ) do local name, length, played = xmlNodeGetAttribute ( v, "name" ), xmlNodeGetAttribute ( v, "length" ), tonumber ( xmlNodeGetAttribute ( v, "played" )) songList[name] = {length, played} end end end addEvent ( "onLoadTable", true ) addEventHandler ( "onLoadTable", root, loadTable ) Link to comment
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