Good-bye camelCase, Hello delay()

Note: This is one of those highly technical articles. If you want something lighter then go here.

The latest build is primarily bug-fix release. However, we’ve added a couple of small scripting enhancements recently.

First, you may have noticed that most object members are now capitalized rather than “camelCase”. We’re supporting old scripts that call member functions that start in lower-case, but all new members will start with an upper-case character. (We’ve decided to standardize on the ‘.NET’ style with regards to capitalization)

Second, there’s a new global function called “delay”. It complements the wait() function that many of you use. delay takes 2 arguments: The first is a time to wait in seconds, the second is the function to call after the wait time has elapsed. delay continues executing, unlike wait, which blocks.

You’ll find delay is a very useful way to spawn a thread. You might use it in place of connecting to a Heartbeat event and then disconnecting later on. For example, the following code will print “Hello” and “world” followed by “!” a second later:

local c

function exclamation()
   c:disconnect()
   wait(1)
   print("!")
end

print("Hello")
c = game:GetService("RunService").Heartbeat:connect(exclamation)
print("world")

Here is the same functionality written with delay:

function exclamation()
   print("!")
end

print("Hello")
delay(1,exclamation)
print("world")

-Erik

About Erik Cassel

Co-Founder & Chief Scientist of ROBLOX. @CasselErik on Twitter

6 thoughts on “Good-bye camelCase, Hello delay()

  1. Erik Cassel

    I forgot to mention that that when the function passed to delay is called, the first argument will be the time elapsed. This is similar to wait() returning the elapsed time.

    function exclamation(t)
    print(“!”)
    print(“elapsed time = ” .. t)
    end

Comments are closed.