Skip to content

Examples

dougreichard edited this page May 21, 2025 · 3 revisions

Welcome to the Artemis Cosmos examples page

Table of Contents:

  1. Communication With State

Communication with State


Note

Required libraries

  1. Artemis Cosmos v1.1.0 or greater
  2. artemis-sbs.sbs_utils
  3. artemis-sbs.legendarymissions.internal_comms

This is an example of a communication conversation that saves the state of the conversation.

Add the lifeforms Dude and Dudet to player ships by adding this code somewhere after the players ships are created.

    for p in to_object_list(role("__player__")):
        lifeform_spawn("dude", random_terran(civilian=True), "dude",p, path="//comms/dude")
        lifeform_spawn("dudet", random_terran(civilian=True), "dudet",p, path="//comms/dudet")

Then add these comms. To have conversations with Dude and Dudet. Since they have a path, they will have a comms badge, and can be contacted via the ship/station they are on.

"Play Game" will play a game where the lifeforms try to guess you favorite Arvonian ship.

Notice the use of the jump() function using the saved state to jump to the right state handler.

//comms/dude 
  
    + "What's up":
        with comms_override(COMMS_ORIGIN_ID, LIFEFORM_ID):
            << "Status"
                % just chillin
                % righteous
    + "Play game" //comms/favorite_ship

//comms/dudet 
    + "How you doin'?":
        with comms_override(COMMS_ORIGIN_ID, LIFEFORM_ID):
            << "Status"
                % Get lost
                % Pig
    + "Play game" //comms/favorite_ship

//comms/favorite_ship
    quiz_state = get_inventory_value(LIFEFORM_ID, "quiz_state")
    if quiz_state is not None:
        jump(quiz_state)

    with comms_override(COMMS_ORIGIN_ID, LIFEFORM_ID):
        << "Question"
            % Does your favorite arvonian ship have a tavern
    
    + "Yes":
        set_inventory_value(LIFEFORM_ID, "quiz_state", "yes1")
    + "No":
        set_inventory_value(LIFEFORM_ID, "quiz_state", "no1")
    yield success

--- yes1
    with comms_override(COMMS_ORIGIN_ID, LIFEFORM_ID):
        << "Question"
            % Does your favorite arvonian ship have VIP Quarters

    + "Yes":
        set_inventory_value(LIFEFORM_ID, "quiz_state", "yes1_yes")
    + "No":
        set_inventory_value(LIFEFORM_ID, "quiz_state", "yes1_no")
    yield success

--- yes1_yes
    with comms_override(COMMS_ORIGIN_ID, LIFEFORM_ID):
        << "Answer"
            % Your favorite is the arvonian carrier

    + "Yes":
        with comms_override(COMMS_ORIGIN_ID, LIFEFORM_ID):
            << "Response"
                % Great that was fun!
        comms_navigate("//comms/")
        set_inventory_value(LIFEFORM_ID, "quiz_state", None)
    + "No":
        with comms_override(COMMS_ORIGIN_ID, LIFEFORM_ID):
            << "Response"
                % You lied or you don't know arvonian ships
        comms_navigate("//comms/")
        set_inventory_value(LIFEFORM_ID, "quiz_state", None)

--- yes1_no
    with comms_override(COMMS_ORIGIN_ID, LIFEFORM_ID):
        << "Answer"
            % Your favorite arvonian is the light carrier

    + "Yes":
        with comms_override(COMMS_ORIGIN_ID, LIFEFORM_ID):
            << "Response"
                % Great that was fun!
        comms_navigate("//comms/")
        set_inventory_value(LIFEFORM_ID, "quiz_state", None)
    + "No":
        with comms_override(COMMS_ORIGIN_ID, LIFEFORM_ID):
            << "Response"
                % You lied or you don't know arvonian ships
        comms_navigate("//comms/")
        set_inventory_value(LIFEFORM_ID, "quiz_state", None)
    yield success

--- no1
    with comms_override(COMMS_ORIGIN_ID, LIFEFORM_ID):
        << "Question"
            % Does your favorite arvonian ship have a brig
            % Does your favorite arvonian ship have crew quarters
            % Does your favorite arvonian ship have a gym
            % Does your favorite arvonian ship have a hyper drive

    + "Yes":
        set_inventory_value(LIFEFORM_ID, "quiz_state", "no1_yes")
    + "No":
        set_inventory_value(LIFEFORM_ID, "quiz_state", "no1_no")
    yield success

--- no1_yes
    with comms_override(COMMS_ORIGIN_ID,LIFEFORM_ID):
        << "Answer"
            % Your favorite arvonian ship is the destroyer

    + "Yes":
        with comms_override(COMMS_ORIGIN_ID,LIFEFORM_ID):
            << "Response"
                % Great that was fun!
        comms_navigate("//comms/")
    + "No":
        with comms_override(COMMS_ORIGIN_ID, LIFEFORM_ID):
            << "Response"
                % You lied or you don't know arvonian ships
        comms_navigate("//comms/")

-- no1_no
    with comms_override(COMMS_ORIGIN_ID,LIFEFORM_ID):
        << "Answer"
            % Your favorite is the arvonian fighter

    + "Yes":
        with comms_override(COMMS_ORIGIN_ID, LIFEFORM_ID):
            << "Response"
                % Great that was fun!
        comms_navigate("//comms/")
        set_inventory_value(LIFEFORM_ID, "quiz_state", None)
    + "No":
        with comms_override(COMMS_ORIGIN_ID, LIFEFORM_ID):
            << "Response"
                % You lied or you don't know arvonian ships
        comms_navigate("//comms/")
        set_inventory_value(LIFEFORM_ID, "quiz_state", None)
    yield success
        

Clone this wiki locally