• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

A function to check storage if is string or not...

kito2

www.masteria.net
Joined
Mar 9, 2009
Messages
3,764
Solutions
1
Reaction score
227
Location
Chile, Santiago
Hi there, well if someone can make this: I need a function that check player storage if it is a string or number...
The idea of the function is to be used and see if the storage value is a string, then it will be changed for a number.
 
LUA:
local function checkStorage(pid, storage)
   return setPlayerStorageValue(pid, storage, tonumber(getPlayerStorageValue(pid, storage)))
end

That won't check since it's set~ and you can't use tonumber in a string, tonumber is to check if parameter is a number, not to convert it to one (unless it is a number).
 
That won't check since it's set~ and you can't use tonumber in a string, tonumber is to check if parameter is a number, not to convert it to one (unless it is a number).

I thought tonumber converted a numeric string into a number (although I guess with the way lua handles typing it doesn't matter).

K try this..

LUA:
local function checkStorage(pid, storage)
   local storageInNumFormat = tonumber(getPlayerStorageValue(pid, storage))

   if (storageInNumFormat ~= nil) then
      setPlayerStorageValue(pid, storage, storageInNumFormat)
   else
      setPlayerStorageValue(pid, storage, -1) -- if it's a string it will be changed to -1
   end

   return true
end
 
LUA:
if tonumber(a) ~= nil then
   --it's a number
end
?

? If you're asking if that's the correct use, then yes you could check that way.
This is an example, so you can notice:
LUA:
a = {1, "1", "a"}
for i = 1, 3 do
    if tonumber(a[i]) then
       print(" " .. i .. " ")
    else
        print("fail")
    end
end

Will return
Code:
 1 
 2 
fail

Which means, 1 is number, "1" is number (you can only convert strings that contain numbers), "a" fails.
 
? If you're asking if that's the correct use, then yes you could check that way.
This is an example, so you can notice:
LUA:
a = {1, "1", "a"}
for i = 1, 3 do
    if tonumber(a[i]) then
       print(" " .. i .. " ")
    else
        print("fail")
    end
end

Will return
Code:
 1 
 2 
fail

Which means, 1 is number, "1" is number (you can only convert strings that contain numbers), "a" fails.

Kk, that's what I thought after reviewing what I posted, thanks a bunch for the wisdom!
 
Back
Top