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: A few questions about enumerations in C++

Previous Thread :: Next Thread 
Flurite is not online. Flurite
Joined: 03 Apr 2011
Total Posts: 5386
21 Mar 2012 04:06 PM
I have a few questions about enumerators in C++.

1. In ROBLOX, I believe that you can do: game.Workspace.Part.RightSurface = "Weld". In C++, you do: int variable = Lol. Is this just the standard syntax for C++ or is there a way to do: int variable = "Lol", and it will return the same result.

2. Is it possible for an enumerator to hold any data type other than numerical ones (such as strings)?

3. Does an enum have indices?
Report Abuse
TheMyrco is not online. TheMyrco
Joined: 13 Aug 2011
Total Posts: 15105
21 Mar 2012 04:09 PM
for 1 and 2:

http://msdn (DOT) microsoft (DOT) com/en-us/library/2dzy4k6e(v=vs (DOT) 71) (DOT) aspx
Report Abuse
myrkos is not online. myrkos
Joined: 06 Sep 2010
Total Posts: 8072
21 Mar 2012 04:12 PM
Enums, simply put, are variable types you create that can only hold specific values.

For instance:

enum Answer {yes,no};

Answer cake = yes;

cake = no;

etc.

In the end of the day they're just usually integers and each value corresponds to some integer number. Most probably in this case, yes = 0 and no = 1.
Report Abuse
Flurite is not online. Flurite
Joined: 03 Apr 2011
Total Posts: 5386
21 Mar 2012 04:38 PM
@myrkos,

Then enums are pure nooby. What is a time when they are actually useful?
Report Abuse
Legend26 is not online. Legend26
Joined: 08 Sep 2008
Total Posts: 10586
21 Mar 2012 04:40 PM
@Flurite,

Would you rather memorize what error code 1, 512, and 44 do or see something that you can understand? The same goes for a ton of things besides error codes. It's primarily for values that have a limited range.
Report Abuse
Flurite is not online. Flurite
Joined: 03 Apr 2011
Total Posts: 5386
21 Mar 2012 04:41 PM
Okay, so for readability enums are good.
Report Abuse
myrkos is not online. myrkos
Joined: 06 Sep 2010
Total Posts: 8072
21 Mar 2012 04:43 PM
It's good for setting options using bit stuff:

enum {cake = 1,pie = 2,cheese = 4,pizza = 8} food;

food = cake | pie | pizza;
Report Abuse
Flurite is not online. Flurite
Joined: 03 Apr 2011
Total Posts: 5386
21 Mar 2012 04:48 PM
o_O, I never saw enums like that before..
Report Abuse
Varp is not online. Varp
Joined: 18 Nov 2009
Total Posts: 5333
21 Mar 2012 05:11 PM
You could write a class that accepts

T x = "lol";

and acts like an enum. The question, though, is "Should you?", to which the answer is, "Almost certainly not."

Enums are really useful just for basically defining a bunch of named constants that support the operations == and !=. In addition to that, tricks like what myrkos shows are useful too (even better in C++11, since you get to decide the underlying type of an enum).
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