Editor icon indicating copy to clipboard operation
Editor copied to clipboard

Textual event script writing and compiling

Open mateofio opened this issue 5 years ago • 2 comments

Clicking around boxes for event code is nice for newbies, but it's horribly slow if you know what you're doing.

I would really want some kind of way to type event script on the keyboard.

This is a somewhat big project. We would need to define the text syntax for each command, and write a parser / compiler for it. It would also be nice if game projects could leave the event script files as text and compile them into lcf binary for shipping.

No other scripting language really fits, so this would likely end up being a custom scripting language of sorts. Essentially something declarative which just executes commands.

So all of this might end up being part of liblcf.

mateofio avatar Sep 21 '20 02:09 mateofio

I also had this in my mind.

My idea would be using a Javascript engine that is used as a macro-language to emit event code. The Editor executes it to generate the event commands.

Semantic (reserved variable prefixes):

  • $ Event code (Appears as event command)
  • _ constant stuff (evaluated during compile time)

Example:

for (let i = 0; i < 3; ++i) {
  $V(i, '=', i*2);
}
$C("---");
for (let i = 1; i < 3; ++i) {
  $V(i, '+', $V[i]);
$C("+++");
let val = 100;
$V(5, '=', 100 + _db.monsters[2].attack); // OK. DB is Constant expression
$V(5, '=', $game.party.actor[1].level); // OK. Fetches party actor 1 level at runtime

This is evaluated while typing. Functions prefixed with $ appear in event code. This would emit:

@CtrlVariable(V1 = 0)
@CtrlVariable(V1 = 2)
@CtrlVariable(V1 = 4)
@Comment(---)
@CtrlVariable(V1 + V1)
@CtrlVariable(V2 + V2)
@Comment(+++)
@CtrlVariable(V5 = 140) <- Evaluated at compile time, monster attack in DB was 40
@CtrlVariable(V1 = Actor 1 Level)

Errors:

$V(5, '=', 100 + $game.party.actor[1].level); // Error $game is not constant
let val = $V[3] // Error $V is not a constant

Ghabry avatar Sep 21 '20 08:09 Ghabry

I hacked now together some basic javascript for this and bound it to C++ via QuickJS. Highly experimental.

With the following "event code" which is valid Javascript

$msg("Javascript!!1");

$showpic("Punkt").id(1).x(0).y(180);

for (let i = 0; i <= 360; ++i) {
	$movepic().id(1).x(i / 360 * 320).y(Math.sin(to_rad(i)) * 120 + 120);
	$wait(0);
}

Generated event code:

Screenshot_20210202_214525-fs8

I generate the following event which shows a Sinus curve: (sorry for the flicker)

https://user-images.githubusercontent.com/1331889/106658723-ec14f780-659d-11eb-8aba-7cc5d290a8e4.mp4

Ghabry avatar Feb 02 '21 20:02 Ghabry