Methods

Defining a custom method

Using the def command you can create a new custom method for your program to use. A custom method will return a value

Syntax

def input.method(parameters) (
    // run your method code
    return "data"
)

log "hi".method()
// this passes "hi" and null to the method and then logs "data"

Example

The below is an example of how to make a script that splits a string into single characters, like using

def text_data.makeLetters() (
  data = []
  // new array
  i = 0
  loop text_data.len (
    i ++
    // increment counter
    
    letter = text_data[i]
    // get letter of string

    data = data.append(letter)
    // push letter of string onto data array
  )
  return data
  // return the array
)

log "hello".makeLetters()
// ["h","e","l","l","o"]

We can also compress the splitter using some more advanced techniques

def text_data.makeLetters() (
  data = []
  // new array
  
  // start a for loop using the "i" variable
  for i text_data.len (
  
    data.append(text_data[i])
    // push letter of string onto data array
  )
  return data
  // return the array
)

log "hello".makeLetters()
// ["h","e","l","l","o"]

Last updated