Author Topic: Custom Script syntax question  (Read 4012 times)

0 Members and 1 Guest are viewing this topic.

Padanges

  • Newbie
  • *
  • Posts: 179
Custom Script syntax question
« on: August 23, 2016, 01:35:30 PM »
Hi,
is it possible to write such a script (function) that it would have a dynamic name reference? For example, I want to extend the functionality of a given function "Split" which has syntax [Split:d|n]. But following given examples all I can get is [Split](d|n). Which means that I can't pass results of a previous function to this function.
The second question is whether we can "overwrite" the names of the default functions?


Thanks in advance.

RTT

  • Administrator
  • *****
  • Posts: 918
Re: Custom Script syntax question
« Reply #1 on: August 24, 2016, 12:56:21 AM »
I thought about this at the time, but decided it was too much confuse to use with these simple hard coded functions already with an awkward syntax. I might return to this later, but higher complexity can always be handled with a custom script function.

You can create a script function named Split and pass static parameters, or even from other functions results. Here's a quick example:
Code: [Select]
function Split() {
    var params = CurrentField.Value.split('|');
    if (params.length == 3) {
        ss = params[0].split(params[1]);
        if (ss.length > parseInt(params[2])) return ss[parseInt(params[2])]
    }
}
It takes 3 parameters as one string, with each parameters separated by a | character. The first is the string to split, the second is the separator and the last one is the index of the part to return.
Calling examples:
  Split the filename by the space character, and return the second word: [Split]([F]| |1)
  Split the author by a custom function returned separator, and return the first part: [Split]([A]|[GetSeparator]([A])|0)