pjohansson / inkling

Limited Rust implementation of the Ink markup/scripting language for game narratives
Other
42 stars 7 forks source link

Variables cannot be defined inbetween printable lines #9

Open kaisalmon opened 7 months ago

kaisalmon commented 7 months ago

Describe the issue The following unit test fails

#[test]
fn global_variables_can_be_defined_in_between_prints() {
    let content = "
    VAR x = 10
    {x} is ten
    VAR z = 12
    Now {x} and {z} are both set
";

    let mut story = read_story_from_string(content).unwrap();
    let mut line_buffer = Vec::new();

    story.resume(&mut line_buffer).unwrap();

    assert_eq!(
        &line_buffer[0].text,
        "10 is ten\n"
    );
    assert_eq!(
        &line_buffer[1].text,
        "Now 10 and 12 are both set\n"

    );
}

However, when running Inky, this code:

   VAR x = 10
    {x} is ten
    VAR z = 12
    Now {x} and {z} are both set

prints out

10 is ten

Now 10 and 12 are both set

without any issue.

To Reproduce Copy paste the unit test into tests\setting_variables.rs

Expected behavior The unit test above should pass

Screenshots image

System (please complete the following information):

Additional context The error returned is

thread 'global_variables_can_be_defined_in_between_prints' panicked at 'called `Result::unwrap()` on an `Err` value: ValidationError(ValidationError { invalid_address_errors: [InvalidAddressError { kind: UnknownAddress { name: "z" }, meta_data: MetaData { line_index: 4 } }], name_space_errors: [], variable_errors: [] })', tests\setting_variables.rs:141:53

I am to attempt and fix this I am aware this repo seem very very dead. I ran into this issue when experimenting with adding additional features into the repo

kaisalmon commented 7 months ago

I'm now realising that variables can only be set in prelude. I cannot find this concept of a prelude anywhere in the Inkle docs, and it seems to be an artificial limitation baked into this implementation

EDIT: Yeah, it looks like variables are only considered at the start of the whole story, and then are "baked" into the lines? It looks like a total refactor, with possibly a total removal of the prelude concept is required to allow the use of (dynamic) variables?