Logo
v0.11.0

Quickstart

  • Introduction
  • Build
  • Examples
  • Version matrix
  • License

Building

  • Cloning
  • Build requirements
  • Build options
  • Project version
  • Building on Windows
  • Building in Docker (Windows or Linux)
  • Building on Linux natively

Lua Syntax

  • Quick start
  • Basics of Lua
  • Declaring an interface() and a run() function
  • Global variables and the init() function
  • Indexing inside Lua
  • Errors in scripts
  • Using Lua modules
  • Additional Lua syntax specifics

API

  • Overview
  • Script creation
  • Object lifecycle
  • Creating links between scripts
  • Linking scripts to Ramses scenes
  • Animations
  • Error handling
  • Print messages from within Lua
  • Iterating over object collections
  • Saving/Loading from file
  • Logging
  • Security and memory safety
  • Performance
  • List of all examples
    • Minimal example
    • Example with primitive properties
    • Example with structured properties
    • Example with indexed (vector, array) properties
    • Handling compilation errors
    • Handling runtime errors
    • Example with Ramses
    • Save/load from file example
    • Override print function example
    • Links example
    • Animation example
    • Modules example

Class Index

  • Class Index

ChangeLog

  • master
  • v0.11.0
  • v0.10.2
  • v0.10.1
  • v0.10.0
  • v0.9.1
  • v0.9.0
  • v0.8.1
  • v0.8.0
  • v0.7.0
  • v0.6.2
  • v0.6.1
  • v0.6.0
  • v0.5.3
  • v0.5.2
  • v0.5.0
  • v0.4.2
  • v0.4.1
  • v0.4.0
  • v0.3.1
  • v0.3.0
  • v0.2.0
  • v0.1.0

Developers

  • Understand RAMSES Logic architecture and design
  • Developer guidelines
  • Contributing
  • Pull requests
  • Commit guidelines
  • Review
  • Code style
  • Continuous integration
  • Branching
ramses_logic
  • Docs »
  • Overview »
  • Links example
  • Edit on GitHub

Links exampleΒΆ

/**
 * This example demonstrates how to link properties of different scripts to
 * create a network of logic nodes executed in a specific order
 */

int main()
{
    rlogic::LogicEngine logicEngine;

    // Create a simple script which increments an integer and prints the result
    const std::string_view scriptSrc = R"(
        function interface()
            IN.script_name = STRING

            IN.number = INT
            OUT.incremented_number = INT
        end

        function run()
            -- add 1 to the input and assign to the output
            OUT.incremented_number = IN.number + 1

            -- Print the name of the script currently being executed and the result
            print("Executing: " .. IN.script_name .. ". Result is: " .. OUT.incremented_number)
        end
    )";

    // Create two scripts using the Lua source code from above
    rlogic::LuaScript* script1 = logicEngine.createLuaScript(scriptSrc);
    rlogic::LuaScript* script2 = logicEngine.createLuaScript(scriptSrc);

    // Assign the scripts their names so that we can see their execution order
    script1->getInputs()->getChild("script_name")->set<std::string>("script 1");
    script2->getInputs()->getChild("script_name")->set<std::string>("script 2");

    // Scripts will be executed at arbitrary order (they are not linked yet!)
    logicEngine.update();

    // Both scripts will produce 1 as a result (add 1 to 0 -> results to 1)
    assert(1 == *script1->getOutputs()->getChild("incremented_number")->get<int32_t>());
    assert(1 == *script2->getOutputs()->getChild("incremented_number")->get<int32_t>());

    // Create a link between the output property (of script1) and the input property (of script2)
    logicEngine.link(
        *script1->getOutputs()->getChild("incremented_number"),     // Get data from this property...
        *script2->getInputs()->getChild("number"));                 // ... and provide it to this property

    // Let's initialize script1's input with a new number
    script1->getInputs()->getChild("number")->set<int32_t>(42);

    // Above link will cause script1 to be executed first now, its output's data
    // provided to the input of script2, then script2 will be executed
    logicEngine.update();

    // New results are different, based on the new input value of script1 and the link between the scripts
    assert(43 == *script1->getOutputs()->getChild("incremented_number")->get<int32_t>());
    assert(44 == *script2->getOutputs()->getChild("incremented_number")->get<int32_t>());
Next Previous

© Copyright 2020, BMW AG Revision eb679ab3.

Built with Sphinx using a theme provided by Read the Docs.