Keylang - Get started

Version 2.0.0+

Keylang logo

If you know Python:

Keylang should be very easy to learn!

Otherwise, here you'll get the basics of Keylang and... coding in general


DO YOU understand this code?


var vari_name = dict("a" = random(67, 68), "b" = 2763)

func cool_func{
    print("hi")
	loop(3){
		wait(1)
		self 's scale *= random(vari_name)
		}
	}
	
cool_func()
	
# prints hi, then, repeating 3 times, waits 1 second before multiplying self's scale by a random value from the dictionary vari_name.

If yes, and you have little programming experience, then that shows how readable Keylang (and Python) is!

If no, and you have a lot of programming experience, then that's not good for Keylang


This page will teach you how to code basic Keylang, and show you how that code works

While assuming you don't know any programming


The most basic function


print("hi")

This is a function that PRINTS "hi". Where? To the stdout (standard output). Basically it prints "hi" somewhere the screen.
If you run a .py file with print("hi") in it, it will quickly open a terminal (the output area), print hi, then immediately close. You'll only see hi for a a few milliseconds, but it works
However, .kl files do NOT support this yet. It's an early release ok

Even this simple function has a lot of complexity in it. Why, thou may ponder whilst gandering at the general direction of the brackets and quotation marks, are those labyrinthine syntax decisions required?

Print is the first part. It is the (built in) function you're calling. When calling functions, they must have brackets after them to contain the argument.
Right now you would have:


print()

BUT inside the () is... NOTHING! Which means right now it prints nothing.
If you want it to print something, you need to put an ARGUMENT inside the brackets, and it will print whatever's in the brackets

print(hi)

BUTTTTTTTTTTTTT THIS DOES NOT WORK
If you've done programming before, you'll likely know why. You are printing the VARIABLE hi, not the TEXT hi
If the variable hi wasn't defined, it will error. If it was defined, it will print whatever hi's value is

var hi = 5
# Defines the variable hi with a value of 5

print(hi)
# This will print 5 instead of hi

If you want it to print the TEXT hi, you need to put it in quotation marks to state that it is a STRING.

print("hi")

Here, you directly state that it is a STRING and not a variable. THEN it will print hi


With the knowledge you now know, simply type code to print the word yahoo (case sensitive)





Variables and data types

Some words you type... are a type (literally).


"STRING"
# Specifies that it is TEXT (string)
'STRING'
# Same thing for single quotation marks

5
# Specifies that it is a WHOLE NUMBER (integer)

5.0
# Specifies that it is a DECIMAL NUMBER (float)

True
# Specifies that it is a TRUE or FALSE (boolean)

array(5, 2763, "string")
# Can contain multiple values

Above is only the basics, there's more
If you printed the above, it would be

print("STRING")
# Prints STRING

print(5)
# Prints 5

print(5.0)
# Prints 5.0

print(True)
# Prints True

print(array(5, 2763, "string"))
# Prints 5, 2763, "string"

ALL of these print exactly what is looks like, because none of them are variables.
When you want a variable, you type the var keyword, then a word that isn't a built in word

var this_is_a_var = 5
# Creates a variable named this_is_a_var with the value of 5

var not = 5
# Errors, cannot assign value to any reserved keywords

var print = 5
# Works, but horrible idea, as the print() function would stop working

YOU CAN assign data types OTHER than integers. For example:

var this_is_a_var = "hi"
# Creates a variable named this_is_a_var with the value of "hi"
print(this_is_a_var)
# Prints hi

AND you CAN do operations with data types of the same data type:

print(6 * 7)
# Prints 42
print("hi" + 'there')
# Prints hithere (no spaces)

Why variables when you can just type numbers?
BECAUSE YOU CAN CHANGE THE VARIABLES
THEY'RE CALLED VARIABLES FOR A REASON they VARY!!!

If you changed the value of a variable, stuff that use the variable will be altered to using the new value

To change variables, you have the basic math operators you have, BUT with = in front of them!!!

var vari_name = 0
# Creates a variable named vari_name with the value of 0

vari_name += 5
# Adds 5 to vari_name, new value is 5

vari_name *= 5
# Multiplies vari_name by 5, new value is 25

vari_name /= 5
# Divides vari_name by 5, new value is 5

vari_name = 5
# It's reverse for this. == would mean "is equal to" and = would mean "WILL be equal to"
# Sets vari_name to 5, new value is... also 5

How would you add 5 to a variable called woah_vari_name





Now, looking back at the code from the start:


var vari_name = dict("a" = random(67, 68), "b" = 2763)

func cool_func{
    print("hi")
	loop(3){
		wait(1)
		self 's scale *= random(vari_name)
		}
	}
	
cool_func()
	
# prints hi, then, repeating 3 times, waits 1 second before multiplying self's scale by a random value from the dictionary vari_name.

You now understand how print() works! As well as wait(), where you're using the function wait with the argument 1 in between the brackets.
You also can understand random() a little, it takes one of the RANDOM numbers that vari_name's value contains. You'll learn more about this later
What's func though


Functions (the non built in ones)

Functions are different from Python in Keylang.

Functions are defined using the func keyword. Calling a function with the function's name will execute the code in the function.


func cool_func {
# creates a function called cool_func
    print("hi")
}
	
cool_func()
# Calls the function named cool_func, therefore printing hi

print() is a built in function. cool_func() is a CUSTOM function.
The "{" signifies the START of the function, and "}" signifies the END. If a variable is defined INSIDE a function's curly brackets, they only exist INSIDE that function

func cool_func {
    print("this is in the function")
    var_name = "this only exists in the function"
}
print("this is out of the function")

When cool_func is called, you must add brackets at the end, even though there's nothing inside the brackets.

cool_func
# WRONG

cool_func()
# RIGHT!!!

Now... assuming there's a function called uncool_func, how would you call it





Now, looking back at the code from the start AGAIN:


var vari_name = dict("a" = random(67, 68), "b" = 2763)

func cool_func{
    print("hi")
	loop(3){
		wait(1)
		self 's scale *= random(vari_name)
		}
	}
	
cool_func()
	
# prints hi, then, repeating 3 times, waits 1 second before multiplying self's scale by a random value from the dictionary vari_name.

You now understand how print(), wait(), random() somewhat, and func {} works!
You also understand loop, it's basically like a function, it has "{" that signifies the start and "}" for the end. print("hi") is OUTSIDE of the loop curly brackets, so it doesn't get looped
What's dict() though


Lists and dictionaries

Looking back:


print(array(5, 2763, "string"))
# Prints 5, 2763, "string"

This is a LIST, not an ARRAY despite what it says. Can be a little bit confusing for programmers, I'll probably change that later
Lists can contain multiple values. To make a list, just type array(). Inside array's brackets, you put the values you want to put, seperated by commas

the_LIST_name = array(value1, value2, "you_can_add_as_much_as_you_want")


If you want to access one of the LIST's values from a variable, you type the variable's name and a set of square brackets, with a number in them

var var_name = array(5, 2763, "string"))

print(var_name[0])
# Prints the FIRST number in the list, which would be 5

print(var_name[1] + 5)
# Prints the SECOND number in the list PLUS 5, which would be 2768

print(var_name[2])
# Prints the THIRD number in the list, which would be "string"

Yeah it's weird
You would need to type 0 to get the first number of the list

dict() functions similarly to array(). The difference is that the values inside dict's brackets need to be assigned to stuff inside dict()
And instead of doing vari_name[number], you would do vari_name[variable that number is assigned to]

var var_LIST = array(5, 2763)
var var_dict = dict("a" = 5, "b" =  2763)
# You don't need to create these variables, but you can use created variables

print(var_LIST[0])
# Prints the FIRST number in the list, which would be 5

print(var_dict["a"])
# Prints whatever "a" is assigned to in the dictionary, which would be 5

Looking back:

var vari_name = dict("a" = random(67, 68), "b" = 2763)

Yeah you basically know what random() does at this point, it picks a random number from the MULTIPLE values inside its brackets

Here's a hard question that's actually a test of my explanation
If there was a there was vari_name = dict("a" = "yay", "b" = "nay"), how would you print yay





Now, looking back at the code from the start yet AGAIN:


var vari_name = dict("a" = random(67, 68), "b" = 2763)

func cool_func{
    print("hi")
	loop(3){
		wait(1)
		self 's scale *= random(vari_name)
		}
	}
	
cool_func()
	
# prints hi, then, repeating 3 times, waits 1 second before multiplying self's scale by a random value from the dictionary vari_name.

You now understand... everything
EXCEPT for this one line:

self 's scale *= random(vari_name)

Well, "self" is just the current object that the script is on
"'s" accesses self's properties. A dot (.) works perfectly fine too.
"scale" is one of self's built in properties. It's the variable for the... scale of the object

Right now we have "self 's scale", and we ALSO have "*= random(vari_name)"

"*=" you know what this does
"random(vari_name)" takes a random value from vari_name's dictionary

So this code multiplies the scale of the object which this script is on by a random number chosen from vari_name.


Congratulations!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
You're pro Keylang (and half pro Python cause of the similarity) now!!!!!!!!!

The rest you'll need to know is on the main page, and on the Python website cause they're THAT similar