Author Topic: Feature think-tank: Timescript  (Read 1751 times)

0 Members and 1 Guest are viewing this topic.

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Feature think-tank: Timescript
Another unimaginatively named idea from the mind of WMCoolmon :D.

This is something I've had in the back of my mind for a few weeks...but only really fleshed it out while I was in the shower tonight (If you'll pardon the pun :p)

First the TBL (timescript.tbl?)
Code: [Select]
#Timescripts
$Name:     Example
;;Immediately show "Example script" for 10 seconds
0:   [
          --A lua script, note my double-dash comment.
          --We can do some stuff here with scripting. For example:
          grpc.text("Example script",0,0)
     ]
     +Duration: 15 ;;Show text for 15 seconds

;;After 10 seconds of script activation...
10:  [grpc.line(0,0,640,480)]
     +Duration: 4.5     ;;...draw a line for 4.5 seconds

;;After 20 seconds of script activation...
20:  [grpc.text("Goodbye!", 0, 0)]
     +Duration: 2 ;;Say goodbye for 2 seconds (Don't seem too desperate!)
$End ;;End this one, so we can begin another

Pretty self-explanatory. Would obviously require more scripting functions to be really useful, however, the fun thing is that you could call a Timescript from a SEXP or a script relatively easily.

+Duration makes it extremely useful, because you can actually do graduated movement, assuming I pass a "tse" variable for the current timescript entry progress. (And assuming a setshipposition thingamajigger gets implemented).
Code: [Select]
;;Moves a ship forward from starting position at 15 m/s, presumeably in global coords.
15:  [ShipHandle.setPosition(ShipHandle.getPosition("X"),ShipHandle.getPosition("Y"),ShipHandle.getPosition("Z")+15*fs2.getFrameTime()]

Even more fun...after thinking about this a bit, I've realized that the Lua VM probably does store global variable values between frames. So if, say, you made an animation script for a ship to do a jig...you could in theory make the TimeScript apply for multiple ships by setting a global ship handle variable used in the TimeScript before calling the TimeScript.

Now some data structs that could be improved on to allow multiple executions of the same timescript at once:
Code: [Select]
class TimescriptLib
{
private:
     std::vector<Timescript> scripts;

public:
     scriptid AddScript(script);
     void ActivateScript(scriptid);
     void DoFrame();
};
Code: [Select]
typdef struct Timescript
{
     float activation_time; //Mission time of activation
     int current_entry;

     //"Static"
     char name[NAME_LENGTH];
     std::vector<TimeEntry> entries;
};
Code: [Select]
typedef struct TimeEntry
{
     //Reusable variables
     float activation_time;  //This is relative to script activation time (ie 10 s past, rather than mission 2:10
     float remaining_time;

     //"Static" variables
     float duration;
     script_hook action;
};

Hopefully I'll think up a better name before I implement it. :p
-C

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: Feature think-tank: Timescript
essentially this is like the little timer control in vb that got me through oh so many programming assignments back in highschool:D
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline FireCrack

  • 210
  • meh...
Re: Feature think-tank: Timescript
Is there a good, comprehensive refrence for the LUA implementation in FS open?
actualy, mabye not.
"When ink and pen in hands of men Inscribe your form, bipedal P They draw an altar on which God has slaughtered all stability, no eyes could ever soak in all the places you anoint, and yet to see you all at once we only need the point. Flirting with infinity, your geometric progeny that fit inside you oh so tight with triangles that feel so right."
3.141592653589793238462643383279502884197169399375105820974944 59230781640628620899862803482534211706...
"Your ever-constant homily says flaw is discipline, the patron saint of imperfection frees us from our sin. And if our transcendental lift shall find a final floor, then Man will know the death of God where wonder was before."

 

Offline Taristin

  • Snipes
  • 213
  • BlueScalie
    • Skelkwank Shipyards
Re: Feature think-tank: Timescript
What purpose would this serve? I see what it oes, but I don't see the use...
Freelance Modeler | Amateur Artist

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Re: Feature think-tank: Timescript
I was mostly thinking for movies. It's omewhat cleaner to do gradual movement over a number of frames, since you don't have to have global variables to keep track of when the series of actions started. You could also use something like this to do a looping animation with a complex series of steps, assuming you had the functions.

Is there a good, comprehensive refrence for the LUA implementation in FS open?

The command-line "-output_scripting" will make an HTML file with all classes and functions. Right now there's only one scripting hook, in scripting.tbl, using the field $Global:, this will be executed every time the screen is drawn to.

scripting.tbl
Code: [Select]
$Global: [
     grpc.drawLine(0,0,639, 479)
]
This would draw a diagonal line across the whole screen in 640x480, or just the upper-left in 1024x768 or higher, coordinates are in pixels from the upper left.


Other than that, not rly, at least for modders.
-C

  

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: Feature think-tank: Timescript
you need to ba able to run timed functions to make hud gauges and complicated submoel animations i think.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN