NOUGAT EXAMPLE MAIN OBJECT SCRIPT
DECLARE PLUGINS: plugin import declarations are not needed when libraries are built-in, as the compiler will prompt to automatically add them, but you can still specify those imports. Alternatively, import can be written as "grab". Global imports can also be saved to an "imports" file in the project's root folder, which will automatically be detected. Imports specific to objects can be specified in a similar way, either from another "imports" file in the object's folder, or directly in the object's code. However, plugins imported directly in the main object's code (root folder) will not be globalized unless they're specified in the imports file.
import {*} from {mediaStage}
import {mediaStage}
grab {https://example.com/nougatplugins/foobar.ngx}
grab {foo:bar}&{isnt:it:var:tho} from {yougetthepoint.com}
alias {mediaStage} as {ms}
to call an alias, use this format: ".myalias"
below is an equivalent to a greenflag on scratch. "when {} {}" is used for system-defined (or "built-in") events, while "on {} {}" is used for user-defined events.
when {run} {
log {Hello world!}
set {my variable} to { world!}
"set (my variable) to { world!}" with () surrounding the variable name will just attempt to create a new variable named after the contents of (my variable), so {} should be used in most cases.
log [join {Hello}(my variable)]
send {hello}
do {world}
once done, we continue:
You can also insert any JavaScript into Nougat mid-sentence:
js {yourJavaScript}
}
define {world} {
log {this is an example of a function.}
How Nougat handles code lines:
set {my variable} to {something}
Nougat ignores the space between {}1 and {}2, which is only used for "micro-commenting". What Nougat sees is the function (set) and the inputs({}{}), which are like positional arguments in python.
ms:setBackground we want to set a plain {color} for it, value will be {#000000}
If you don't want to do that, you can explicitly specify the input's category with "category:{input}", with "category:" and "{" stuck together.
How Nougat handles system/plugin function names:
someClass:someCategory:someFunction
How Nougat handles mathematical operations and conditionals:
<> is used to calculate a logical operation inside it. It does not support micro-commenting.
syntax is as follows:
<{input1}operator{input2}>: <>'s support any type of input around the middle operator (see operators below), be it {}, (), [], or even nesting <>.
operators:
is: Equivalent to "equal". "=" instead of "is" works as well.
isNot: Equivalent to "not equal". "≠" works as well.
approx/approximates: will round the result of things prior to it on runtime and run an "is".
lt/isLessThan: Equivalent to "<". Do NOT actually use "<" or ">" inside "<>" as a means to do these kinds of operations, use "«" or "»" instead.
gt/isGreaterThan: Equivalent to ">".
or: Used to determine if either input is true. Will only work if the inputs return a boolean (true/false).
and: Used to determine if both inputs are true. Will only work if the inputs return a boolean.
contains: Used to determine if string {}1 contains the sequence of characters in string {}2 somewhere.
Additionally, starting <> with "
For example:
log <{9}+{10}>
<{9}+{10}>
<<{9}+{10}> is {21}>
set {number} to {5}
<<(number) isLessThan {8}> and >>
set {myCondition} to <<(number) isLessThan {8}> and >>
How Nougat handles conditions:
if (myCondition) {
log {The condition is true!}
}
For "else", simply do:
if (myCondition) {
log {The condition is true!}
} else {
log {The condition is false!}
}
So, usage of "if" is "if {condition} {action} {else-action}".
Extra conditions (like Scratch):
{myCondition} = {0}
repeatUntil <(myCondition) = 5> {
log {this will continue to be logged until myCondition becomes 5}
set {myCondition} to <(myCondition)+{1}>
}
or if you want to repeat a specific number of times:
log {it goes on}
repeatTimes {5} {
log {and on}
}
"while" works too if you come from a programming language that uses that:
while <[get:time:hour24] lt {8}> {
log {Zzz...}
log {zZz...}
log {zzZ...}
log {i will sleep til 8am}
}
while:stop stops everything that's inside it and breaks the loop once the condition is no longer met, leaving further lines no chance to run.
while:stop <[get:time:hour24] lt {8}> {
log {Zzz...}
log {zZz...}
log {zzZ...}
log {i will sleep til 8am}
once the condition is not true, this thread will stop and not every line will finish running
}
How Nougat handles blocking calls
send {makeIt6}
waitUntil <(myCondition) = {6}>
wait {2}{s}
wait {1}{m}
wait {5}
How to get variables from the system:
plugin:get:varCategory:varName <- the key is adding "get:" after the plugin's name. The plugin spec recommends using the "get" category for this purpose.
For non-plugin system variables, just use get: at the beginning:
get:time:hour24
with this, you can do:
log [join{The time is }[get:time:hour24]{:}[get:time:minute]]
How to create and use a private variable:
set:mine {myPrivateVar} to {And me? I'll take care of \n Mine, mine, mine, mine, mine!}
or:
set {mine: myPrivateVar} to {And me? I'll take care of \n Mine, mine, mine, mine, mine!}
You can reference a private variable with "(mine: yourVariableName)".
log (mine: myPrivateVar)
Private variables can only be used by the active object.
}
on {hello} {
log {this is an example of an event. event calls will also be received by other objects.}
foo:bar:orderFromTheBar
}
on {makeIt6} {
wait {1}{s}
set {myCondition} to {6}
}
from here, everything is just automatically adjusted, corrected (the compiler will try its best), and compiled directly to JavaScript, yipee :D!
With Nougat, you don't need to strictly declare much of anything; the compiler will know what you mean. Just know your a:b's, {}'s, and ()'s, and you should be good to go.