Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   enum (https://forums.graalonline.com/forums/showthread.php?t=66073)

Yen 05-17-2006 02:02 AM

enum
 
How does it work?
I've used it before, but I can't remember how now.

enum MODE{"FOLLOW","STAY","ATTACK"};
enum MODE{FOLLOW,STAY,ATTACK};
MODE.FOLLOW;
this.action = MODE.FOLLOW;

Help? I have no clue how it works.

excaliber7388 05-17-2006 03:07 AM

I'm not sure how Graal does it, but I think in C++ an enumeration is a word constant for numbers, in your example, follow would be 0, stay as 1, and attack as 2 and so on. But this isn't the format I've seen it in, I've never seen using mode.follow or the MODE at the front of the enumeration, so I could be very wrong XD

Angel_Light 05-17-2006 03:38 AM

looks as if some array o.O

napo_p2p 05-17-2006 04:00 AM

Quote:

Originally Posted by Yen
this.action = MODE.FOLLOW;

From what I remember about enumerated types, that would give this.action the value of 0. (this.action = MODE.ATTACK //this.action is 2).

It's used mostly so that you don't have to remember '2' means attack. You can just use MODE.ATTACK instead.

Examples:
PHP Code:

enum foo{abc}; 

is sort of like:
PHP Code:

foo.0;
foo.1;
foo.2

You can also do:
PHP Code:

enum foo{4810}; //4, 8, 10 are arbitrary 

Which is like:
PHP Code:

foo.4;
foo.8;
foo.10


Angel_Light 05-17-2006 01:32 PM

All hail Napo =p

Skyld 05-17-2006 04:54 PM

Quote:

Originally Posted by excaliber7388
I'm not sure how Graal does it, but I think in C++ an enumeration is a word constant for numbers, in your example, follow would be 0, stay as 1, and attack as 2 and so on. But this isn't the format I've seen it in, I've never seen using mode.follow or the MODE at the front of the enumeration, so I could be very wrong XD

PHP Code:

enum MODE
{
  
IDLEWALK


... produces the following possibilities:
  • MODE.IDLE, with value 0
  • MODE.WALK, with value 1
Also.
PHP Code:

enum
{
  
IDLEWALK


... produces the following possibilities:
  • IDLE, with value 0
  • WALK, with value 1

excaliber7388 05-17-2006 05:08 PM

Yeah I've never done it with something in front of the definitions, I suppose it would be quite usefull


All times are GMT +2. The time now is 05:46 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.