generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Good simple scripting trick

Previous Thread :: Next Thread 
XlegoX is not online. XlegoX
Joined: 16 Jun 2008
Total Posts: 14955
25 Aug 2011 11:05 PM
-Use double quotes when writing a string literal intended for the user to see, and which won't effect the script in any way it it's changed.
-Use single quotes when writing a string literal which is purely an identifier for the purposes of the script, and will require other changes if it is changed.

Benefits:
-Consistency of which type of quote you use, has style benefits.
-You'll know immediately on sight weather it's safe to change a string literal somewhere, or you'll need to make sure that it doesn't break anything when changing it.
-Consistency with other languages: Typically single quotes are used for "lightweight" entities, such as identifiers, as opposed to double quotes which are used for longer strings of text. Also, in English double quotes represent an quote, a longer piece of text.

Simple but useful. It's led me to catch bugs before they happened a couple of time in the few months I've been using it, and it improves code readability surprisingly much.
Report Abuse
ENET is not online. ENET
Joined: 01 Jan 2010
Total Posts: 4820
25 Aug 2011 11:08 PM
Ok so I know it is rare xLEGOx uses incorrect grammar so I won't to correct him...

"sight weather it's "
weather should be whether!
YAY now xLEGOx Hates me!

Just kidding, I like this might start using it.
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
25 Aug 2011 11:08 PM
Never bothered doing that before.

­<'+1 Post. Ujelly?'>
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
25 Aug 2011 11:10 PM
ENET, there are a few grammar errors, but I'm sure they were unintentional.

he forgot an 's' on "time" :p

Pretty obvious grammar error, it was most likely, if not for sure a typo.

­<'+1 Post. Ujelly?'>
Report Abuse
XlegoX is not online. XlegoX
Joined: 16 Jun 2008
Total Posts: 14955
25 Aug 2011 11:17 PM
I make a lot of typing errors when I'm writing posts. They're maybe going to be read at most, what? 100 times? So I don't really proofread them, just briefly glance over them for any really glaring errors.

If you looked at my posts and did some statistical analysis on them you'd find lots of missing s' and what not. It's too bad I'm not a moderator anymore, I can't fix them anymore when I notice them later.
Report Abuse
ENET is not online. ENET
Joined: 01 Jan 2010
Total Posts: 4820
25 Aug 2011 11:19 PM
@xLEGOx True that. I just wish teachers would think that way. I mean they are the only ones reading my report, why should I make it perfect for them?!
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
25 Aug 2011 11:19 PM
xLego, I had always thought that you were a paid moderator, such as briguy[insert numbers here]

­<'+1 Post. Ujelly?'>
Report Abuse
XlegoX is not online. XlegoX
Joined: 16 Jun 2008
Total Posts: 14955
25 Aug 2011 11:26 PM
"@xLEGOx True that. I just wish teachers would think that way. I mean they are the only ones reading my report, why should I make it perfect for them?!"

I'd have to disagree there. In a forum post, especially in a closely knit community like Scripters, it's an informal setting where all you need to do it get your point across.

The whole point of most reports is to build your technical writing skills, which perfect form is a part of. When I'm writing something that more people will see when I make very sure that there aren't any errors, and I wouldn't be able to do that without the skills learned in language arts classes. In fact I would say that my writing skills right now aren't very good because I haven't done any serious papers for a year and a half now.
Report Abuse
XlegoX is not online. XlegoX
Joined: 16 Jun 2008
Total Posts: 14955
25 Aug 2011 11:29 PM
@nate890
I wasn't 18 at the time that the Forum mods were abolished, and now they've limited hiring to local people to simplify things for the company. I've got enough to do right now anyways though, so it's not an issue.
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
25 Aug 2011 11:33 PM
I don't quite understand how it was a child labour law. If anything, it was an added bonus.

I mean, if they were forcing you to delete post, then sure, I guess it could classify as child labour.

­<'+1 Post. Ujelly?'>
Report Abuse
Avolition is not online. Avolition
Joined: 20 Apr 2011
Total Posts: 708
26 Aug 2011 12:08 AM
i thought you said you resigned, not got fired. maybe that was someone else. anaminus, i bet.
Report Abuse
JulienDethurens is not online. JulienDethurens
Joined: 11 Jun 2009
Total Posts: 11046
26 Aug 2011 06:00 AM
I always do that, since I seen Camoy doing it once. I find it a great idea and it is, in fact, really useful. Believe what xLEGOx is saying, he's completely right. It makes the code look better and can help you to avoid some errors.
Report Abuse
ENET is not online. ENET
Joined: 01 Jan 2010
Total Posts: 4820
26 Aug 2011 06:04 AM
@XlegoX I was being sarcastic :)...
Report Abuse
NXTBoy is not online. NXTBoy
Joined: 25 Aug 2008
Total Posts: 4533
26 Aug 2011 02:48 PM
I would argue that you shouldn't have any strings which are used internally. Some kind of enum constant would be better:

    function enum(names)
        local enum = {}
        for _, name in ipairs(names) do
            enum[name] = {}
        end
        return enum
    end

Example:

    local Fruit = enum { "Apple", "Pear", "Banana" }

print(Fruit.Apple == Fruit.Pear) -- False
print(Fruit.Apple == "Apple") -- False
print(Fruit.Apple == Fruit.Apple) -- True
Report Abuse
XlegoX is not online. XlegoX
Joined: 16 Jun 2008
Total Posts: 14955
26 Aug 2011 03:03 PM
My own Enum implementation:

Utility function which it needs:
errMT_Cache = {}
function strict(name)
local v = errMT_Cache[name]
if not v then
local errMT = {
__index = function(obj, inx)
error("Can't get `"..name.."::"..inx.."`")
end,
__newindex = function(obj, inx, val)
error("Can't set `"..name.."::"..inx.."`")
end,
}
v = function(tb)
return setmetatable(tb, errMT)
end
errMT_Cache[name] = v
end
return v
end

Code:
function enum(name)
return function(values)
local strictName = 'Enum::'..name
local valueLookup = {}
for key, value in pairs(values) do
value.Name = key
strict(strictName)(value)
valueLookup[value] = true
end
function values.expect(obj)
return valueLookup[obj] or false
end
return strict(strictName)(values)
end
end

Used like:
local MyEnum = enum"MyEnum"{
Bar = {},
Foo = {},
}

Then you can also check values:
function f(arg)
if not MyEnum.expect(arg) then
--bad argument!
end
end
Report Abuse
NXTBoy is not online. NXTBoy
Joined: 25 Aug 2008
Total Posts: 4533
26 Aug 2011 03:47 PM
Could you possibly explain the strict function? I'm having difficulty understanding its purpose.
Report Abuse
XlegoX is not online. XlegoX
Joined: 16 Jun 2008
Total Posts: 14955
26 Aug 2011 04:41 PM
Sets the metatable of the thing you call it on so that you can't get/set nil values of that object. It helps in debugging since it means you'll get an error right away when you try to get something which is null rather than silently getting a nil-value instead.
Report Abuse
Merlin11188 is not online. Merlin11188
Joined: 20 Dec 2007
Total Posts: 4158
26 Aug 2011 04:55 PM
"Also, in English double quotes represent an quote, a longer piece of text."
I'm having serious problems with that sentence. Let me fix it:
"Also, in English double quotes represent a quote, no matter how long it may be; however, single quotes represent a quote within a quote. Always."
Ahh. Much better.
Report Abuse
chikenugget is not online. chikenugget
Joined: 09 May 2009
Total Posts: 2552
26 Aug 2011 04:57 PM
I read this thread because it said simple on the top :)

~~ In Soviet Russia, scripts write you. ~~
~~ ChildAdded is better than PlayerAdded ~~
Report Abuse
Nikolas5411 is not online. Nikolas5411
Joined: 03 Apr 2010
Total Posts: 2117
26 Aug 2011 05:08 PM
Nice trick, I have one to share too! Well, its not a "trick" trick, but here it is:
[[
Instead of using "" to print stuff, you can
also use ''. Just look at the example below:
print("Hello World!")
new version
print('Hello World!')
or...
print('Hello World!'Hello!'World!')
Tip: prints the text into output.
Report Abuse
sdfgw is not online. sdfgw
Top 50 Poster
Joined: 08 Jan 2009
Total Posts: 41681
26 Aug 2011 05:10 PM
"however, single quotes represent how long it may be; however, single quotes represent quote within a quote."

QUOTECEPTION

I JUST WATCHED THAT FILM IT'S SO EPIC IT MAKES ME WANT TO BUILD A PLACE WITHIN A PLACE
Report Abuse
booing is not online. booing
Joined: 04 May 2009
Total Posts: 6594
26 Aug 2011 06:38 PM
ogm hi xlgeo
Report Abuse
xSIXx is not online. xSIXx
Joined: 06 Aug 2010
Total Posts: 9202
26 Aug 2011 06:39 PM
too much big words. D:
Report Abuse
sdfgw is not online. sdfgw
Top 50 Poster
Joined: 08 Jan 2009
Total Posts: 41681
27 Aug 2011 08:19 AM
hey I actually forgot to post what I was gonna say

When I was at work experience, the bloke there told me to never put literals in the middle of the script because it was bad practice - he said to define them at the top of the program

:S
Report Abuse
mew903 is not online. mew903
Joined: 03 Aug 2008
Total Posts: 22071
27 Aug 2011 08:23 AM
I use 'a' and [[a]] instead of "a"

HATE ME NOW!

print('This post is now related because meowmix said so.')
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image