Globals

Bosscript comes with several built-in functions declared as global variables. They can be used anywhere within a Bosscript program. These are:

  1. ispis()
  2. greska()
  3. upozorenje()
  4. unos()
  5. postoji()
  6. nasumicni()
  7. brojOd()
  8. logickiOd()
  9. nizOd()
  10. tip()

Functions ispis, greska, upozorenje and unos

All four of these functions are covered in the Standard Input and Output article. Read the article to learn more about them.

Function postoji

The postoji function simply performs a null check. It is an alternative to using the ! operator:

ako(postoji(x)){
    ispis("'x' exists");
}

ako(!x){
    ispis("'x' doesn't exist");
}

Function nasumicni

The nasumicni function is a random number generator. By default, it generates a random number from 0 to 100 exclusive, but you can provide a different ending bound as an argument:

var n = nasumicni();
var cn = nasumicni(25);

ispis(n, cn);
Output:

63
12

Function brojOd

The brojOd function is a function for parsing numbers from other types. When provided a broj, it simply returns another broj with the same value. When provided a tekst, it tries to parse a number out of it and throws an exception if it is not able to. Finally, when provided a logički, it returns 0 if the value is netačno and 1 if the value is tačno.

var l = brojOd(netačno);
var t = brojOd("12.44");
var b = brojOd(10);

ispis(b, l, t);
Output:

10
12.44
0

Trying to parse an invalid tekst or passing a value of any type other than the three supported ones will result in an exception:

var invalidTekst = "one million";
var b = brojOd(invalidTekst);
Error: Cannot parse 'one million' into broj.
var invalid = [1,5,2,1];
var b = brojOd(invalid);
Error: Cannot convert [1,5,2,1] to broj.

Function logickiOd

Similar to brojOd, logickiOd is also a parsing function. It parses a logički from other types. When provided a logički, it simply returns a new logički with the same value. When provided a tekst, it tries to parse it as follows:

Finally, when provided a broj, it returns netačno only if the broj is equal to 0. Otherwise, it returns tačno.

var l = logickiOd(tačno);
var t = logickiOd("">netačno");
var b = logickiOd(32);

ispis(b, l, t);
Output:

tačno
netačno
tačno

Trying to parse an invalid tekst or passing a value of any type other than the three supported ones will result in an exception:

var invalidTekst = "netanco";
var t = logickiOd(invalidTekst);
Error: 'netanco' is not a logički.
var invalid = [1,5,2,1];
var l = logickiOd(invalid);
Error: Cannot convert [1,5,2,1] to logički.

Function nizOd

The nizOd function can be used to create a niz in place.

var n = nizOd(1, tačno, "tekst", 66);

ispis(n);
Output:

[1, tačno, "tekst", 66]

Function tip

The tip function is used to determine the type of a particular value. It returns a tekst with the typename:

ispis(tip(1));

ispis(tip("Sample"));

ispis(tip([1,3,5]));

ispis(tip({x: 1, y: 2}));
Output:

broj
tekst
niz
objekat