Tokio Posted August 1, 2017 Share Posted August 1, 2017 i got this error, but the script working fine... -.- bad argument #1 to 'len' (string expected, got boolean) how to fix this? code: function currentSongName() local radio_title = getElementData(resourceRoot, "radio.title") if string.len(radio_title) >= x*0.0625 then radio_title = string.sub(radio_title, 1, 80)..".." end for i, shading in pairs ( offsetShadings ) do dxDrawText("Radio: "..radio_title, xD+shading[1], yD+shading[2], xD, yD+textHeight, tocolor ( 0, 0, 0, 255 ), scale, font, "left", "center", false, false, true, true) end dxDrawText("Radio: #ffffff"..radio_title, xD, yD, xD, yD+textHeight, tocolor ( 70, 215, 0, 255 ), scale, font, "left", "center", false, false, true, true) end addEventHandler('onClientRender', root, currentSongName) Link to comment
Ben_Sherman Posted August 2, 2017 Share Posted August 2, 2017 8 hours ago, 50cent said: i got this error, but the script working fine... -.- bad argument #1 to 'len' (string expected, got boolean) how to fix this? code: function currentSongName() local radio_title = getElementData(resourceRoot, "radio.title") if string.len(radio_title) >= x*0.0625 then radio_title = string.sub(radio_title, 1, 80)..".." end for i, shading in pairs ( offsetShadings ) do dxDrawText("Radio: "..radio_title, xD+shading[1], yD+shading[2], xD, yD+textHeight, tocolor ( 0, 0, 0, 255 ), scale, font, "left", "center", false, false, true, true) end dxDrawText("Radio: #ffffff"..radio_title, xD, yD, xD, yD+textHeight, tocolor ( 70, 215, 0, 255 ), scale, font, "left", "center", false, false, true, true) end addEventHandler('onClientRender', root, currentSongName) I assume you get the error message on line 3 since you never said where, if so to avoid the error message just change line 2 to this local radio_title = getElementData(resourceRoot, "radio.title") or "" the reason you get that error message is because whenever "radio.title" doesn't exist it returns it as false, and you're trying to get the length of a string in which it gives you that error message. I hope it helps, I can't confirm this solves the problem, as I've run into very weird problems with Lua lately, however, it should work script-wise. 1 Link to comment
Tokio Posted August 2, 2017 Author Share Posted August 2, 2017 6 hours ago, Ben_Sherman said: I assume you get the error message on line 3 since you never said where, if so to avoid the error message just change line 2 to this local radio_title = getElementData(resourceRoot, "radio.title") or "" the reason you get that error message is because whenever "radio.title" doesn't exist it returns it as false, and you're trying to get the length of a string in which it gives you that error message. I hope it helps, I can't confirm this solves the problem, as I've run into very weird problems with Lua lately, however, it should work script-wise. Thank you!:D Link to comment
Tokio Posted August 2, 2017 Author Share Posted August 2, 2017 7 hours ago, Ben_Sherman said: I assume you get the error message on line 3 since you never said where, if so to avoid the error message just change line 2 to this local radio_title = getElementData(resourceRoot, "radio.title") or "" the reason you get that error message is because whenever "radio.title" doesn't exist it returns it as false, and you're trying to get the length of a string in which it gives you that error message. I hope it helps, I can't confirm this solves the problem, as I've run into very weird problems with Lua lately, however, it should work script-wise. Why output the another player's music? Link to comment
Mr.Loki Posted August 2, 2017 Share Posted August 2, 2017 1 hour ago, 50cent said: Why output the another player's music? Because you are saving the elementData to the resource. Doing this means everyone will save the elementData to the same key in the resource overwriting the previous title. I suggest saving the elementData to the player or if the radio has an object set it to the object/vehicle. Link to comment
Tokio Posted August 2, 2017 Author Share Posted August 2, 2017 14 minutes ago, Mr.Loki said: Because you are saving the elementData to the resource. Doing this means everyone will save the elementData to the same key in the resource overwriting the previous title. I suggest saving the elementData to the player or if the radio has an object set it to the object/vehicle. How? Link to comment
Ben_Sherman Posted August 4, 2017 Share Posted August 4, 2017 (edited) On 2017-08-02 at 13:49, 50cent said: How? Not sure where you're saving it, but here is how you get the data from a player as well an example of storing it, however, the storing function is client-side ONLY. If you want to save the data from a server-side script you need to replace getLocalPlayer() with the player itself. getElementData(getLocalPlayer(), "radio.title") setElementData(getLocalPlayer(), "radio.title", theData) Edited August 4, 2017 by Ben_Sherman 1 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