Game of Life

For Decorations and areal map layout tools.

Moderator: Plugin Moderators

User avatar
Lobby
Developer
Reactions:
Posts: 3110
Joined: Sun Oct 26, 2008 12:34
Plugins: Show
Version: Beta
Phone model: S7 edge

Game of Life

Post by Lobby » Sat Sep 09, 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:
2017-09-09 15.10.24.png
Ans here's also a YouTube Video🎞 showing it in action.

The confuse you here's the code :json

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"}
        ]
      }
    ]
  }
]
Used images:
gol.png
gol.png (924 Bytes) Viewed 1995 times
icon.png
icon.png (303 Bytes) Viewed 1995 times
A proper documentation will follow. This plugin's purpose is to demonstrate the functionality rather than being useful.
Attachments
gol.json
(1.6 KiB) Downloaded 39 times
Game of Life.zip
(2.25 KiB) Downloaded 106 times
...Have a nice stay

User avatar
Bearbear65
Inhabitant of a Universe
Reactions:
Posts: 4465
Joined: Fri Feb 10, 2017 14:53
Plugins: Show
Version: Beta
Phone model: ASUS ZenPad 10 z300c

Re: Game of Life

Post by Bearbear65 » Sat Sep 09, 2017 15:22

Nice... again :bc
ImageJust my opinion
Caladrius is officially my favourite bird

User avatar
Bearbear65
Inhabitant of a Universe
Reactions:
Posts: 4465
Joined: Fri Feb 10, 2017 14:53
Plugins: Show
Version: Beta
Phone model: ASUS ZenPad 10 z300c

Re: Game of Life

Post by Bearbear65 » Sat Sep 09, 2017 15:42

What's "z" :bq
ImageJust my opinion
Caladrius is officially my favourite bird

User avatar
Lobby
Developer
Reactions:
Posts: 3110
Joined: Sun Oct 26, 2008 12:34
Plugins: Show
Version: Beta
Phone model: S7 edge

Re: Game of Life

Post by Lobby » Sat Sep 09, 2017 15:47

In this context it means how many buildings of this id are expected as neighbor. If the actual number differs the condition is not fulfilled.
...Have a nice stay

User avatar
Josh
Graphic designer
Reactions:
Posts: 2199
Joined: Sat Mar 11, 2017 19:20
Location: The Netherlands
Plugins: Show
Version: Beta

Re: Game of Life

Post by Josh » Sat Sep 09, 2017 15:59

That is something cool :fire
Proud TheoTown player sinds update 1.1.50

Creator of Aldorria, Covinton Empire, West Country, Sunnydale

Save nature, before it kills you🌲

User avatar
JustAnyone
Feature manager
Reactions:
Posts: 2246
Joined: Sun Jul 23, 2017 12:45
Location: Phone repair service
Plugins: Show
Version: Beta
Phone model: Xiaomi Redmi 3s

Re: Game of Life

Post by JustAnyone » Sun Sep 10, 2017 15:42

In latest video Lobby created some dangerous wildlife animals eating power lines.

User avatar
Lobby
Developer
Reactions:
Posts: 3110
Joined: Sun Oct 26, 2008 12:34
Plugins: Show
Version: Beta
Phone model: S7 edge

Re: Game of Life

Post by Lobby » Tue Sep 12, 2017 12:51

I just updated the code to use new fun functionality from version 341. The old code will still work, though I recommend to forget about anything you read in it. The new style is cleaner and has better performance.
...Have a nice stay

Post Reply Previous topicNext topic

Return to “Decorations and Tools”

Who is online

Users browsing this forum: No registered users and 1 guest