Add SimpleScript option #505

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants
@lealeelu
Contributor

lealeelu commented Jun 26, 2016

This is just a start to an idea that I think other people might find useful. It definitely needs some work.

In simplescript, most lines will look like this:

r: Hi there!
r/sad/right: I'm feeling sad today.
r/happy: but I have something that always cheers me up!
The destruction of my enemies!

You can add lines of lua code by escaping using ``` like you would in markdown.

I took a look at mustache but I couldn't get what I wanted from it. I didn't want to involve my writers in using json.

@chrisgregan

This comment has been minimized.

Show comment
Hide comment
@chrisgregan

chrisgregan Jun 27, 2016

Contributor

I think this would be a great addition, would really speed up the writing process!

From an architecture perspective, I'd like to make this more of a core feature of FungusLua rather than a separate command. If you want to run your script in a LuaScript component you would expect to be able to use the simplescript syntax there too.

Regarding the syntax itself, we should aim to keep the style consistent with Lua, e.g.:

s = sherlock
w = watson

-- comments!

s,angry,right: What are we doing here again?
w,annoyed,left: I don't know.
You're the one who called me out here.
s,bored: I can't be bothered to remember every appointment I arrange.
s,angry: That's why I have you.
w: ...

stage.hide(sherlock)
stage.hide(watson)
wait(1)

It should be possible to mix simplescript in with Lua freely without special code blocks, the lines with special markup on them just expand into more Lua.

To get this to work generically, I'll add an IPreprocessor interface to LuaEnvironment, and have LuaUtils implement it. LuaEnvironment will run all scripts through the preprocessor before passing them to MoonSharp for execution. That way every script that goes through FungusLua can use this syntax, and we can extend it in the future.

Sorry for all the proposed changes, but I think this could be a really powerful feature so let's nail it!

What do you think?

Contributor

chrisgregan commented Jun 27, 2016

I think this would be a great addition, would really speed up the writing process!

From an architecture perspective, I'd like to make this more of a core feature of FungusLua rather than a separate command. If you want to run your script in a LuaScript component you would expect to be able to use the simplescript syntax there too.

Regarding the syntax itself, we should aim to keep the style consistent with Lua, e.g.:

s = sherlock
w = watson

-- comments!

s,angry,right: What are we doing here again?
w,annoyed,left: I don't know.
You're the one who called me out here.
s,bored: I can't be bothered to remember every appointment I arrange.
s,angry: That's why I have you.
w: ...

stage.hide(sherlock)
stage.hide(watson)
wait(1)

It should be possible to mix simplescript in with Lua freely without special code blocks, the lines with special markup on them just expand into more Lua.

To get this to work generically, I'll add an IPreprocessor interface to LuaEnvironment, and have LuaUtils implement it. LuaEnvironment will run all scripts through the preprocessor before passing them to MoonSharp for execution. That way every script that goes through FungusLua can use this syntax, and we can extend it in the future.

Sorry for all the proposed changes, but I think this could be a really powerful feature so let's nail it!

What do you think?

@chrisgregan

This comment has been minimized.

Show comment
Hide comment
@chrisgregan

chrisgregan Jun 27, 2016

Contributor

Just added the preprocessor support for LuaEnvironment / LuaUtils if you want to hook into that.

Contributor

chrisgregan commented Jun 27, 2016

Just added the preprocessor support for LuaEnvironment / LuaUtils if you want to hook into that.

@lealeelu

This comment has been minimized.

Show comment
Hide comment
@lealeelu

lealeelu Jun 27, 2016

Contributor

Ya! Nail it!

I think I see what I should do with the Preprocessor. I'll have to tinker around with it when I get home.
Another thing that I was wanting to add in later, but we can wait on it was a scene change. Basically, if I had a line like...

SCENE: train_station

it would turn into...

camera.changeToView(train_station)

Would that be possible?

Contributor

lealeelu commented Jun 27, 2016

Ya! Nail it!

I think I see what I should do with the Preprocessor. I'll have to tinker around with it when I get home.
Another thing that I was wanting to add in later, but we can wait on it was a scene change. Basically, if I had a line like...

SCENE: train_station

it would turn into...

camera.changeToView(train_station)

Would that be possible?

@chrisgregan

This comment has been minimized.

Show comment
Hide comment
@chrisgregan

chrisgregan Jun 28, 2016

Contributor

Good stuff. For the scene change thing, you could just make a Lua utility function, e.g.

scene(train_station)

Same amount of typing, no code changes needed to support it.

Although that said, this gives me an idea. What if the preprocessor always did this:
SAY a,b,c: => say(a, b, c)
SCENE y: => scene(y)

Where SAY and SCENE can be any string and c includes everything up to the next blank line. It'd basically be a generic way to write dialog & other commands without using brackets all the time.

Contributor

chrisgregan commented Jun 28, 2016

Good stuff. For the scene change thing, you could just make a Lua utility function, e.g.

scene(train_station)

Same amount of typing, no code changes needed to support it.

Although that said, this gives me an idea. What if the preprocessor always did this:
SAY a,b,c: => say(a, b, c)
SCENE y: => scene(y)

Where SAY and SCENE can be any string and c includes everything up to the next blank line. It'd basically be a generic way to write dialog & other commands without using brackets all the time.

@chrisgregan

This comment has been minimized.

Show comment
Hide comment
@chrisgregan

chrisgregan Jun 28, 2016

Contributor

Btw I can help with the regex if you like

Contributor

chrisgregan commented Jun 28, 2016

Btw I can help with the regex if you like

@lealeelu

This comment has been minimized.

Show comment
Hide comment
@lealeelu

lealeelu Jun 28, 2016

Contributor

Ohhhhh! yeah that would be pretty good having the processing be more generic like that. I'll think about it.

I figured the regex stuff out, just took me a little time to relearn the syntax. The match group stuff is super handy. I used it in the latest commit.

Contributor

lealeelu commented Jun 28, 2016

Ohhhhh! yeah that would be pretty good having the processing be more generic like that. I'll think about it.

I figured the regex stuff out, just took me a little time to relearn the syntax. The match group stuff is super handy. I used it in the latest commit.

@lealeelu

This comment has been minimized.

Show comment
Hide comment
@lealeelu

lealeelu Jun 28, 2016

Contributor

can I be picky and have it be that if the first \w matches an existing character key in luabindings, it is automatically a say function?

in luabindings:
[ character_watson ] [ w ] [ Fungus.Character ]

in the script:

w,happy,left: la la la la la la la la la 

converts to:

say(w, "happy", "left", "la la la la la la la la la")

and have a lua function...

function say(character, mood, location, text) {
  --set character, stage function, and say function
}
Contributor

lealeelu commented Jun 28, 2016

can I be picky and have it be that if the first \w matches an existing character key in luabindings, it is automatically a say function?

in luabindings:
[ character_watson ] [ w ] [ Fungus.Character ]

in the script:

w,happy,left: la la la la la la la la la 

converts to:

say(w, "happy", "left", "la la la la la la la la la")

and have a lua function...

function say(character, mood, location, text) {
  --set character, stage function, and say function
}
@lealeelu

This comment has been minimized.

Show comment
Hide comment
@lealeelu

lealeelu Jun 28, 2016

Contributor

And the second+ arguments would be assumed to be strings.

Contributor

lealeelu commented Jun 28, 2016

And the second+ arguments would be assumed to be strings.

@chrisgregan

This comment has been minimized.

Show comment
Hide comment
@chrisgregan

chrisgregan Jun 28, 2016

Contributor

Hmmm... not sure about checking the LuaBindings to infer the meaning of a line of script. Feels like it could be brittle and maybe give confusing error messages when things aren't set up correctly? I'd prefer a simple, clear transformation that only depends on the text in the script, even if it needs a bit more markup. That way it could work for any Lua function call which would be super powerful.

Ok, here's another idea for a format using a special leading # character to indicate a line that should be transformed. For this to work we'd need to put string parameters in quotes, though I really like the idea of assuming that the last parameter after a colon is a long string (and no quotes needed).

-- This transformation would work for any Lua function call
#wait 1
wait(1)

-- You can use a colon before the last parameter to indicate a long string
#say w, "happy", "left": La la la
say(w, "happy", "left", "La la la")

-- Leaving out the #say at the start is interpreted as a say command (special case)
w, "happy", "left": La la la
say(w, "happy", "left", "La la la")

Hope you don't mind bouncing ideas for this format around a bit more. Once we implement the format it'll be hard to change so worth getting it right I think!

Contributor

chrisgregan commented Jun 28, 2016

Hmmm... not sure about checking the LuaBindings to infer the meaning of a line of script. Feels like it could be brittle and maybe give confusing error messages when things aren't set up correctly? I'd prefer a simple, clear transformation that only depends on the text in the script, even if it needs a bit more markup. That way it could work for any Lua function call which would be super powerful.

Ok, here's another idea for a format using a special leading # character to indicate a line that should be transformed. For this to work we'd need to put string parameters in quotes, though I really like the idea of assuming that the last parameter after a colon is a long string (and no quotes needed).

-- This transformation would work for any Lua function call
#wait 1
wait(1)

-- You can use a colon before the last parameter to indicate a long string
#say w, "happy", "left": La la la
say(w, "happy", "left", "La la la")

-- Leaving out the #say at the start is interpreted as a say command (special case)
w, "happy", "left": La la la
say(w, "happy", "left", "La la la")

Hope you don't mind bouncing ideas for this format around a bit more. Once we implement the format it'll be hard to change so worth getting it right I think!

@lealeelu

This comment has been minimized.

Show comment
Hide comment
@lealeelu

lealeelu Jun 29, 2016

Contributor

I like where this is headed. I don't mind bouncing ideas back and forth. Maybe we should mention this convo on the forums and get other opinions too?

Contributor

lealeelu commented Jun 29, 2016

I like where this is headed. I don't mind bouncing ideas back and forth. Maybe we should mention this convo on the forums and get other opinions too?

@chrisgregan

This comment has been minimized.

Show comment
Hide comment
@chrisgregan

chrisgregan Jun 29, 2016

Contributor

Yup, good idea!

Contributor

chrisgregan commented Jun 29, 2016

Yup, good idea!

@lealeelu

This comment has been minimized.

Show comment
Hide comment
@lealeelu

lealeelu Jun 29, 2016

Contributor

Now I'm kind of back tracking. I don't want to confuse new users to Lua by conflicting syntax. My original intention was to have this be a logic-less language for pure dialog previews. I threw in the extra lua code blocks to be convenient.

Contributor

lealeelu commented Jun 29, 2016

Now I'm kind of back tracking. I don't want to confuse new users to Lua by conflicting syntax. My original intention was to have this be a logic-less language for pure dialog previews. I threw in the extra lua code blocks to be convenient.

@lealeelu

This comment has been minimized.

Show comment
Hide comment
@lealeelu

lealeelu Jun 29, 2016

Contributor

Ok! here's another iteration!

SimpleScript blocks+keep strings (or single quotes?? Does lua do that?)
edit: it does http://stackoverflow.com/questions/17202195/difference-between-and-within-lua

--some standard lua
wait(1)

#say
  w: Hi!
  s,'angry','right': Don't "Hi!" me!
#end

#wait 2
stage.hide(s)
#say w: What was that for??

Everything in the script blocks are assumed to be scripted says

Contributor

lealeelu commented Jun 29, 2016

Ok! here's another iteration!

SimpleScript blocks+keep strings (or single quotes?? Does lua do that?)
edit: it does http://stackoverflow.com/questions/17202195/difference-between-and-within-lua

--some standard lua
wait(1)

#say
  w: Hi!
  s,'angry','right': Don't "Hi!" me!
#end

#wait 2
stage.hide(s)
#say w: What was that for??

Everything in the script blocks are assumed to be scripted says

@chrisgregan

This comment has been minimized.

Show comment
Hide comment
@chrisgregan

chrisgregan Jun 29, 2016

Contributor

Interesting! Gives me another idea, but let's continue on the forum thread and see what others think.

Contributor

chrisgregan commented Jun 29, 2016

Interesting! Gives me another idea, but let's continue on the forum thread and see what others think.

@lealeelu

This comment has been minimized.

Show comment
Hide comment

@lealeelu lealeelu closed this Jul 3, 2016

@lealeelu

This comment has been minimized.

Show comment
Hide comment
@lealeelu

lealeelu Jul 3, 2016

Contributor

Moved to #510

Contributor

lealeelu commented Jul 3, 2016

Moved to #510

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