Castillo Posted September 19, 2010 Share Posted September 19, 2010 hey, i've got a strange problem updating a gui label with a data i get from server side O_o, here is my code and the error i'm genting. client: function upClientStats(zombiekills,deaths) if deaths == 0 then guiSetText(ratioLabel, "Ratio: N/A") else ratio = (tonumber(zombiekills)/tonumber(deaths))*10 guiSetText(ratioLabel, "Ratio: "..tostring(ratio).." %") end end addEvent("updateClientStatsGui", true) addEventHandler("updateClientStatsGui", getRootElement(), upClientStats) server: function info2(cliente) local account = getPlayerAccount (cliente); if not isGuestAccount(account) then local zombiekills = getAccountData(account,"zombieKills") local deaths = getAccountData(account,"deaths") triggerClientEvent (cliente,"updateClientStatsGui",cliente,zombiekills,deaths) end end addEvent("getInfoFromClient", true) addEventHandler("getInfoFromClient", getRootElement(), info2) Error: attempt to perfrom arithmetic on a nil value its at zombiekills if i'm right. Thanks in advance Link to comment
dzek (varez) Posted September 19, 2010 Share Posted September 19, 2010 if player didnt kill any zombie and nothing is in his elementData, you are probably passing nil this probably work: triggerClientEvent (cliente,"updateClientStatsGui",cliente,zombiekills or "0",deaths or "0") if not: local zombiekills = getAccountData(account,"zombieKills") if (not zombiekills) then zombiekills=0 end same for deaths Link to comment
Castillo Posted September 19, 2010 Author Share Posted September 19, 2010 sorry, i forgot to post that its genting the data for other individual labels thats why its strange.. the data is there i can get it via many ways but this still not working Link to comment
dzek (varez) Posted September 19, 2010 Share Posted September 19, 2010 genting = getting? Erm, i don't know what is your problem now.. Link to comment
Castillo Posted September 19, 2010 Author Share Posted September 19, 2010 genting = getting?Erm, i don't know what is your problem now.. well, i can get the data then trigger it to client and set a label with that data but then when using it with ratio it fails saying its a nil value Link to comment
dzek (varez) Posted September 19, 2010 Share Posted September 19, 2010 And what is wrong with my solution? Link to comment
Castillo Posted September 19, 2010 Author Share Posted September 19, 2010 And what is wrong with my solution? ... i think you don't get what i want to mean, i will explain again, i have a whole menu where you can see your kills deaths rank level etc well there it shows the zombiekills value. Link to comment
dzek (varez) Posted September 19, 2010 Share Posted September 19, 2010 i know, now explain me - what's wrong with my solution? on this line you are doing arithmetic operation ratio = (tonumber(zombiekills)/tonumber(deaths))*10 error says it cant do arithmetics on nil value so it means one/both of them (zombiekills or deaths) are arithmetic. you are triggering it from server. syntax is ok, so the only problem is data that is send from server i suggested you to fix it. you said something that i didnt understand.. try little debug. function upClientStats(zombiekills,deaths) outputDebugString("got values: "..tostring(zombiekills).." and "..tostring(deaths)) if deaths == 0 then guiSetText(ratioLabel, "Ratio: N/A") else ratio = (tonumber(zombiekills)/tonumber(deaths))*10 guiSetText(ratioLabel, "Ratio: "..tostring(ratio).." %") end end addEvent("updateClientStatsGui", true) addEventHandler("updateClientStatsGui", getRootElement(), upClientStats) function info2(cliente) local account = getPlayerAccount (cliente); if not isGuestAccount(account) then local zombiekills = getAccountData(account,"zombieKills") if (not zombiekills) then zombiekills=0 end local deaths = getAccountData(account,"deaths") if (not deaths) then deaths=0 end outputDebugString("sending values: "..tostring(zombiekills).." and "..deaths) triggerClientEvent (cliente,"updateClientStatsGui",cliente,zombiekills,deaths) end end addEvent("getInfoFromClient", true) addEventHandler("getInfoFromClient", getRootElement(), info2) Link to comment
Castillo Posted September 19, 2010 Author Share Posted September 19, 2010 it outputs at debugscript this, got values: 866 and 0 sending values: 866 and 0 Link to comment
dzek (varez) Posted September 19, 2010 Share Posted September 19, 2010 and does it still triggerring this error/warning you mentioned in first post? deaths = 0? Is it true? By doing this little debug you should spot your bug.. Link to comment
Castillo Posted September 19, 2010 Author Share Posted September 19, 2010 and does it still triggerring this error/warning you mentioned in first post?deaths = 0? Is it true? By doing this little debug you should spot your bug.. yes that data its correct, it still saying same error message... Link to comment
dzek (varez) Posted September 19, 2010 Share Posted September 19, 2010 maybe: if deaths == 0 or deaths=="0" then Link to comment
Castillo Posted September 19, 2010 Author Share Posted September 19, 2010 maybe: if deaths == 0 or deaths=="0" then still saying same error Link to comment
dzek (varez) Posted September 19, 2010 Share Posted September 19, 2010 in which line? Link to comment
Castillo Posted September 19, 2010 Author Share Posted September 19, 2010 in which line? this one: ratio = (tonumber(zombiekills)/tonumber(deaths))*10 Link to comment
12p Posted September 19, 2010 Share Posted September 19, 2010 Are you sure that "zombieKills" can be processed to a number? Remember that "zombieKills" is saved at your account, maybe is causing problems your account's zombie kills data (it's a boolean value? or a nil maybe?). Just an idea. Link to comment
Castillo Posted September 20, 2010 Author Share Posted September 20, 2010 Are you sure that "zombieKills" can be processed to a number? Remember that "zombieKills" is saved at your account, maybe is causing problems your account's zombie kills data (it's a boolean value? or a nil maybe?). Just an idea. I don't get what do you mean with this... Link to comment
dzek (varez) Posted September 20, 2010 Share Posted September 20, 2010 Solid, check my replies - ive already add "protection" not to send boolean/nil, but zero. also check what debug is displaying.. Link to comment
Castillo Posted September 20, 2010 Author Share Posted September 20, 2010 Solid, check my replies - ive already add "protection" not to send boolean/nil, but zero.also check what debug is displaying.. i have added what you said and keeps saying attempt to perfrom arithmetic on a nil value also when i open the menu it says this: got values: nil and nil, sending values: 966 and 0, got values: 966 and 0 Edit: i was thinking that i can also make it server side then trigger it and use guiSetText but the problem now is that this keeps saying my ratio are my kills... local rat = 2 function round(num, idp) local mult = 10^(idp or 0) return math.floor(num * mult + 0.5) / mult end function ratio(cliente) local account = getPlayerAccount (cliente) local zombiekills = getAccountData(account,"zombieKills") local deaths = getAccountData(account,"deaths") if deaths == 0 or deaths == "0" then ratio = "" triggerClientEvent (cliente,"updateClientRatio",cliente,ratio) else local ratio = round(zombiekills / deaths, rat) triggerClientEvent (cliente,"updateClientRatio",cliente,ratio) end end addEvent("getInfoFromClient", true) addEventHandler("getInfoFromClient", getRootElement(), ratio) Link to comment
[M2S]moe Posted September 20, 2010 Share Posted September 20, 2010 Your problem is that you check if deaths = 0 or "0" when it == nil, so it runs the else and since deaths is nil, it doesnt divide by zombiekills and thus zombiekills becomes your ratio. Change line 12 in your code quote to: if deaths == 0 or deaths == "0" or deaths == nil then Link to comment
Castillo Posted September 20, 2010 Author Share Posted September 20, 2010 Your problem is that you check if deaths = 0 or "0" when it == nil, so it runs the else and since deaths is nil, it doesnt divide by zombiekills and thus zombiekills becomes your ratio.Change line 12 in your code quote to: if deaths == 0 or deaths == "0" or deaths == nil then it does same problem, btw my deaths data its 1 and kills 960. this is the current code, function ratio(cliente) local account = getPlayerAccount (cliente) local zombiekills = getAccountData(account,"zombieKills") local deaths = getAccountData(account,"deaths") if deaths == 0 or deaths == "0" or deaths == nil then ratio = "" triggerClientEvent (cliente,"updateClientRatio",cliente,ratio) else local ratio = round(zombiekills / deaths, rat) triggerClientEvent (cliente,"updateClientRatio",cliente,ratio) end end addEvent("getInfoFromClient", true) addEventHandler("getInfoFromClient", getRootElement(), ratio) Link to comment
UAEpro Posted September 20, 2010 Share Posted September 20, 2010 Check for Capital Letter or Smal letter in the names like Zombiekills or zombiekills << Cus they are Different Link to comment
Castillo Posted September 20, 2010 Author Share Posted September 20, 2010 Check for Capital Letter or Smal letter in the nameslike Zombiekills or zombiekills << Cus they are Different Its all fine dude, i ever check this Link to comment
[M2S]moe Posted September 23, 2010 Share Posted September 23, 2010 Try this: local ratio = round(tonumber(zombiekills / deaths), rat) 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