Skip to content

Using crossplot

Sven Marcus edited this page Jun 5, 2021 · 1 revision

Using crossplot for communication between story plots

The DeepCore framework comes with crossplot, a library that allows publish-subscribe communication via GlobalValues between story plots. To achieve this crossplot initialises a MainGlobalValueEventBus in GameScoring.lua that listens to incoming subscriptions and publish messages. The publish messages are redirected to GlobalValueEventBus instances running on different story plots. Users of crossplot don't have to worry about the implementation details and can simply call crossplot:galactic() to initialise crossplot in a galactic story plot. The story plot running the instance of EawXMod does not have to call crossplot:galactic() explicitly, it will be initialised inside the EawXMod constructor and can be used globally afterwards.

The example below shows how the first plot subscribes to the sub_test event with its Receive function with crossplot:subscribe(). The second plot uses crossplot:publish() to publish an update to the sub_test event. The additional second argument provided by this plot will be passed on to the Receive function in the first plot. The number of additional arguments is not limited.

Click to see Rebel plot
require("PGDebug")
require("PGStateMachine")
require("PGStoryMode")

require("deepcore/crossplot/crossplot")

function Definitions()
    DebugMessage("%s -- In Definitions", tostring(Script))

    ServiceRate = 0.1

    StoryModeEvents = {Universal_Story_Start = Begin_GC}
end

function Begin_GC(message)
    if message == OnEnter then
        crossplot:galactic()
        crossplot:subscribe("sub_test", Receive)
    elseif message == OnUpdate then
        crossplot:update()
    end
end

function Receive(text_entry)
    Game_Message(text_entry)
end
Click to see Empire plot
require("PGDebug")
require("PGStateMachine")
require("PGStoryMode")

require("deepcore/crossplot/crossplot")

function Definitions()
    DebugMessage("%s -- In Definitions", tostring(Script))

    ServiceRate = 0.1

    StoryModeEvents = {Universal_Story_Start = Begin_GC}
end

function Begin_GC(message)
    if message == OnEnter then
        crossplot:galactic()
        Sleep(1) -- sleep to make sure the other plot had time to subscribe
        crossplot:publish("sub_test", "TEXT_FACTION_EMPIRE")
    elseif message == OnUpdate then
        crossplot:update()
    end
end