Game of Life
Posted: 09 Sep 2017, 15:19
With version 340 we introduced a new functionality for plugin buildings called fun. With it you can define actions which depend on conditions like whether a specific building is placed nearby. These transitions (conditions + following actions) are evaluated and executed daily so you there's no time limitation.
I tried to come up with a meaningful example to demonstrate it's capabilities. The result is a Game of Life implementation whose functionality is fully expressed via it's plugin code. The cells switch it's state if you click on them.
Here's how it looks like: And here's also a YouTube Video🎞 showing it in action.
The confuse you here's the code
Used images:
A proper documentation will follow. This plugin's purpose is to demonstrate the functionality rather than being useful.
I tried to come up with a meaningful example to demonstrate it's capabilities. The result is a Game of Life implementation whose functionality is fully expressed via it's plugin code. The cells switch it's state if you click on them.
Here's how it looks like: And here's also a YouTube Video🎞 showing it in action.
The confuse you here's the code
Code: Select all
// This is a plugin for TheoTown
// Visit www.theotown.com to learn more about TheoTown plugins
//
// Written by Lobby Divinus to demonstrate new fun functionality
[
{
"id":"$cat_gol",
"type":"category",
"title":"Game of Life",
"frames":[{"bmp":"icon.png"}]
},
{
"id":"$gol_dead",
"type":"decoration",
"category":"$cat_gol",
"title":"Dead cell",
"text":".",
"width":1,
"height":1,
"frames":[{"bmp":"gol.png","w":32,"h":16}],
"frame alignment area":true,
"fun":[
{
"condition":{"type":"nearby","z":3,"inner":[{"type":"building","id":"$gol_alive"}]},
"actions":[
{"type":"remove"},
{"type":"build","id":"$gol_alive"}
]
}
],
"on click fun":[
{
"actions":[
{"type":"remove"},
{"type":"build","id":"$gol_alive"}
]
}
]
},
{
"id":"$gol_alive",
"type":"decoration",
"category":"$cat_gol",
"title":"Alive cell",
"text":".",
"width":1,
"height":1,
"frames":[{"bmp":"gol.png","x":32,"w":32,"h":16}],
"frame alignment area":true,
"fun":[
{
"condition":{"type":"nearby","min":2,"max":3,"invert":true,"inner":[
{"type":"building","id":"$gol_alive"}
]},
"actions":[
{"type":"remove"},
{"type":"build","id":"$gol_dead"}
]
}
],
"on click fun":[
{
"actions":[
{"type":"remove"},
{"type":"build","id":"$gol_dead"}
]
}
]
}
]