Game of Life

For Decorations and areal map layout tools.

Moderators: KoalaGuy, Showcase Moderators

Post Reply
User avatar
Lobby
Developer
Reactions:
Posts: 2321
Joined: Sun Oct 26, 2008 12:34

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 545 times
icon.png
icon.png (303 Bytes) Viewed 545 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 10 times
Game of Life.zip
(2.25 KiB) Downloaded 30 times
...Have a nice stay

User avatar
Bearbear65
Inhabitant of a Supercluster
Reactions:
Posts: 3697
Joined: Fri Feb 10, 2017 14:53
Location: Japan

Re: Game of Life

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

Nice... again :bc
ImageJust my opinion

User avatar
Bearbear65
Inhabitant of a Supercluster
Reactions:
Posts: 3697
Joined: Fri Feb 10, 2017 14:53
Location: Japan

Re: Game of Life

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

What's "z" :bq
ImageJust my opinion

User avatar
Lobby
Developer
Reactions:
Posts: 2321
Joined: Sun Oct 26, 2008 12:34

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: 1912
Joined: Sat Mar 11, 2017 19:20

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
My plugins and collections!
Creator of Aldorria, Covinton Empire, West Country, Sunnydale
Save nature, before it kills you🌲

Online
User avatar
JustAnyone
Inhabitant of a Continent
Reactions:
Posts: 1005
Joined: Sun Jul 23, 2017 12:45
Location: Space Station 478B
Contact:

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.
President of Domkisas
Founder and owner of DSA
Discord manager.

User avatar
Lobby
Developer
Reactions:
Posts: 2321
Joined: Sun Oct 26, 2008 12:34

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

Who is online

Users browsing this forum: No registered users and 2 guests