Game of Life

For Decorations and areal map layout tools.

Moderator: Plugin Moderators

User avatar
Lobby
Developer
Reactions:
Posts: 3705
Joined: 26 Oct 2008, 12:34
Plugins: Showcase Store
Version: Beta

Platform

Game of Life

#1

Post by Lobby »

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
And 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 9893 times
icon.png
icon.png (303 Bytes) Viewed 9893 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 276 times
Game of Life.zip
(2.25 KiB) Downloaded 373 times

User avatar
Bearbear76
Former Bearbear65
Reactions:
Posts: 5730
Joined: 10 Feb 2017, 14:53
Location: L2 cache
Plugins: Showcase Store

Plugin Creator

Platform

Re: Game of Life

#2

Post by Bearbear76 »

Nice... again :bc

User avatar
Bearbear76
Former Bearbear65
Reactions:
Posts: 5730
Joined: 10 Feb 2017, 14:53
Location: L2 cache
Plugins: Showcase Store

Plugin Creator

Platform

Re: Game of Life

#3

Post by Bearbear76 »

What's "z" :bq

User avatar
Lobby
Developer
Reactions:
Posts: 3705
Joined: 26 Oct 2008, 12:34
Plugins: Showcase Store
Version: Beta

Platform

Re: Game of Life

#4

Post by Lobby »

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.

User avatar
Josh
Graphic designer
Reactions:
Posts: 2214
Joined: 11 Mar 2017, 19:20
Location: The Netherlands
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Game of Life

#5

Post by Josh »

That is something cool :fire

User avatar
JustAnyone
Developer
Reactions:
Posts: 3474
Joined: 23 Jul 2017, 12:45
Location: Easter Island
Plugins: Showcase Store

Platform

Re: Game of Life

#6

Post by JustAnyone »

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

User avatar
Lobby
Developer
Reactions:
Posts: 3705
Joined: 26 Oct 2008, 12:34
Plugins: Showcase Store
Version: Beta

Platform

Re: Game of Life

#7

Post by Lobby »

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.

User avatar
Thisismyname
Small-town resident
Reactions:
Posts: 27
Joined: 23 Feb 2018, 09:01
Plugins: Showcase Store
Version: Beta

Platform

Re: Game of Life

#8

Post by Thisismyname »

Yay
Attachments
Screenshot_20181222-231404.png

User avatar
imajoke
Inhabitant of a Conurbation
Reactions:
Posts: 532
Joined: 27 Oct 2019, 02:39
Plugins: Showcase Store
Version: Beta

Re: Game of Life

#9

Post by imajoke »

lol this is already in-game...

i know, this is before it was added

i also know this thread is dead

so dont reply saying "this thread is dead" or whatever

User avatar
Bearbear76
Former Bearbear65
Reactions:
Posts: 5730
Joined: 10 Feb 2017, 14:53
Location: L2 cache
Plugins: Showcase Store

Plugin Creator

Platform

Re: Game of Life

#10

Post by Bearbear76 »

imajoke wrote:
06 Apr 2020, 04:22
lol this is already in-game...

i know, this is before it was added

i also know this thread is dead

so dont reply saying "this thread is dead" or whatever
What was the point in the post though?

Post Reply Previous topicNext topic

Return to “Decorations and Tools”