Menu

Castle script

Anonymous
2017-03-07
2017-03-07
  • Anonymous

    Anonymous - 2017-03-07

    Hi, Michalis!

    Today I've had a go with CastleScript tutorial and in order to either go on with it or to do some script language of my own I'd like to ask you a few questions about it (no urgency at all, the question is mostly theoretical - I won't start any complex scripting soon, I'll be absolutely fine with pure tirggers for almost a year to come :)).

    1. I found no way of passing some in-game (pascal, not X3D) values to the CastleScript. E.g. I need the script to apply a some abstract status to player's character, can it do this? E.g. Party[randomCharacter].add(Poison_status);

    2. I found no way to control the game flow for some time. E.g. I need to launch a cut-scene at some certain point of the game:

    if Trigger(NPC_thief) then begin
    Request 2 characters main or die; //this cut-scene requires 2 alive characters
    Request NPC_thief or die; // request an external game world object
    Select Char1 as Strong strict; //strict "locks" Char1 and makes him/her unable to be selected as Char2
    Select Char2 as Biologist strict;
    Select Char3 as Engineer mayduplicate(Char1); //can duplicate char1
    Select Ext1 as NPC_thief;
    Party relaxed; //non-selected party members play "relaxed" animation
    LockControl; //disable player control; first-person cutscenes can happen without loosing control
    Teleport Char1 to (+1,0,0); //create scene relative to current party location
    Teleport Char2 to (-1,0,0);
    Teleport Char3 to (0,1,0);
    Teleport Ext1 to (1,1,0);
    Teleport Camera to (0,-4,0);
    Camera Lookat Ext1;
    Fly Camera [#a..#b] to (0,-4,1) animate; //animate camera slowly raising up
    PlayMusic 'cutscene10music.ogg'; //Stops current and plays a new background music
    Label a: //time sensor
    Char1 lookat Char2 animate;
    Char3 lookat Char2 animate;
    next Char2 speak 'cutscene10-1'; //say a phrase and shift time sensor by the time spent
    next Char1 speak 'cutscene10-2';
    interrupt[-300]  Char3 speak 'cutscene10-3'; //this will "steal" 300ms from time sensor and the next scene event will fire before this one finished
    parallel PlaySound 'splash.ogg'; //this will play a sound and won't shift time sensor
    pause 100; //this will wait 100ms from current time sensor
    next Char2 speak 1057;
    label b: //another time sensor
    Teleport Camera to (-1,0,0);
    next Camera lookat Char1;
    Pause 200;
    next Char1 speak  'cutscene10-4';
    next Char2 speak  'cutscene10-5';
    label c:
    FreeCamera; // camera will fly around randomly
    V = PlayerChoice('Inquire about the accident','Inquire about the mine','Goodbye');
    case V of
    1: ...
    goto c
    2: If Party.persuasion>10 then
    ...
    else
    ...
    goto c
    3: Char 1 speak 'cutscene10-goodbye';
    next ReleaseControl; //finally release control (actually it'll be automatically released on cutscene end)
    end;
    

    It doesn't seem like CastleScript can handle so much calling to in-game functions/procedures, right?

    1. Is it possible to "extend" CastleScript to handle such game-specific functions? Or would it be easier to "just write a parser and forget" :)

    Eugene Loza
    P.S. Still having troubles logging-in :) SourceForge support didn't respond, I should try it again :)

     
  • Michalis Kamburelis

    I found no way of passing some in-game (pascal, not X3D) values to the CastleScript.

    You can run the script in CastleScript from your own code. You can pass variables to it as TCasScriptValue descendants. See examples/castlescript/image_make_by_script.lpr for a demo of using CastleScript your own code.

    So, CastleScript is not tied to X3D.

    It doesn't seem like CastleScript can handle so much calling to in-game functions/procedures, right?

    It is possible to add new functions to the CastleScript, that are implemented in Pascal. That's how existing units CastleScriptImages, CastleScriptVectors add more functions on top of the CastleScript "core".

    That said, it looks like you will need do add a lot of functions... And it looks like you want to do something non-trivial in CastleScript. So: Possibly, CastleScript will be too limited for your needs. There are some major shortcomings of the current CastleScript language: it is not possible to define your own types, variables, constants in CastleScript code And you cannot define in CastleScript a function callable by CastleScript. You can define various things in Object Pascal to "enhance" what the CastleScript code can do. But the CastleScript usefullness is mostly for really simple scripts... Or for "enhancing" your syntax of float expressions, E.g. I can write in XML files stuff like player_life="difficulty_level * sin(10.0)", not only player_life="123.45" :) And the "difficulty_level * sin(10.0)" is a CastleScript expression.

    In the long term, I don't plan to extend CastleScript much more. It's not a familiar language, and it's not a full-featured language, and for this reason I would prefer to add other scripting languages to CGE:

     
  • EugeneLoza

    EugeneLoza - 2017-03-10

    Thanks a lot!
    (And finally I can login again :))
    Maybe, then I'll have a go with CastleScript + own SceneScripting (that'll be the most "complex" part, which would actually be relatively simple to parse and implement - it should just call hard-coded functions with some input parameters specificed by script). Or, maybe, making some own scripting at all... Because most of the stuff can be hard-coded then (and not result in a very complex script).
    Still have to think about it...

     

Anonymous
Anonymous

Add attachments
Cancel