Coder Social home page Coder Social logo

rena's Introduction

Rena

Rena is a scripting language for Godot Engine, designed with a goal of turning writing interactive dialogues for games a very enjoyable and intuitive process. Rena is heavily inspired by RenPy, an awesome engine for visual novels, although Rena tries to be more general purpose.

Its not a framework. It does not enforce certain project structure or anything like that. Its just a small virtual machine that interprets code, how you integrate it in your project is completely up to you.

Rena is still in active development, some features might buggy, Not recommended for production yet. If you are experiencing problems, report them in the issues tab, I'll try to fix everything as fast as I can. You can also request features, of course.

Features

  • say statements representing characters' speech

  • variables which can be defined and changed at runtime or from gdscript

  • if statements to control the flow with conditions

  • menus to get user input in the dialogue

  • gdscript functions of your choice can be called directly from Rena whenever you need it with arbitrary number of arguments

  • wide range of operators for all kinds of expressions you might need.

  • Arrays and Dictionaries fully supported

  • save/load system, to be able to save game during the dialogue and load it back

  • multiline strings

Planned features

  • ACTUAL DOCUMENTATION

Getting started

Installation

  1. Download repo as zip or clone it.
  2. Copy /addons/ directory into your project root directory(where your project.godot is)
  3. Activate plugin in your project settings -> plugins tab
  4. (Optionally) copy /examples/ folder to see how it all works
  5. You are ready to go.

Contributing

One can contribute by reporting bugs via issues. If your script is being interpreted incorrectly, please be sure to include that script or a minimal example that reproduces the problem, so I can debug it.

You can also propose features to the language or vm.

If you would like to code some feature, pull requests are also welcome.

rena's People

Contributors

cmd410 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

boyquotes

rena's Issues

Interpreter

Implement interpreter.

The goal would be to be able to interpret "The Question" script from RenPy examples, adapted for RenGo.

So, "The Question" has:

  • define/default statements
  • characters
  • labels
  • menus
  • if statements

Thats core features that need to be done for interpreter to be considered complete.

Create a demo minigame

This minigame should showcase various ways of interacting with the VM as well as basic scripting principles., such as:

  • labels
  • menus
  • conditions and variables
  • call statements

Convert AST to bytecode

Converting AST to bytecode can give several advantages:

  • More compact representation of script
  • Saving progress during script execution can be done easily

Make some script pre-pass to cleanup and validate indentation

So, state of problem is:

  • Lexer currently only support space as indentation
  • Current script editor is Godot's TextEdit node, which for some reason only uses tabs as indent.

This apparent mismatch of editor and underlying interpreter will most probaly make user suffer.

Proposed solution:

  • Create pre-pass for script which will
    • Cleanup script from comments
    • Determine indent character by the first indented line
    • Forbid to mixup indentation
  • Lexer then must use indent chracter from pre-pass to determine code block boundary and ignore others

Compile If statements

Compile if statements to bytecode:

Should look similar to python's:

5           0 LOAD_GLOBAL              0 (random)
              2 CALL_FUNCTION            0
              4 STORE_FAST               0 (chance)

  6           6 LOAD_FAST                0 (chance)
              8 LOAD_CONST               1 (0.5)
             10 COMPARE_OP               4 (>)
             12 POP_JUMP_IF_FALSE       18

  7          14 LOAD_CONST               2 (1)
             16 RETURN_VALUE

  8     >>   18 LOAD_FAST                0 (chance)
             20 LOAD_CONST               3 (0.3)
             22 COMPARE_OP               4 (>)
             24 POP_JUMP_IF_FALSE       30

  9          26 LOAD_CONST               4 (3)
             28 RETURN_VALUE

 11     >>   30 LOAD_CONST               5 (2)
             32 RETURN_VALUE
             34 LOAD_CONST               0 (None)
             36 RETURN_VALUE

for

chance = random()
if chance > 0.5:
    return 1
elif chance > 0.3:
    return 3
else:
    return 2

Create save/load system

This system should be able to save progress of rena script execution and load it. Such system exists in RenPy and specificaly useful for visual novels, which are basically one big script.

Menu

Parser must be able to parse menu entries like this:

menu:
    "What should i do?"

    "Go to the park.":
         ...
    "Stay home.":
        ...

Menu body is not exactrly a compound. It has more delibirate structure.

[MENU][COLON][EOL]
?[PROMPT]?
[OPTION][COLON][EOL]
    <compound>
[OPTION][COLON][EOL]
    <compound>
...

Come up with an idea to handle exceptions in RenGo script

So...

GDScript does not have any built-in excpetion system, you can use assert(false, ...) to crash game with some error message. Such assertions are used by interpreter currently.

Lexer and Parser on the other hand use custom type RenResult which has two subtypes RenOK and RenERR for success and failure respectively to provide comprehensible error message about user script, ie SyntaxErrors, Unexpected tokens and so on, without crashing the "IDE" and showing lexer/parser internal callstack which is generally not usefull for debugging user's script.

And this is kinda clumsy, it lead to cunstructions like:

var result = function()

if result is RenERR:
    return result

var value = result.value


result = function2(value)

if result is RenERR:
    return result

var value2 = result.value

This kind of manual error propagation is very unhandy and takes up a LOT of space, and unnecessarily confuses the code.

Multiline strings

Implement multiline strings parsing.

That would involve somehow changing cleanup function of Lexer to ignore # in triple-quoted strings so it does not cut off line after it, and, of course, string function to recognise triple quotes as multiline string.

Parse bitwise and comparison operators

  • Make token types for bitwise operatiors:

    • <<, >>, ^, |, &, ==, <, >, <=, >=
  • Parser must parse these operations with proper precedence

  1. unary operators (can be done in factor() function of Parser class)
  2. multiplicative [ DONE ]
  3. additive [ DONE ]
  4. shifts
  5. less, greater
  6. exact comparison
  7. bitwise and
  8. xor
  9. bitwise or

All these operations must use BinOp class as their AST node.

Flow control

Add support for conditional statements like this:

if a == b:
    ...
elif b < 0:
    ...
else:
    ...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.