Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


- - - - -

Enums?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 nebukadnezzar   Members   -  Reputation: 122

Like
Likes
Like

Posted 09 March 2004 - 05:53 PM

Can I youse enums and wich method does declare them to the vm? or should i use const int instead?? p.s: I''m very happy that you set up this forum

Sponsor:

#2 Henners   Members   -  Reputation: 122

Like
Likes
Like

Posted 09 March 2004 - 06:45 PM

In order to solicit help effectively, one needs to supply far more specific questions. Perhaps you could specify what language you are using, and what you are trying to accomplish with it.

No hard feelings of course, just trying to help

Henry

#3 EddHead   Members   -  Reputation: 140

Like
Likes
Like

Posted 09 March 2004 - 06:46 PM

I guess ''const int'' is better, or enums should function the same way const int should work. cos i would like to use it as ints for the system function that i pass the labels to.

Jayanth.K
Raptor Entertainment Pvt. Ltd.

#4 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 10 March 2004 - 12:28 AM

You can use the enums in your C source code, but not in the actual script as far as I know. You would need a bunch of cont ints there. So it doesn''t really matter what you use, you still have to cast them to something else if you want to modify them.

PS: Henners, we are talking about AngelScript. Visit the AngelCode website for more info: http://www.angelcode.com

#5 nihlist   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 March 2004 - 12:36 AM

Agreed, I have tried enums with no success in scripts.

I think the real problem is that there is no way to register them, I don''t see why the engine itself wouldn''t support them.

How about a RegisterEnumType() method in a later release?

nihlist



#6 Andreas Jonsson   Moderators   -  Reputation: 3416

Like
Likes
Like

Posted 10 March 2004 - 01:54 AM

Anything is possible

What exactly is it that you want from an enum type in the scripting languge?

Do you want to be able to declare enums in the scripts? Do you want to pass enums to script functions? Or perhaps you wish to declare a type that can hold integer values but nothing else?

Tell me more about how you would use the enums and I''ll see what I can do to include support for them.

www.AngelCode.com - game development and more...
AngelScript - free scripting library

#7 nebukadnezzar   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 March 2004 - 04:47 AM

I''d like to "register" the enum and simply work tih it

example (i declared an enum MyE {arm = 0, leg, hand} foo; )
so that i can write (in AS):
if (foo = leg) ...;

and it to pass it as param it would be useful too,
but it could be done with cast too

#8 Andreas Jonsson   Moderators   -  Reputation: 3416

Like
Likes
Like

Posted 10 March 2004 - 05:46 AM

It''s not a perfect solution but for now you could do the following:

const char scriptEnums[] =
"const int arm = 0;\n"
"const int leg = 1;\n"
"const int hand = 2;\n";

Then add this string to the engine before building your dynamically loaded scripts:

engine->AddScriptSection("scriptfile.as", loadedScript, sizeLoadedScript);
engine->AddScriptSection("enums", scriptEnums, sizeof(scriptEnums));
engine->Build();

Having a function for automatically register enum constants is not possible, I think. The only way is to have a precompiler parse the enum declaration from the C++ file and generate code that register each enumerated constant for you.



www.AngelCode.com - game development and more...
AngelScript - free scripting library

#9 nihlist   Members   -  Reputation: 122

Like
Likes
Like

Posted 11 March 2004 - 01:12 AM

Thats a certainly a workable solution to my issues with enums.

In my previous post I was thinking of a:

RegisterEnumType(const char * enumName, int elementCount, const char ** elements)

With AS friendly inputs...

You would have to store the enums in a map type structure caching their int equivalents and preprocess the script files replacing these for ints, or handle unknown types by extending the parser.cpp IsRealType() and IsDataType().

The real work would be validating name collisions etc on addition of a new enum type.

Thinking about it, it is really worth it when constant ints either added as a script section or included in a script file would do just as well?

Sorry for the long post, but has anyone toyed with the thought of supporting script include directives for file based scripts?

If this was standardized, it would perhaps simplify the creation of large scripting implementations? Any thoughts?

nihlist

[edited by - nihlist on March 11, 2004 8:15:04 AM]

#10 Andreas Jonsson   Moderators   -  Reputation: 3416

Like
Likes
Like

Posted 11 March 2004 - 04:43 AM

I think that for now I will not add a method for registering enum types, the extra script section should be good enough.

To have an #include directive with AngelScript, a pre-processor can be run on the scripts before adding them to AngelScript. The preprocessor would then scan for #include directives with extra filenames to include. It would also substitute two first characters of the lines with "//" to form a comment so that the AngelScript compiler doesn''t complain. It should be rather easy to write a pre-processor for this case.

AngelScript will not have native support for any #include directives, because AngelScript doesn''t have any resources for reading from the disk (and will not).

www.AngelCode.com - game development and more...
AngelScript - free scripting library

#11 nihlist   Members   -  Reputation: 122

Like
Likes
Like

Posted 12 March 2004 - 10:47 AM

The included constants scripts is certainly workable.

As for the preprocess includes, I could just make this part of my base ScriptManager class implementation so that scripts loaded from disk always preprocess for includes.

Thats all the C++ compiler is doing anyway. Thanks for your feedback.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS