Jump to content
  • Advertisement
Sign in to follow this  
Hypnotron

[.net] c# scripting - user enums/constants shareable by all user scripts

This topic is 2640 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

I want the user to be able to create enums/constants that are accessible to all of their scripts without them having to just copy and paste them into every single script.


I don't want the host application to define these. I want these to be strictly user land constants that should only make sense to the users' scripts.



1) One way i know would work is to just read in some know file like UserConstants.cs and then insert that code into every user script prior to compiling them, but that seems kludgy.

2) Maybe search for and then compile a file named UserConstants.cs into an assembly and then modify each script prior to compiling it to reference that assembly so that their use of those constants will be recognized. (eg. insert a "using UserConstants;" at the top of their script)

3) some better way? anyone?



EDIT: Currently trying a variation on #2 but instead of modifying the script to including the using statement, setting the UserConstants assembly as a referenced assembly for the loaded script to use.. i think this should work...

Share this post


Link to post
Share on other sites
Advertisement
The best way in my mind is to simply compile all the user scripts into a single DLL. Then they can put an enum in any of the files and other scripts can use it exactly how you can in, for example, Visual Studio projects. Unity handles scripts in this way where you have a bunch of script files yet you can access any types from one script in another. Behind the curtains they're really compiling all your scripts into a single assembly.

Share this post


Link to post
Share on other sites
Interesting, thanks for the feedback. I'll look into this down the line. For now I do have it working by adding the compiled userconstants assembly as a referenced assembly to use during the user scripts compile.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!