Game of Life

For Decorations and areal map layout tools.

Moderator: Plugin Moderators

User avatar
Lobby
Developer
Reactions:
Posts: 3639
Joined: Sun Oct 26, 2008 12:34
Plugins: Show
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 5371 times
icon.png
icon.png (303 Bytes) Viewed 5371 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 141 times
Game of Life.zip
(2.25 KiB) Downloaded 217 times
=^._.^= ∫

User avatar
Bearbear76
Former Bearbear65
Reactions:
Posts: 5347
Joined: Fri Feb 10, 2017 14:53
Plugins: Show
Version: Beta

Platform

Plugin Creator

Re: Game of Life

#2

Post by Bearbear76 »

Nice... again :bc
Just my opinion

User avatar
Bearbear76
Former Bearbear65
Reactions:
Posts: 5347
Joined: Fri Feb 10, 2017 14:53
Plugins: Show
Version: Beta

Platform

Plugin Creator

Re: Game of Life

#3

Post by Bearbear76 »

What's "z" :bq
Just my opinion

User avatar
Lobby
Developer
Reactions:
Posts: 3639
Joined: Sun Oct 26, 2008 12:34
Plugins: Show
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: 2223
Joined: Sat Mar 11, 2017 19:20
Location: The Netherlands
Plugins: Show
Version: Beta

Platform

Plugin Creator

Re: Game of Life

#5

Post by Josh »

That is something cool :fire
TheoTown player since update 1.1.50

Creator of Aldorria, Covinton Empire, West Country, Sunnydale

User avatar
JustAnyone
Rip-off engineer
Reactions:
Posts: 3106
Joined: Sun Jul 23, 2017 12:45
Location: Easter Island
Plugins: Show

Platform

Re: Game of Life

#6

Post by JustAnyone »

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

User avatar
Lobby
Developer
Reactions:
Posts: 3639
Joined: Sun Oct 26, 2008 12:34
Plugins: Show
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: Fri Feb 23, 2018 9:01
Plugins: Show
Version: Beta

Platform

Re: Game of Life

#8

Post by Thisismyname »

Yay
Attachments
Screenshot_20181222-231404.png
I like bulding realistic stuff
But i still dont know how to make plugins

:bt

imajoke
Inhabitant of a Conurbation
Reactions:
Posts: 435
Joined: Sun Oct 27, 2019 2:39
Location: what's this stalker stop asking me XD
Plugins: Show
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
Show
click me
MADE YA LOOK LOOOOL :space
youtube: curtis warren btw stop begging

User avatar
Bearbear76
Former Bearbear65
Reactions:
Posts: 5347
Joined: Fri Feb 10, 2017 14:53
Plugins: Show
Version: Beta

Platform

Plugin Creator

Re: Game of Life

#10

Post by Bearbear76 »

imajoke wrote:
Mon Apr 06, 2020 4: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?
Just my opinion

Post Reply Previous topicNext topic

Return to “Decorations and Tools”