• 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!

Helper lua functions

Codex NG

Recurrent Flamer
Joined
Jul 24, 2015
Messages
2,994
Solutions
12
Reaction score
1,657
Every time I think of a useful function that can be used in a script I am going to post it here...

These functions will be useful in all distro's as I know and you shall soon or eventually see that the code is the same :)

Also these functions might help you understand the language a little better, I will update this thread as time goes on.

Code:
-- for those times you just want to know if something explicitly contains a value
function isset(value)
    return value and true or false
end

Code:
-- for those times when you just want to know if an index exists within a table
function isIndexInTable(table, index)
    for i, _ in pairs(table) do
        if i == index then
            return true
        end
    end
    return false
end

Code:
-- this will allow you to extract numbers from a string while converting them to a number 
-- and return either as a table or multiple values
-- please note presently this function does not work with floating point values
function parseInt(words, split)
    local t = {}
    for number in words:gmatch('%d+') do
        t[ #t + 1 ] = tonumber(number)
    end
    if split then
        return unpack(t)
    end
    return t
end
 
Last edited:
Code:
function isset(value)
    return value and true or false
end

Code:
function isset(value)
    return value ~= nil
end

??

Code:
-- for those times when you just want to know if an index exists within a table
function isIndexInTable(table, index)
    for i, _ in pairs(table) do
        if i == index then
            return true
        end
    end
    return false
end

Code:
-- for those times when you just want to know if an index exists within a table
function isIndexInTable(table, index)
   return table[index] ~= nil
end

Code:
-- this will allow you to extract numbers from a string while converting them to a number 
-- and return either as a table or multiple values
-- please note presently this function does not work with floating point values
function parseInt(words, split)
    local t = {}
    for number in words:gmatch('%d+') do
        t[ #t + 1 ] = tonumber(number)
    end
    if split then
        return unpack(t)
    end
    return t
end

Code:
--Works also with float
function parseInt(str, split)
    local t, value = {}, nil
    for word in str:gmatch('%S+') do
        value = tonumber(word)
        if(value)then
            table.insert(t, value)
        end
    end

    if split then
        return unpack(t)
    end
    return t
end
 
Last edited:
Code:
function isset(value)
    return value and true or false
end

Code:
function isset(value)
    return value ~= nil
end

??

Code:
-- for those times when you just want to know if an index exists within a table
function isIndexInTable(table, index)
    for i, _ in pairs(table) do
        if i == index then
            return true
        end
    end
    return false
end

Code:
-- for those times when you just want to know if an index exists within a table
function isIndexInTable(table, index)
   return table[index] ~= nil
end

??
You are not seeing the bigger picture :p
Sure I could write all the code as small as humanly possible, but how will people understand the execution of the code or how it can be used in other ways?

Your avatar suits you :)
 
Function name already solves it. This is not about being short code, this is about performance, smartass.
 
Unless the bigger picture is writing overly complicated functions, I don't see it either.
Maybe you should enlighten us.
 
Great approach, for a retard like you. Have a good day, maybe one day you will actually learn something.
 
Unless the bigger picture is writing overly complicated functions, I don't see it either.
Maybe you should enlighten us.
OOO look it is Summ.. The king noob coder of all the moderators combined
Great approach, for a retard like you. Have a good day, maybe one day you will actually learn something.
I know more about teaching programming than any of you on this forum, everyone tries to get people to run before they even learn to crawl, maybe if you got your head out of your own ass and paid attention you would learn something.
 
Honestly, Mods Became a little butthurt, if you have something good to say then say it, no need to criticize,Ya We all Know how Codex is,but atleast he is trying to help.
 
Honestly, Mods Became a little butthurt, if you have something good to say then say it, no need to criticize,Ya We all Know how Codex is,but atleast he is trying to help.
con2.png
 
You really need control yourself as @Summ said. You said once that you have 39 years old then show some maturity, the OtLand community beg for it, all thread you're fighting with someone. You are acting like a kid. By the way, please stop saying you need to learn lua/c++/any other shit - is not everyone who wants learn lua/c++/etecera - need is a strong word and none need learn something, only if he wants and you must understand that.

Grow up and shoot me a rage comment.
 
You really need control yourself as @Summ said. You said once that you have 39 years old then show some maturity, the OtLand community beg for it, all thread you're fighting with someone. You are acting like a kid. By the way, please stop saying you need to learn lua/c++/any other shit - is not everyone who wants learn lua/c++/etecera - need is a strong word and none need learn something, only if he wants and you must understand that.

Grow up and shoot me a rage comment.
If you want people to take you seriously as a developer than you need to know a developer skill-set and yes you do NEED to learn these languages, or your're just another mooch.

This is or was once a developer's community now its just a bunch of lazy ass people who are too ignorant to know when some one is telling them they should learn x or y, it is for their own good.

Kids are lazy, adult's take on responsibility..

I posted those screen shots in protest and to enlighten those around you that these moderators don't give a flying fuck about any of you and would rather keep you all right where you are, clueless and in the dark.

If you don't like what I have to say than you can 1st go fuck yourself and 2nd put me on ignore..


PS#
Summ, Stop removing my screenshots..
 
Last edited by a moderator:
If you want people to take you seriously as a developer than you need to know a developer skill-set and yes you do NEED to learn these languages, or your're just another mooch.

This is or was once a developer's community now its just a bunch of lazy ass people who are too ignorant to know when some one is telling them they should learn x or y, it is for their own good.

Kids are lazy, adult's take on responsibility..

I posted those screen shots in protest and to enlighten those around you that these moderators don't give a flying fuck about any of you and would rather keep you all right where you are, clueless and in the dark.

If you don't like what I have to say than you can 1st go fuck yourself and 2nd put me on ignore..

Jesus christ, just stop being spoiled child. Are you making a protest in a forum? Jesus, you are very virgin.

Ooh, I see now, you are lacking. Just wants attention, that is sad.
 
What Are You Guys Talking about actually? he just said the truth about otland, ya otland was active before,now there are just like 5-6 skilled scripters and the

others are here to copy their scripts, download a server,post in "Support" for help, and get money, and most of them dont even know how to put / change a single

line in either a lua or C++ code,Ya Codex should not Be telling everyone to learn Lua But if the community continues to offer help for noobs, then everyone is just

gonna be a noob and none will be able to help,Also Both of Codex and EvulMastah should Get a Warning
 
Why no one has banned this guy already? He helps no one, he just want to feel that his knowledge is worth something... He really don't do this for help, he just do all for his dumb ego ._. What's up with the moderators?
 
If you want people to take you seriously as a developer than you need to know a developer skill-set and yes you do NEED to learn these languages, or your're just another mooch.

This is or was once a developer's community now its just a bunch of lazy ass people who are too ignorant to know when some one is telling them they should learn x or y, it is for their own good.

Kids are lazy, adult's take on responsibility..

I posted those screen shots in protest and to enlighten those around you that these moderators don't give a flying fuck about any of you and would rather keep you all right where you are, clueless and in the dark.

If you don't like what I have to say than you can 1st go fuck yourself and 2nd put me on ignore..


PS#
Summ, Stop removing my screenshots..

If you really want to help the community, don't post overcomplicated codes.

Code:
--Works also with float
function parseInt(str, split)
    local t, value = {}, nil
    for word in str:gmatch('%S+') do
        value = tonumber(word)
        if(value)then
            table.insert(t, value)
        end
    end

    if split then
        return unpack(t)
    end
    return t
end

That pattern is going to work if its not spaces, its not straightforward. And it would not work for things like "3,3" or "3>3" as there is no spaces its going to use tonumber("3,3") and its going to return nil

Thats how I would do it:
Code:
function parseSomeShit(str, split)
    local ret = {}
    str:gsub("[%d%.*]+", function(s) table.insert(ret, tonumber(s)) end)
    if split then
        return unpack(ret)
    end
    return ret
end
 
Last edited:
Back
Top