Results 1 to 7 of 7

Thread: Scripting question...kinda

  1. #1

    Scripting question...kinda

    I've recently endeavored to learn how scripting systems work so I can eventually implement them in my games. I currently have a simple system working in a test project (Spacee Shooter) I made. It basically works using opcodes. A number assigned to each possible command and a place to add simple parameters, for example instruction #1 sets the ships X coordinate and uses parameter #1 (There are 2 parameter fields) as the coordinate. For the more complex system I had in mind I would like to be able to index the variables from a record and be able to make changes to this from the script. See below

    TShip = Record
    X: Integer;
    Y: Integer;
    VelX: Integer;
    VelY: Integer;
    Health: Integer;
    end;

    and then by using the command:
    ChangeShipVar( 3 , 10 );
    I could change the VelY value of a TShip record. I would of course have to specify which TShip but it would cut down a lot of work. I don't want to have to specify that X is index 0 and Y is index 1 and so on. I want it to know this and I'm sure there is a way of getting the index of a variable from within a record but I don't know how.

    God damn, why do I always give the long drawn out explanation when a simple one would have done.
    Isometric game development blog http://isoenginedev.blogspot.com/

  2. #2
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    Scripting question...kinda

    I'm just wondering how you are going to write the scripts? If you are going to have some sort of opcode comiler then it doesn't matter what the index is because your compiler can read the original text and work it out.

    I use DWS for my scripting. Its nice Delphi compatible code, and I've worked out some nice methods for integrating it into my games with a minimum of hassle. If you like I'll pass it on.
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

  3. #3

    Scripting question...kinda

    i use a bytecode script language a little like the one you descripe. it's based upon a VERY few assemblylike instructions like MOVe, ADD, SUBstract, DiSTance, MOVLiteral accepting up to 4 arguments a function.

    i'm solving it by giving a scripttoken to each of the objects i want to be scripted. then in the scriptmanager i run the script that the scripttoken descripes for each object scripted. the script will ask for registered variables which are stored by name,(pointer) and index in an array by the scriptmanager. the script (which is composed of numbers only refering to vars by index) is just run through a parser which parses:

    IFNZ character.CanSeeEnemy
    MOV character.HeadTo, character.CanSeeEnemy
    END

    to

    5,3
    1,2,3
    0

    that's how i solve it.. how userfriendly it s i don't know but it's lightning fast and i can handle it just fine
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  4. #4

    Scripting question...kinda

    have you seen dw script? http://www.dwscript.com/ were using that in our game

  5. #5

    Scripting question...kinda

    Well the reason I wanted to retrieve the index for a given variable is so that I can expand my Record without having to describe the extra parts I've had to the script editor. Currently if I was to add a bullet count to my record I would have to write code that tells the script manager to convert the index 5 into the variable "bulletcount".

    TShip = Record
    X: Integer; //Variable Index : 0
    Y: Integer; //1
    VelX: Integer; //2
    VelY: Integer; //3
    Health: Integer; //4
    Bullets: Integer; //5
    end;

    With the method I wish to implement the script manager wouldn't care it would just find the variable index 5 and adjust the values accordingly. Saving me a lot of messing about with case statements. I'm not saying the other way wouldn't work I'm just saying it seems a little inelegant and if I was frequently changing my code the other method would save a lot of time. Does anyone know if it's possible.
    Isometric game development blog http://isoenginedev.blogspot.com/

  6. #6

    Scripting question...kinda

    you could hack it by typecasting the record into an array type:

    [pascal]
    type tship = record
    x,y,bullets: integer;
    end;

    type tvars = array[0..2] of integer;

    function getvar(tmp: tship; index: integer): integer;
    begin
    result := tvars(tmp)[index];
    end;
    [/pascal]

    this would however only work if you know how big the record is and what fields are in it.

    you could look into how variants could be useful?
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  7. #7

    Scripting question...kinda

    You could also do something like this:
    [pascal]
    TShip = record
    case Boolean of
    True: (x, y, bullets: Integer);
    False: (arr[0..2] of Integer);
    end;
    [/pascal]
    It's a bit more to write to each record but no typecasting hack.
    Signature:
    <br />This is a block of text that can be added to posts you make. There is a 255 character limit

Bookmarks

Posting Permissions

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