Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Textual event script writing and compiling #140

Open
mateofio opened this issue Sep 21, 2020 · 2 comments
Open

Textual event script writing and compiling #140

mateofio opened this issue Sep 21, 2020 · 2 comments

Comments

@mateofio
Copy link
Contributor

mateofio commented Sep 21, 2020

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.

@Ghabry
Copy link
Member

Ghabry commented Sep 21, 2020

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
Copy link
Member

Ghabry commented Feb 2, 2021

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)

simplescreenrecorder-2021-02-02_21.29.58.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants