CVExtra -- Super Module Script (DEVELOPMENT FORUM)


  • @Phlegethon5778 I cannot disagree, that wiki is quite trash, I never go to it for scripting help. But as you stated, rather to figure out that function I forgot.

    But now it doesn't even teach ya about base, global functions aaaa

    But I'll take your word for it to look up the Lua 5.1


  • @Cvieyra2test, I recommend the reference manual. It's helped me immensely. Some parts are confusing and hard to understand, and you'd probably never encounter most of them on Roblox, so you can ignore those parts.


  • Chapter two is probably going to be the most helpful to you.


  • @Cvieyra2test @Phlegethon5778

    Roblox Wiki for learning the Roblox API

    Lua official site for learning Lua

    I didn't know you can use string patterns to get information about the date. For example, os.date("%x") returns the date in string format MM/DD/YYYY.

    In string patterns %x is a hexadecimal. The wiki doesn't document that you can use this for os.date


  • Questions:

    How do I create a function like pairs() ? (I wish to make a function that can iterate through a userdata/table's metatable)

    Nevermind about the above, this article (https://www.lua.org/pil/7.3.html) just helped with that

    How do I convert the PlaybackSpeed property of Sound instances to musical notes?


  • @Cvieyra2test you don't, use playbackloudness instead lol


  • @Cvieyra2test You could use Game Hero's Midi Player as a reference. :p


  • @Fifkee reee that's how I'd do cool visual things like https://www.roblox.com/games/187659887/Audio-Visualizer

    @TheAlphaStigma Ooo thanks!

    The idea of me getting these notes 'n stuff is to create something actually similar to it.

    With PlayAudio, I plan to make a lengthy piece of audio that contains numerous instruments. And then, with those instruments, create something that people can make audio with. However I will certainly look into this Midi player for definite reference in both note definition and how I'd have my thing work out as well. I'm curious how they managed to do it on Studio, since you can't modify noises that are played in Roblox Studio, unless you can?


  • @Cvieyra2test

    How do I create a function like pairs() ? (I wish to make a function that can iterate through a userdata/table's metatable)

    pairs doesn't actually do much work other than return. It is literally written as

    function pairs(t)
        return next, t, nil
    end
    

    So when pairs is called on each iteration it's really next doing all the work.

    With this knowledge in mind you can get the metatable like this

    local function traverseMetatable(object)
        local mt = getmetatable(object);
    
        if (rawequal(type(mt), "table")) then --// there is a metatable
            return next, mt, nil;
        end
    end
    

  • Had a feeling it had to do something with next, just didn't know how to apply next to it. Thank ye' although


  • This post is deleted!

  • @sjr04Alt However, question, what is the third argument you have provided there,
    "nil"?

    It is known as "0" on the Lua wiki for ipairs, is it like the starting position or somethin'?


  • @Cvieyra2test I believe he's referring to this, where it reads

    The pairs function, which iterates over all elements in a table, is similar, except that the iterator function is the next function, which is a primitive function in Lua:
    
        function pairs (t)
          return next, t, nil
        end
    

  • 0_1555295049328_upload-ddab7055-8803-478d-97c4-f499171114af
    It finds the metatable, knows both the length and the stuff in it.

    But... It doesn't return anything with the return statement???

    It prints out an empty value in output.


  • @Cvieyra2test said in CVExtra -- Super Module Script (DEVELOPMENT FORUM):

    However, question, what is the third argument you have provided there,
    "nil"?
    It is known as "0" on the Lua wiki for ipairs, is it like the starting position or somethin'?

    ipairs is for traversing the array part of a table. It returns 0 since it adds 1 and Lua's arrays start at 1.

    @Phlegethon5778

    you use rawequal in too many unnecessary places. There is very rarely a need for it.

    To bypass the __eq metamethod. It's just a new habit of mine. Semicolons and my conditional expressions in parenthesis is also unnecessary but you don't complain about that?

    What if the metatable has its own metatable which has an __eq field? Hmm?

    @Cvieyra2test (again)

    You would not use it like this. I'll quote the PIL:

    The call next(t, k), where k is a key of the table t, returns a next key in the table, in an arbitrary order. (It returns also the value associated with that key, as a second return value.) The call next(t, nil) returns a first pair. When there are no more pairs, next returns nil.

    You don't need to use nil, you can just return next, mt. But the PIL returns nil as well so why not

    For ipairs, I'll go in a bit more depth.

    In that link, the iter function is called passing the argument of 0. This is the i parameter. It is incremented by 1. The next call will be iter(a, 1) and will then be a[2], and so on, until a nil value is encountered.

    For pairs (again x2), that is also why some people put next directly instead of calling pairs. This adds a negligible performance boost. Use pairs. It's clearer. Micro optimisations are never a good argument. You rarely need to use next, both inside or outside a generic for loop.


  • This post is deleted!

  • @Phlegethon5778 in ROBLOX, it's used a LOT, even by ROBLOX themselves.

    UDim2, Vector3, CFrame, and more datatypes have an __eq metamethod.

    just stop, the difference in performance and such is miniscule, like who cares


  • @sjr04Alt said in CVExtra -- Super Module Script (DEVELOPMENT FORUM):

    the difference in performance and such is miniscule

    He wasn't arguing performance though? :thinking:


  • @TheAlphaStigma

    rawequal just adds an unnecessary element of complexity and a function call, which isn't really necessary either.

    Function calls reeeeeee

Log in to reply
 

Looks like your connection to Scripting Helpers was lost, please wait while we try to reconnect.