Loops, Ifs, and scopes babey
Neumann » Devlog
The NGS interpreter now supports while loops, if statements, and function-bound variables (RIP the global scope)
the examples for this are somewhere in the default script, ill put the relevant parts here in case its changed later
# Variables are stored in the current scope, meaning that any variable inside a function # will get discarded as soon as the function returns # however, if you assign a new value to a variable you already defined outside of the function, it will overwrite it at that scope and it wont be discarded im_a_string = "they are surrounded by double qoutes"
# if statements are pretty straight forward
# note that they accept only 1 argument, and it must be a boolean
if true {
im_inside_an_ifstat = true
}
# if you do give more than one argument, it will be ignored
if true "hello" {
im_also_inside_an_ifstat = true
}
ill_never_be_true = false
if LOGIC_equals("Hi", "Hello") {
ill_never_be_true = true
}
# Recursion /is/ possible, but is almost always the wrong solution to a problem, and is generally not recommended
# keep in mind that the maximum stack size is currently 1024 items
func countdown(in) {
out = 0
if LOGIC_not(LOGIC_equals(in,0)) {
out = countdown(MATH_sub(in, 1))
}
return out
}
countdown_results = countdown(10)
# a better fit for this would be a while loop
func countdown_2(in) {
out = in
while LOGIC_not(LOGIC_equals(out,0)) {
out = MATH_sub(out,1)
}
return out
}
countdown_2_results = countdown_2(10)Files
Web build Play in browser
Dec 05, 2021
Windows build 35 MB
Dec 05, 2021
Get Neumann
Neumann
Program self-replicating spacecraft and explore the universe!
| Status | On hold |
| Author | (lis)anne |
| Genre | Simulation, Strategy |
| Tags | 2D, Exploration, in-game-scripting, ingame-scripting, programming, Singleplayer, Space, Space Sim |
| Languages | English |
More posts
- Build 9Feb 03, 2022
- We stray a little closer to a working protoypeJan 23, 2022
Leave a comment
Log in with itch.io to leave a comment.