Cuberite Forum
headache - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Plugins (https://forum.cuberite.org/forum-1.html)
+--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html)
+--- Thread: headache (/thread-69.html)



headache - Tim - 03-05-2011

Code:
local iniFile = cIniFile("myfile.ini")
                if(iniFile:ReadFile()) then
                        local data = tonumber(iniFile:GetValue(Player:GetName(), "data"))
                        if(not data==true) then
                                Server:SendMessage("cant retrieve data", Player)
                        else
                                Server:SendMessage("data: "..iniFile:GetValue(Player:GetName(), "data"), Player)
                        end
                end
If it finds the key with the players name and value of data, it should output the data, otherwise output "cant retrieve data" right? or am i wrong? :S but either way its not working, it outputs fine if it finds the data, otherwise it doesnt do anything

heeeeeeelllppppp HuhHuh


RE: headache - Revolucas - 03-05-2011

Is Player's name suppose to be a number? Also you don't want to check for data == true. That simply doesn't work. You want to make sure it isn't null or nil by:

Code:
if (not data) then
for easier readability:
Code:
if (data) then
               Server:SendMessage("data: "..iniFile:GetValue(Player:GetName(),"data"), Player)
            else
                Server:SendMessage("Can't retrieve data",Player)
            end

In reality checking for true is like making something check if it is equal to one.


RE: headache - Tim - 03-05-2011

(03-05-2011, 06:54 AM)Revolucas Wrote: Is Player's name suppose to be a number?
that was when i was trying something else, needed to convert the data to a number, i guess i forgot to take it outTongue


thanks for the help, i tried everything you said and every combination of 'not' '==' etc and it just doesnt want to work :/

but im sure i checked the existence of data using GetValue() before...


RE: headache - FakeTruth - 03-05-2011

You should not check data == true, data is never true, data is a number. However, tonumber can return nil if the given argument is not a number. So what you should do is check for nil instead of true.


RE: headache - Tim - 03-05-2011

Problem solved, cheers for the help guys!