Skip to content
Lloyd Dilley edited this page Jun 17, 2020 · 10 revisions

Comments

# Single line comment

##
Multi-line
Comments
##

Functions and Variables

Functions execute a block of code when called. The last value in the function body becomes its return value.

func add(num1, num2) {
  num1 + num2
}
sum = add(5, 3) # sum equals 8

Parentheses are optional in most cases, so the following would work as well:

sum = add 5, 3

Statements

Concoct provides the standard set of statements

myVar = true

if myVar
  executeFunc()

while myVar
  executeFunc()

do
  executeFunc()
while myVar

num = 2
switch num {
  if 1:
    executeFunc1()
    # break statements are implicit
  if 2:
    executeFunc2()
  else:
    executeFunc3()
}

Arrays and For Loop

myArray = [5, "string", 'a', false]

# Either this syntax or possibly a "contains" method for checking array members
if("string" in myArray)
  print "Array contains string"

for element in array
  print element


for num in range(5)
  print num

Classes and Namespaces

Classes are for object-oriented designs, and they can optionally be grouped in namespaces.

namespace RPG {
  class Entity {
    func new(name) {
      self.name = name
      self.health = 100
    }
  }

  class Player : Entity {
    func new() : super("Player Name") {

    }
    func take_damage(amount) {
      self.health -= amount
    }
  }
}
player = new RPG.Player()
player.take_damage(13)
Clone this wiki locally