Skip to content

Examples

Lesson #0 - Hello world!

Every bot needs at least a main dialog. This is the dialog that gets triggered when the bot starts. As you can see, using the # character you can add comments to your scripts.

Lesson #1 - Dialogs and triggers

Lesson #2 - say & show

Lesson #3 - Ask

Lesson #4 - Strings & numbers

Lesson #5 - Locations

Lesson #6 - Collections

Due to the use of log, you should run this script in the DialoX studio directly.

dialog main do
  say "Look at the Log pane in the lower mid part of your studio window:"
  show image "https://s3.eu-west-1.amazonaws.com/bsqd-out/image/13f1c476-ccb6-49c8-85e3-dae2473405dc-1280x1280.jpg"
  invoke arrays
  invoke lists
  invoke maps
end

# see https://developer.dialox.ai/bubblescript/builtins/#list-array-functions
dialog arrays do
  # an array
  colors = ["red", "green", "blue", "yellow", "purple", "brown"]

  # pick an item by its index
  log colors[0]

  # iterate through all items
  say "colors:"
  repeat c in colors do
    say c
  end

  # from array to string
  colors = join(colors, ", ")
  say "Colors comma separated: #{colors}"

  # from string to array
  colors = split(colors, ", ")

  # from array to string with last item different: x, y and z
  say "Colors nicely formatted: #{join(colors, ", ", " and ")}"

  # slice a part of the list
  log slice(colors, 2, 3)

  # shuffle the list
  log shuffle(colors)

  # reverse the list
  log reverse(colors)

  # get first item
  log first(colors)

  # get the length of the list
  log length(colors)

  # add something to the list
  colors = colors + "cyan"
  log colors

  # take something out of the list
  colors = colors - "yellow"
  log colors

  # sort
  log sort(colors)
end

dialog lists do
  colors = [red: [255, 0, 0], green: [0, 255, 0], blue: [0, 0, 255], yellow: [255, 255, 0]]

  log colors["red"]        # to show all values for red
  log colors["yellow"][0]  # to show the red value of yellow

  log keys(colors)         # to show all keys

  log values(colors)       # to show all values

  repeat c in keys(colors) do
    say "#{c} is made out of:\n
    red: #{colors[c][0]}\n
    green: #{colors[c][1]}\n
    blue: #{colors[c][2]}"
  end
end

dialog maps do
  # define a map
  colors = [
    [color: "red"   , rgb: [255, 0, 0]     ],
    [color: "green" , rgb: [0, 255, 0]     ],
    [color: "yellow", rgb: [255, 255, 0]   ],
    [color: "white" , rgb: [255, 255, 255] ]
  ]

  # notice you can also do it the elixir way:
  colors = [
    %{ "color" => "red"  , "rgb" => [255, 0, 0] },
    %{ "color" => "green", "rgb" => [0, 255, 0] },
    %{ "color" => "blue" , "rgb" => [0, 0, 255] },
  ]

  # we are going to create a map with colors and their intensities
  map = []
  repeat c in colors do
    item = [color: c.color, intensity: c.rgb[0] + c.rgb[1] + c.rgb[2]]
    map = map + item
  end

  # sort the list on highest intensity on top
  map = sort(map, field: "intensity", direction: :desc)

  # show the sorted list
  say "Colors, ordered by intensity"
  repeat item in map do
    say item.color
  end
end