Is there any way to shorten the repeating 'fun' codes?

Plug-in related stuff can be discussed here.

Moderator: Plugin Moderators

User avatar
Index
Settler
Reactions:
Posts: 6
Joined: 07 Jul 2018, 08:26
Location: Seoul(Korea Rep.)
Plugins: Showcase Store

Is there any way to shorten the repeating 'fun' codes?

#1

Post by Index »

Code: Select all

{
    "condition":{
    "type":"value", "code":"$redbuttoncount+1%10","z"=0
    },
    "actions":[
     {
      "type":"remove","y":1
     },
     {
      "type":"build","id":"index_dsp_0k","y":1
     }
    ],
    "always":true
   },
{
    "condition":{
    "type":"value", "code":"$redbuttoncount+1%10","z"=1
    },
    "actions":[
     {
      "type":"remove","y":1
     },
     {
      "type":"build","id":"index_dsp_1k","y":1
     }
    ],
    "always":true
   },
//... repeat to 9
I'm making a button counter plugin. But the code goes too long when I make the code repeating most of the components but building id and condition value.
Is anyone know how to shorten this code or seperating JSON files on one building?

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

Platform

Re: Is there any way to shorten the repeating 'fun' codes?

#2

Post by Lobby »

First of all I assume you mean "z":0 instead of "z"=0.

ABout your issue I'm afraid there isn't a better way to do it. However you might use a shorter format:

Code: Select all

{
  "condition":{"type":"value", "code":"$redbuttoncount+1%10","z":0},
  "actions":[
    {"type":"remove","y":1},
    {"type":"build","id":"index_dsp_0k","y":1}
  ],
  "always":true
},
{
  "condition":{"type":"value", "code":"$redbuttoncount+1%10","z":1},
  "actions":[
    {"type":"remove","y":1},
    {"type":"build","id":"index_dsp_1k","y":1}
  ],
  "always":true
 },
//... repeat to 9
Also you can simplify value conditions like this one

Code: Select all

"condition":{"type":"value", "code":"$redbuttoncount+1%10","z":0}
to

Code: Select all

"condition":"$redbuttoncount+1%10=0"
Similar shorthand syntax is available for set actions.

If you need the a whole fun code multiple times you can use a template for it.

User avatar
Index
Settler
Reactions:
Posts: 6
Joined: 07 Jul 2018, 08:26
Location: Seoul(Korea Rep.)
Plugins: Showcase Store

Re: Is there any way to shorten the repeating 'fun' codes?

#3

Post by Index »

Thanks for fast reply. I have one more question. Seperating the codes yo multi JSONs on one id is possible?

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

Platform

Re: Is there any way to shorten the repeating 'fun' codes?

#4

Post by Lobby »

It partly is by using templates. However, you have then to ensure that the templates have been loaded first (by naming them accordingly). Also you cannot split up the content of "fun":[...] so that's limited.

User avatar
Index
Settler
Reactions:
Posts: 6
Joined: 07 Jul 2018, 08:26
Location: Seoul(Korea Rep.)
Plugins: Showcase Store

Re: Is there any way to shorten the repeating 'fun' codes?

#5

Post by Index »

Thanks ;)

Post Reply Previous topicNext topic

Return to “Plug-In Discussion”