CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Jun 2001
    Location
    Sweden
    Posts
    11

    Question Script to manage code objects?

    I want to let a script call functions and manage properties in my program. As i understand this is inpossible if i not create my own script engine. Any ideas?

    //B4N WarWolf

  2. #2
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    are you talking about this script at runtime or design time.
    if its a design time issue then you need to work on PropertyManager. which manages the property etc. you can save it also on I/O file as XML or so and later you can retrive it...


    thanx
    Paresh

  3. #3
    Join Date
    Feb 2003
    Location
    North Carolina
    Posts
    57

    Re: Script to manage code objects?

    Originally posted by WarWolf
    I want to let a script call functions and manage properties in my program. As i understand this is inpossible if i not create my own script engine. Any ideas?

    //B4N WarWolf
    WarWolf,
    Do you mean scripting languages like Javascript and VBScript?

  4. #4
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890

    Lightbulb

    well we should wait for his answer and guess thinking

  5. #5
    Join Date
    Jun 2001
    Location
    Sweden
    Posts
    11

    Sorry has been away for couple of days :-(

    Well i want to expose methods and propeties in runtime ex i can pass parameters to a script function at certin events or something like that. Kind of triggers on certin events.

  6. #6
    Join Date
    Feb 2003
    Location
    North Carolina
    Posts
    57
    I still don't understand what you're asking. Are you trying to execute methods in a dll or exe from within a scripting language like Javascript or VBScript?

  7. #7
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    warwolf, you would be better-off looking in dynamic loading of assembley. u will need to search MSDN on that. its a big topic though !

  8. #8
    Join Date
    Jun 2001
    Location
    Sweden
    Posts
    11

    Ok ill give a small example

    Let's say i got this game, an RPG the game data is stored in a database that contains items such as characters weapons and the world. Say some user want to implemet a sword that steal life whithout to recompile the whole game. Ex this script function that runs for all events.

    void ScriptEventHandler (int nEvent,CChar sender,CChar target,CObject object)
    {
    if(nEvent=WEAPON_HIT)
    {
    target.hp -=10;
    sender.hp +=10;
    }
    }

    so this functions is in some kind of script that i can call from my game. Functions checks what kind of event is rised, and if you hit someone it takes 10 life from victim and adds to your health.

    P.S. Im open for more suggestions how to make the game more dynamical. I want to be able to implement some special functions for weapons and NPC's without recompile every time i got a new idea.

    "When was the last time you did something for the first time"

    //B4N WarWolf

  9. #9
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    you simply need to design your Objects and give them a suitable method.
    for example if Object is Person then you can have property which says HasSword()
    which returns true if that character has sword. this is known as method invocation.

    your object desing, polymorphism etc will help you do this.

    when you make a method move sword then you will have sword object a member of person and it will be initialized only if person has a sword and will have methods that describes your script. actually the word script was mistaken.

    Paresh

  10. #10
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    also forgot to mention that,
    raising events can be done by using delegates and event calling, from mouse movements or some thing else.

    Paresh

  11. #11
    Join Date
    Jun 2001
    Location
    Sweden
    Posts
    11

    Allready know this ...

    Allredy know about this, the problem is that the objects such as characters and weapons data are in a database and i wan't to be able to add new "effects" to weapons and npc's that you can talk to without the need to compile the object.
    Is't the script idea possible i gonna fall back to make it thru interfaces and polymorthism. And make a compile for special objects and just add the libary path in database for dynamical linking.

    /Thanks alot for your answer anyhows :P

    //WarWolf

  12. #12
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    Ah ! I got your point,
    what you will need to do is,
    Make a general Interface and make a dll of it, the Class who ever implements that will be candidate to paint or render the character,

    Now what you do is when you load the game or your program you fetch for dlls
    in particular folder who is implementing the interface,
    (in this way you can create new dlls on the fly and still you don't need to modify the original exe)
    you can use Assembley members and check out reflection for more information.
    collecting the dlls at runtime gives you the ability to do dynamic stuffs like scripting etc. for example,

    consider a senario where you have a image and you need to provide various drawing methods at runtime,
    now the fact that you can't hardcode the Paint method and render image,
    what you will eventually do is

    1) make interfaces
    2) make classes which will implement this
    3) load all the dlls with dynamic load
    4) create a list of objects and have the user call any paint from the list

    now in this way if client requests the new paint method you just provide the new class and dll for that suitable Paint method which will render the Image differently,

    so you provide the dlls to clients at runtime and still your main exe application stays intact.

    hope this helps a bit
    Paresh

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured