Hello,


I'm creating a game editor and I'm at the current stage that I would like the ability to attach scripts to objects (by selecting the string of the method name to be called). That would be saved into the object's scripts to load / run array. That shouldn't be too difficult, the part I'm having trouble with is finding a method to dynamically call functions at runtime based on what script they need to run. Keep in mind this "script" is just C# code.

I need to run the scripts efficiently at game runtime and I can't have complicated lookups to the functions. Is there some way I can do this? I'm thinking delegates / reflection but I'm not sure how to implement any of it.

There's not really any code yet for this specifically but I'll provide whatever is deemed necessary for a reply.

Are the methods predefined or are they created at runtime?

Although it would be cool if they are generated at runtime, I'm not going to bother with that yet. The are going to be predefined in a scripts folder.

The easiest way is to create a delegate. Then use this delegate to create an array of your 'scripts' and use that to call the methods.

You can also use reflection to find the methods and call them, but that takes more work :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.