Skip to content
This repository was archived by the owner on Aug 16, 2018. It is now read-only.

Writing Maps

std::gregwar edited this page Feb 2, 2018 · 3 revisions

Abstract

In solarus, map scripts define how the environment reacts to player actions given the environment state. These reactions consist most of the time in state change. This state change is then displayed visually to the player.

Given this matter of fact, solarus-online main way to 'synchronise' maps is to provide a network synchronised state and ways to capture changes in this state, react to it and decide further state alterations.

Online map script 101

--Template for online map scripts
local map = ...

function map:on_restore_from_state(state)
  --Init you local map copy from state here
  --Setup callback as you usually do for an offline map
  --make sure code only affect state
  --given state table is just a shorthand for
  --map.state
end

map:watch_state_val(
    'key',
    function(value,old_value)
      --React to change of map.state[key] here
end)

map:watch_state_vals(
    'key1', 'key2',
    function(val1,val2)
      -- React to change of key1 or key2 here
end)

map.state

Since online maps inherit the stateful trait, they are blessed with a state field. This state is a smart table that will report to the server any modification. This is your main way of communicating and expressing map changes. As every client automatically sees and capture the changes in this table, expressing map events and actions through state guarantee that everyone has the same map under their eyes, by construction.

Example

--TODO example of two switches opening a door
Clone this wiki locally