Sign in to follow this  
Trae

[.net] Need help on Events calling objects from scripts.

Recommended Posts

Need help on Events calling objects from scripts. Sorry, I’ve been trying to figure this out for a few days and could really use some help. Even if you can only answer this in C# I think I can puzzle it out from there. Events are not clicking for me. Most books and articles tend to deal with existing events or simply mention the D word and then add “beyond the scope of this…” I get basic events, what I don’t get where you put the parts of from scratch events and where to put the parts to raise them: Enter text on a form. Parse the entered text. From here the text calls a verb script which is an external script file. I can get this part to work. What I need next is to communicate with objects in the game which would have exception code. A more specific breakdown: Enter text. Parse text for command (In this case GET) Call GET(a class loaded at run time) So at this point I’m in the Sub run of the script. That section works fine for me. What I’d like help with is the following. I would like to have exception scripts on objects. These might be scripts the object references; they might be modification to the object’s class or both. Here’s some examples: Get fire: I would like to be able to stop this and perhaps have the fire deal out damage to the player. Water: Requires a proper container. So finally the questions. Do I need, or should I be using delegates? How exactly should I be raising events? For instance, what part goes into the base command, what part into the object. What type of interface should I be basing this off of (if any)?

Share this post


Link to post
Share on other sites
Hmm, could you try making it a little clearer what you want to do? I'm not quite sure what you are trying to accomplish, and even less clear on where your actual problem is. Do you need help making new events and throwing them? If that is the case, in VB.Net you would do so like this.

Share this post


Link to post
Share on other sites
Let me try that walkthough -- it looks rather complete.

I’m just surprised that there doesn’t seem to be a tutorial on what seems to me such a basic need for a certain type of game.

In RPGs it seems to me that you either have a menu type game, a parsed text entry, or hybrid game.

Now in the non-oop games I’ve worked on, MUDs, they weren’t fully OOP and used procedural scripting. In those you would pass control though various scripts with calls.

As I indicated in my OP, it seems like the .NET and OOP way would be using events. I am just surprised that there doesn’t seem to be a tutorial on setting up a basic parser, and scripting system which can talk to objects. I’d much rather be working on the creative part then the guts. ;-)

Share this post


Link to post
Share on other sites
The real .Net way would be to make your scripts with .Net, if that is an option. You have to choices when you do this, either make it so scripts have to be pre-compiled, which will increase performance and let and .Net language be used, or compile at run time with either VB.Net or C#. Then you use reflection to look at what is in the script and use it. For example, I usually have an interface for my scripts, and the look for any class inside the script that implements the interface.

Share this post


Link to post
Share on other sites
Thanks for the reply, Intrest86.

Yes, most of that is the route I am going. I called them scripts but they are simply classes (.vb files) which compile from a directory at run time.

Here’s a different example if this helps convey the problem.

The command PULL is usually handled completely within the base script, but I want to make a unique item – an invisibility cloak. When you PULL CLOAK the PULL script needs to check the cloak for any custom code. In this case both for custom messaging and a special effect of hiding the player from sight.

Now most things I’ve read seem to indicate that I need to use events to do this.

I suppose I could use Interfaces and functions calls (putting code in functions to keep from having multiple copies of the same code in multiple locations). I suspect the downside with Interfaces would be should I need to pass information back to the calling script, or am I mistaken?

Given what I’ve said, what do you believe my best option to be?

Thanks to your link, I’ve managed to get some very basic events to work (I can pass events around, I just haven’t gotten to the point where I have figured out how to pass any information... yet.).

Share this post


Link to post
Share on other sites
I'm still not completely clear on what you are going after. If what you need is access to the main code base from the script, then the best way of doing this would be to create a class or interface that has all of the functions that you want a script to be able to call. When you create an instance of the script, pass it this class and it can use it to tell the game to do things like an invisible cloak.

I'm not positivie, but to do this you may need to declare your interface in a class library and then expose it to both the scripts and the game at compile time.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this