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

Lua Broken Down

This is why the title of the tutorial is called Lua Broken Down and not The TFS Framework Broken Down.

As I said nothing I said is directly linked to TFS, all Lua interfaces works pretty much the same way.
There is no reason to load a function 2 times.





@WibbenZ isn't saying you need to teach "the latest TFS framework", he's saying your code is inefficient.
Thank you, just read my posts once again to try and understand how he coulden't.





Everything I have discussed in this tutorial up to the present is essential to know in order to write efficient scripts.

Now if you have nothing to positive to add please leave this thread and go write your own.

You have to be able to take all and any respons of all the codes you write.
In this case no, I can state it once again - your code might work, but can be alot better.

If you can't take criticism you should not post a thread like this, there will always be others with more knowledge then you.
All of us has to accept that.

* Reference this to string.format:
I can only speak for myself, but when I post something on our github page I expect people to write "do it this way insted, it's better".
After I do a quick google check and verify that it would actually be better, I start using that way insted aswell as patch it on my PR.

I don't go running away saying no you are totally wrong, ive done things like this before and it has worked.

And to make it more clearer ill quote one of your posts.
Math Example:
Code:
2 x 2 x 2 x 2 x 2 = 10 -- long way
2 x 5 = 10 -- short way
 
Everything I have discussed in this tutorial up to the present is essential to know in order to write efficient scripts.

Now if you have nothing to positive to add please leave this thread and go write your own.
Whoa, calm down. Why are you attacking everyone trying to help you? I never said your tutorial was bad, or that you're wrong, I was just trying to help you understand what Wibbenz was saying. You really need to grow up if you can't take feedback. Your explanations are fine, but your onEquip() onDeEquip() is inefficient. Instead of attacking Wibbenz (and myself) for helping you write better code, why don't you try to understand why your code is inefficient and why Wibbenz's is better?

I have no desire to write a Lua tutorial, or any basic programming one for that matter. Why you're wasting your time writing one here while there are millions on the internet that can be found from a simple google search is beyond me, but to each their own.

Like I said, your explanations and everything are fine, but take feedback in stride and don't be a baby about it.
 
Currently too busy at work to complete this tutorial or rewrite it because it definitely needs a re-write, won't be able to focus on this til possible mid September :(
 
The very first script you put in this tutorial stating it is functional but not readable.....Its not functional, there is a typo in one of the functions.
 
This can be good to link to :p
But I dislike that you go for the legacy interface insted of the meta interface.

You should how ever correct things like this;
Code:
function onEquip(cid, item, slot)
    local bonus = (isPremium(cid)) and xpToAdd['premacc'] or xpToAdd['freeacc']
    local rate = getPlayerExpRate(cid, true) + bonus
    if getPlayerStorageValue(cid, xpStorage) == -1 then
        setPlayerStorageValue(cid, xpStorage, 1)
        doPlayerSetExperienceRate(cid, rate)
        doPlayerSendTextMessage(cid, 22, "You have gained "..(bonus * 100).."% bonus exp!")
        if not isPremium(cid) then
            doPlayerSendTextMessage(cid,21,"If you were a premium player you would receive "..(xpToAdd['premacc'] * 100).."% instead of "..(xpToAdd['freeacc'] * 100).."% as a free account while using this ring.")
        end
        doTransformItem(item.uid, 7697, 1)
    end
    return true
end

To this:
Code:
function onEquip(cid, item, slot)
    if getPlayerStorageValue(cid, xpStorage) ~= -1 then
        return true
    end

    local isPremium = isPremium(cid)
    local bonus = isPremium and xpToAdd['premacc'] or xpToAdd['freeacc']
    setPlayerStorageValue(cid, xpStorage, 1)
    doPlayerSetExperienceRate(cid, getPlayerExpRate(cid, true) + bonus)
    doPlayerSendTextMessage(cid, 22, "You have gained " .. (bonus * 100) .. "% bonus exp!")
    doTransformItem(item.uid, 7697, 1)

    if not isPremium then
        doPlayerSendTextMessage(cid,21,"If you were a premium player you would receive " .. (xpToAdd['premacc'] * 100) .. "% instead of " .. (xpToAdd['freeacc'] * 100) .. "% as a free account while using this ring.")
    end
    return true
end

Mainly to make it quicker to load (no reason to load the if statment if we are not gonna use it).
And to also not load "isPremium(cid)" 2 times.

You can also add things like the format function:
Code:
string.format("Hi %s!", player:getName())


// Edit
Forgot, always use the constants insted of the integer it resembles.
Ex.
Code:
doPlayerSendTextMessage(cid, 22
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR,

Just look at when 1.1 got updated to 10.76, alot of the integers got changed (most likely due to cipsoft noticing alot of ppl not using the constants = more work to update).

@WibbenZ isn't saying you need to teach "the latest TFS framework", he's saying your code is inefficient.

This tut is clearly for beginners, it's not about efficiency.
A script converted to the most efficient, shortest code possible - is impossible to follow for the inexperienced.

Start up an advanced LUA functions thread if you want to pander to the elites over code quality and start a pissing contest.


@Codex NG keep at it man;
The functions you're explaining are core for OT scripting and are explained in a way that most beginners should be able to grasp on to - excellent stuff!
 
This tut is clearly for beginners, it's not about efficiency.
A script converted to the most efficient, shortest code possible - is impossible to follow for the inexperienced.

Start up an advanced LUA functions thread if you want to pander to the elites over code quality and start a pissing contest.


@Codex NG keep at it man;
The functions you're explaining are core for OT scripting and are explained in a way that most beginners should be able to grasp on to - excellent stuff!

Well I don't think the code I changed got complicated?
To put it simple: Return if you don't need the code below.

if I have 2 apples but I need 3, then ill go back and get one more - or should I see what will happen if I have 3 apples aswell?

Lua is not advanced at all, the things that can be hard (and I still today can notice that) is remembering functions, what they do, how they work etc etc.
But once you get into basic Lua you should have no problems atleast starting with any Lua interface, mainly since the basic functions never change.

Also when I started I had huge problems understanding the for loops, since I found ipairs examples.
While the for i = 1, 5 is alot easier to understand.

Code:
for _, player in ipairs(Game.getPlayers()) do

local players, player = Game.getPlayers()
for i = 1, #players do
player = players[i]

But we all think diffrent things when it comes to making it easy.
Just look at the 0.x Lua interface hard as hell.... I still today can't write a full script without looking for a function name.
Then look at 1.x interface and it should not take more then a couple of days / weeks to get the hang of it.
 
Apparently you have a tough time understanding what I said in my previous post so I will put it in bold for you.
The point of this tutorial is to teach the lua language and not the latest tfs framework, to start with basic concepts and then eventually move on to more complex aspects of the language.

This is why the title of the tutorial is called Lua Broken Down and not The TFS Framework Broken Down.

If people don't understand the core language then how do you expect people to write efficient scripts in any framework?

Edit:
I'll assume by your attitude towards this thread you have never read 1 book on any programming language.
Similar to mathematics when a language is taught you are always shown the long way to do things 1st and then you are shown the short-cuts

Math Example:
Code:
2 x 2 x 2 x 2 x 2 = 10 -- long way
2 x 5 = 10 -- short way

Anyone can read a tutorial or book on any language but it doesn't guarantee your going to understand the concepts until you test what you have learned.

So that is the point here is to introduce the basic concepts of the language while breaking it apart step by step and using what we just learned in conjunction with what we already know.

I'd like to volunteer to be the dick that notes 2 x 2 x 2 x 2 x 2 = 32 not 10 xD I think you were looking for + not x :D
 
I'd like to volunteer to be the dick that notes 2 x 2 x 2 x 2 x 2 = 32 not 10 xD I think you were looking for + not x :D
thanks, shit happens, life goes on
Can I be a dick & say all your "systems" are just a copy & paste of the original with a name change?
 
Back
Top