Results 1 to 10 of 16

Thread: What's the name of the concept of scripting in a Sim/RTS type of game?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Use an scripting language is a good choice. There are several ones that works on Free Pascal and Delphi as Pascal Script and Lua.

    Create your own simple scripting language isn't as hard as most people think. I'm working in my very own one right now (documented in Spanish only, at the moment). Anyway, here you have a simple (incomplete and untested) interpretor:
    Code:
      TYPE
      (* A helper type. *)
        TWordList = ARRAY OF STRING;
    
    
    
    (* This splits a string in to words separated by spaces. *)
      FUNCTION SplitWords (aText: STRING): TWordList;
      VAR
        CharNdx, WordNdx: INTEGER;
        ResultList: TWordList;
      BEGIN
      { First word. }
        SetLength (Resultlist, 1);  WordNdx := 0;
      { Extract... }
        FOR CharNdx := 1 TO Length (aText) DO
        BEGIN
        { If found space or comma (,), then another word starts. }
          IF aText[CharNdx] IN [' ', ','] THEN
          BEGIN
          { This is to avoid multiple spaces. }
            IF ResultList[WordNdx] <> '' THEN
            BEGIN
              INC (WordNdx);
              SetLength (ResultList, WordNdx + 1)
            END
          END
          ELSE
          { Adds character to word.  Does it uppercase. }
            ResultList[WordNdx] := ResultList[WordNdx] + UpCase (aText[CharNdx])
        END;
        EXIT (ResultList)
      END;
    
    
    
      PROCEDURE MyScriptInterpretor (aScript: TStrings);
      VAR
        CurrentLine, Ndx: INTEGER;
        LineWords: TWordList;
        FullLine: STRING;
      BEGIN
        IF aScript.Count > 0 THEN
          FOR CurrentLine := 0 TO aScript.Count - 1 DO
          BEGIN
          { Extract words. }
            LineWords := SplitWords (aScript.Lines[CurrentLine]);
          { Checks "commands" }
            IF LineWords[0] = 'SAY' THEN
            BEGIN
              IF Length (LineWords) < 3 THEN
                RAISE Exception.CreateFmt ('Not enough parameters on line %d.', [CurrentLine + 1]);
              FullLine := '';
              FOR Ndx := 2 TO HIGH (LineWords) DO
                FullLine := FullLine + ' ' + LineWords[Ndx];
              SomebodySays (LineWords[1], FullLine)
            END
            ELSE IF LineWords[0] = 'WARP' THEN
            BEGIN
              IF Length (LineWords) <> 3 THEN
                RAISE Exception.CreateFmt ('Wrong parameters for WARP on line line %d.', [CurrentLine + 1]);
              Player.SetPosition (StrToInt (LineWords[1]), StrToInt (LineWords[2]))
            END
          END
      END;
    Free Pascal's FCL includes an expression evaluator you can use to add maths to your interpretor too. See this link.

    [edit]
    I've just remembered that my PGD Challenge entry Momen3D includes it's own mission script system, much like the one you're asking for. Download it from here and look at file src/mission.pas, function ParseFile, lines 191...650. It looks big and complex but it is actually quite simple, as it is divided in sub-routines for each task.

    To see how the mission script files looks like, just see file bin/data/missions/default/tuto.md
    Last edited by Ñuño Martínez; 05-02-2017 at 02:22 PM.
    No signature provided yet.

  2. #2

    Red face

    Quote Originally Posted by Ñuño Martínez View Post
    Use an scripting language is a good choice. There are several ones that works on Free Pascal and Delphi as Pascal Script and Lua.
    Thanks Ñuño, anyway.

    Well, I was afraid someone would answer something like this when I used the word script .

    What I meant was a way to put this:
    1. Once x time as passed, archaeologist finds, in some ruins, mention to advance space drive
    2. Once you scanned planet Y and Z time passes, you find old space ship and can improve some other aspect
    3. Once you have plan A and plan B on some research, you can discover FTL travel
    4. etc...


    into a data structure.

    So more like a story kind of script, not a scripting language.

    Is there a pattern or a type of data concept, like linked lists or AVL trees that game programmers regularly use to support this?

    Cheers,
    Gus

  3. #3
    Quote Originally Posted by Ñuño Martínez View Post
    [edit]
    I've just remembered that my PGD Challenge entry Momen3D includes it's own mission script system, much like the one you're asking for. Download it from here and look at file src/mission.pas, function ParseFile, lines 191...650. It looks big and complex but it is actually quite simple, as it is divided in sub-routines for each task.

    To see how the mission script files looks like, just see file bin/data/missions/default/tuto.md
    I've downloaded your code and
    Code:
    sudo apt install liballegro5
    but for some reason it's not able to initialise the allegro stuff.

    Any hints on how to debug it?

    Cheers,
    Gus

  4. #4
    Quote Originally Posted by gcarreno View Post
    but for some reason it's not able to initialise the allegro stuff.

    Any hints on how to debug it?
    Check the latest post in http://www.pascalgamedevelopment.com...Momen-3d/page5 for possible solution.

  5. #5
    Quote Originally Posted by SilverWarior View Post
    Check the latest post in http://www.pascalgamedevelopment.com...Momen-3d/page5 for possible solution.

    That page of the thread talks about new installs of XUbuntu and debug flag on the compile.

    I'm on an Ubuntu 16.10, up to date and with open source video drivers. Hopefully it's not that.

    Tried the debug -dDEBUGMODE but I still have a very non explanatory: Error initializing Allegro.

    So I can't even tell you what specifically went wrong on the al_init call.

    If I have time and patience, I'll probably fire up Lazarus to debug the thing.

    Cheers,
    Gus

  6. #6
    Quote Originally Posted by gcarreno View Post
    I've downloaded your code and
    Code:
    sudo apt install liballegro5
    but for some reason it's not able to initialise the allegro stuff.

    Any hints on how to debug it?

    Cheers,
    Gus
    You need to install the dev versions too (liballegro5-dev) as well as the addons. Also see what SilverWarrior said.

    Note that Momen3D use an old Allegro version (5.0, not 5.2).
    No signature provided yet.

  7. #7
    Quote Originally Posted by Ñuño Martínez View Post
    You need to install the dev versions too (liballegro5-dev) as well as the addons. Also see what SilverWarrior said.
    Well, I thought as much and did install liballegro5-dev, dunno why I didn't use that in the prior post.
    Ok, now about the addons? You thrown me on this since I've never used allegro for anything.

    Quote Originally Posted by Ñuño Martínez View Post
    Note that Momen3D use an old Allegro version (5.0, not 5.2).
    Ok, if the addons is not the thing, then the version might be an issue. Ubuntu 16.10 is installing 5.2

    Cheers,
    Gus

Tags for this Thread

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
  •