Page 1 of 1

Game of Life

Posted: 09 Sep 2017, 15:19
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 9909 times
icon.png
icon.png (303 Bytes) Viewed 9909 times
A proper documentation will follow. This plugin's purpose is to demonstrate the functionality rather than being useful.

Re: Game of Life

Posted: 09 Sep 2017, 15:22
by Bearbear76
Nice... again :bc

Re: Game of Life

Posted: 09 Sep 2017, 15:42
by Bearbear76
What's "z" :bq

Re: Game of Life

Posted: 09 Sep 2017, 15:47
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.

Re: Game of Life

Posted: 09 Sep 2017, 15:59
by Josh
That is something cool :fire

Re: Game of Life

Posted: 10 Sep 2017, 15:42
by JustAnyone
In latest video Lobby created some dangerous wildlife animals eating power lines.

Re: Game of Life

Posted: 12 Sep 2017, 12:51
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.

Re: Game of Life

Posted: 23 Dec 2018, 11:04
by Thisismyname
Yay

Re: Game of Life

Posted: 06 Apr 2020, 04:22
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

Re: Game of Life

Posted: 08 Apr 2020, 05:28
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?