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 :)).
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);
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:
ifTrigger(NPC_thief)thenbeginRequest2charactersmainordie;//thiscut-scenerequires2alivecharactersRequestNPC_thiefordie;//requestanexternalgameworldobjectSelectChar1asStrongstrict;//strict"locks"Char1andmakeshim/herunabletobeselectedasChar2SelectChar2asBiologiststrict;SelectChar3asEngineermayduplicate(Char1);//canduplicatechar1SelectExt1asNPC_thief;Partyrelaxed;//non-selectedpartymembersplay"relaxed"animationLockControl;//disableplayercontrol;first-personcutscenescanhappenwithoutloosingcontrolTeleportChar1to(+1,0,0);//createscenerelativetocurrentpartylocationTeleportChar2to(-1,0,0);TeleportChar3to(0,1,0);TeleportExt1to(1,1,0);TeleportCamerato(0,-4,0);CameraLookatExt1;FlyCamera[#a..#b]to(0,-4,1)animate;//animatecameraslowlyraisingupPlayMusic'cutscene10music.ogg';//StopscurrentandplaysanewbackgroundmusicLabela://timesensorChar1lookatChar2animate;Char3lookatChar2animate;nextChar2speak'cutscene10-1';//sayaphraseandshifttimesensorbythetimespentnextChar1speak'cutscene10-2';interrupt[-300]Char3speak'cutscene10-3';//thiswill"steal"300msfromtimesensorandthenextsceneeventwillfirebeforethisonefinishedparallelPlaySound'splash.ogg';//thiswillplayasoundandwon't shift time sensorpause 100; //this will wait 100ms from current time sensornext Char2 speak 1057;label b: //another time sensorTeleport 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 randomlyV = PlayerChoice('Inquireabouttheaccident','Inquireaboutthemine','Goodbye');case V of1: ...goto c2: If Party.persuasion>10 then...else...goto c3: Char 1 speak 'cutscene10-goodbye';next ReleaseControl; //finally release control (actually it'llbeautomaticallyreleasedoncutsceneend)end;
It doesn't seem like CastleScript can handle so much calling to in-game functions/procedures, right?
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 :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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:
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...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
View and moderate all "General Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Old Forum"
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 :)).
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);
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:
It doesn't seem like CastleScript can handle so much calling to in-game functions/procedures, right?
Eugene Loza
P.S. Still having troubles logging-in :) SourceForge support didn't respond, I should try it again :)
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 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:
JavaScript . A very awful, and very widely known language:) It is also standard in the VRML / X3D community. This is on my https://castle-engine.sourceforge.io/planned_features.php .
Lua? Widely known in the game developers community.
Pascal Script? http://wiki.freepascal.org/Pascal_Script .
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...