• Advertisement

Archived

This topic is now archived and is closed to further replies.

Enums?

This topic is 5063 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

  • Advertisement