Announcement

Collapse
No announcement yet.

Learning Lua, few small questions

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Learning Lua, few small questions

    Hi there.

    I come from the San Andrea's Multilayer Community. I've been scripting in pawn for many years.

    There are some differences between Lua and pawn could someone kindly explain a few things and anything else that may be helpful to know? Could someone kindly explain how you would load all files and if you really only need to use main.scm?

    I was viewing the base game mode and I noticed these two items.
    db = false
    PlayerData = { }
    I'm not sure why the dB = false.

    Also where are the variables created for global use in player data? Also why are there braces around the playerdata what exactly does this mean?

    In the script I see:

    PlayerData[player].cash

    ​​​​​​Etc but I don't see where the '. Cash.' is created.

    Thanks for any help.

    #2
    Hey there,

    You can find most of the information on the lua.org, so making this thread is useless. However, I'm still going to answer your questions and not be an arse, but if you have any more questions, check out the link.

    You can create global variables without using any keyword, unlike in Pawn where you had to use new or static, as Lua is not a language with C-like syntax. and PlayerData is a table, just like an array, and since enumerations don't "really" exist in Lua, you do something like PlayerData[playerid].cash.

    Quoting from the Lua.org
    Tables are the sole data-structuring mechanism in Lua; they can be used to represent ordinary arrays, lists, symbol tables, sets, records, graphs, trees, etc. To represent records, Lua uses the field name as an index. The language supports this representation by providing a.name as syntactic sugar for a["name"]. There are several convenient ways to create tables in Lua.
    If any record that doesn't exist within a certain table, it'll return the value of nil. So as long as you don't have any thing in the .cash, or .score, or .cds, it's value will be nil.

    Could someone kindly explain how you would load all files and if you really only need to use main.scm?
    This isn't GTA lmao. Read the dev wiki.

    However, don't expect to grasp Lua if you aren't going to read the Wiki and expect to use your Pawn knowledge here, it won't come much handy.
    Last edited by Logic_; 11-17-2019, 06:57 AM.
    Game Developer @ Onset RP // Early Access tester // Wiki Contributor

    Comment


      #3
      Thanks for the information, even if you did answer it sort of passive aggressively.

      I have read the wiki, but for the most part I understood, but not within those points.

      Comment


        #4
        Originally posted by Grant View Post
        Thanks for the information, even if you did answer it sort of passive aggressively.

        I have read the wiki, but for the most part I understood, but not within those points.
        Sorry, if you felt like that way. But what was the real confusing part? Maybe this can help the new comers to learn Lua faster.
        Game Developer @ Onset RP // Early Access tester // Wiki Contributor

        Comment


          #5
          It's alright, it helped me.

          Essentially the idea of not creating global variables and such was confusing me, as well as how the file system works in terms of how it loads and such. Looking into it. PAWN has just 1 script unless you use includes.

          Comment


            #6
            Yeah. And it's because that SA-MP only had server side scripting, Garry's mod, Onset, MTA, FiveM and such all have client side scripting to enhance the experience. You can still write your whole script in one server side and one client side module but it depends on person to person on how they want to do it, either in different sub-packages (or sub-resources) or one.

            You will learn as you interact with the community in the Discord's #scripting channel. Looking forward to more queries and questions to answer.
            Game Developer @ Onset RP // Early Access tester // Wiki Contributor

            Comment

            Working...
            X