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: show of hands, who doesn't know enumeration

Previous Thread :: Next Thread 
amanda is not online. amanda
Joined: 21 Nov 2006
Total Posts: 5925
17 Mar 2015 01:09 PM
ok put your hands down

--

local part = script.Parent

part.FormFactor = "Symmetric"
part.FormFactor = Enum.FormFactor.Symmetric

--these do the exact same thing

--

now at first you are like

"why?" because you are thinking the first one works, and it is way shorter

but lets look at the following code:

local part = script.Parent
part.FormFactor = "Symmetric"

if part.FormFactor == "Symmetric" then
print("lol see! you can use shortcuts!")
elseif part.FormFactor == Enum.FormFactor.Symmetric then
print("enums man, who would of thought")
end

--

The main reason I actually got into Enumeration was because of ContextActionService. I'm experimenting a lot with functions triggered by different user input, so 2 useful pages to me were the following:

http://wiki.roblox.com/index.php?title=API:Enum/KeyCode
http://wiki.roblox.com/index.php?title=API:Enum/UserInputType
Report Abuse
amanda is not online. amanda
Joined: 21 Nov 2006
Total Posts: 5925
17 Mar 2015 01:12 PM
because "Symmetric" is a string, and the formfactor isn't equal to a string, it is equal to Enum.FormFactor.Symmetric, an enum

Report Abuse
LucasLua is not online. LucasLua
Joined: 18 Jun 2008
Total Posts: 7386
17 Mar 2015 01:18 PM
Check this out:


for i, v in pairs(Enum.FormFactor:GetEnumItems()) do
print(v.Name, v.Value)
end


will print:

Symmetric 0
Brick 1
Plate 2
Custom 3
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
17 Mar 2015 01:19 PM
I use Enums because I can't remember the names of everything.
Report Abuse
LucasLua is not online. LucasLua
Joined: 18 Jun 2008
Total Posts: 7386
17 Mar 2015 01:20 PM
But don't you still need to know the names of everything in order to get the Enum object..?
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
17 Mar 2015 01:21 PM
No you can use the popup menu and scroll through all of them.
Report Abuse
amanda is not online. amanda
Joined: 21 Nov 2006
Total Posts: 5925
17 Mar 2015 01:21 PM
I know Lucas, that's pretty awesome imo because you don't even have to go to the wiki or anything to check.

However, doing that with KeyCode will spam your output pretty badly. :)
Report Abuse
amanda is not online. amanda
Joined: 21 Nov 2006
Total Posts: 5925
17 Mar 2015 01:23 PM
I totally didn't know what all those things were in the Object Browser.

This makes my life easy. :3
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
17 Mar 2015 01:25 PM
Just a side note, the only reason strings and integers are allowed in assigning an Enum property is because the __newindex metamethod of Roblox objects handles it.
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
17 Mar 2015 01:43 PM
I don't use enumerations unless I'm making them myself for internals.
Report Abuse
kert109 is not online. kert109
Joined: 31 Dec 2009
Total Posts: 681
17 Mar 2015 01:50 PM
In case you didn't figure it out yet, you could also use the numbers, rather then the Strings and the Enums.
Report Abuse
amanda is not online. amanda
Joined: 21 Nov 2006
Total Posts: 5925
17 Mar 2015 01:53 PM
because everyone knows that Material 864 is Pebble, of the top of their heads.

it totally wouldn't be easier to do Enum.Material.Pebble
Report Abuse
amanda is not online. amanda
Joined: 21 Nov 2006
Total Posts: 5925
17 Mar 2015 01:56 PM
I think it's interesting to know all the ways you can get the same result, however.

There are times when you would want to use integers instead of strings, strings instead of enums.

I can think of a few tricky math scripts that would take advantage of the different possible datatypes.
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