Add NanoBasic RESET function
This commit is contained in:
parent
7a349f8b49
commit
d451f57a9f
@ -222,7 +222,7 @@ local function renumber_lines(pos, nvm, code)
|
||||
local num = 10
|
||||
for line in code:gmatch("[^\r\n]+") do
|
||||
local s = line:match("^%s*(%d+)")
|
||||
if s and tonumber(s) < 65000 then
|
||||
if s and tonumber(s) < 64000 then
|
||||
lines[#lines + 1] = num .. line:sub(s:len() + 1)
|
||||
new_nums[s] = num
|
||||
num = num + 10
|
||||
@ -645,6 +645,11 @@ register_ext_function("iname$", {nanobasic.NB_STR}, nanobasic.NB_STR, function(p
|
||||
return true
|
||||
end)
|
||||
|
||||
register_ext_function("reset", {}, nanobasic.NB_NONE, function(pos, nvm)
|
||||
nanobasic.reset(pos)
|
||||
return true
|
||||
end)
|
||||
|
||||
--
|
||||
-- Register user input actions: register_action(states, key, function)
|
||||
--
|
||||
@ -701,6 +706,7 @@ register_action({"init", "edit", "stopped"}, "Run", function(pos, nvm, fields)
|
||||
nvm.bttns = {"", "", "", "", "", "Stop", "", ""}
|
||||
nvm.input = ""
|
||||
nvm.variables = nanobasic.get_variable_list(pos)
|
||||
nvm.onload_label_addr = nanobasic.get_label_address(pos, "64000") or 0
|
||||
nvm.error_label_addr = nanobasic.get_label_address(pos, "65000") or 0
|
||||
nvm.ttl = nil
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
@ -820,6 +826,9 @@ techage.register_node({"techage:basic_terminal"}, {
|
||||
nanobasic.vm_restore(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
if nvm.status == "running" then
|
||||
if nvm.onload_label_addr and nvm.onload_label_addr > 0 then
|
||||
nanobasic.set_pc(pos, nvm.onload_label_addr)
|
||||
end
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
end
|
||||
end,
|
||||
|
@ -47,6 +47,7 @@
|
||||
- [MID$](#mid)
|
||||
- [PARAM](#param)
|
||||
- [PARAM$](#param-1)
|
||||
- [RESET](#reset)
|
||||
- [RIGHT$](#right)
|
||||
- [RND](#rnd)
|
||||
- [SERCUR](#sercur)
|
||||
@ -58,6 +59,7 @@
|
||||
- [VAL](#val)
|
||||
- [Techage Functions](#techage-functions)
|
||||
- [Error Handling](#error-handling)
|
||||
- [Mapblock Loading](#mapblock-loading)
|
||||
- [CMD](#cmd)
|
||||
- [CMD$](#cmd-1)
|
||||
- [CHAT](#chat)
|
||||
@ -989,6 +991,18 @@ Example:
|
||||
10 val$ = PARAM$()
|
||||
```
|
||||
|
||||
### RESET
|
||||
|
||||
Format:
|
||||
|
||||
```text
|
||||
RESET()
|
||||
```
|
||||
|
||||
The RESET function is used to reset the program to the first line.
|
||||
The function can be called at any time in the program. But the main use is to
|
||||
restart the program after the mapblock is loaded. See [Mapblock Loading](#mapblock-loading).
|
||||
|
||||
### RIGHT$
|
||||
|
||||
Format:
|
||||
@ -1189,6 +1203,31 @@ and only in the error subroutine.
|
||||
|
||||
After this subroutine is called, the program returns to the `CMD` or `CMD$` function.
|
||||
|
||||
### Mapblock Loading
|
||||
|
||||
When the world around the Techage Terminal is loaded and NanoBasic is active,
|
||||
the program is continued from the line where the program was interrupted.
|
||||
By means of the NanoBasic subroutine starting at line 64000, it is possible to
|
||||
define what should happen when the mapblock is loaded.
|
||||
|
||||
This subroutine can be used to initialize the program and/or initialize connected
|
||||
Techage devices.
|
||||
|
||||
In the easiest case, the on-load subroutine can be defined as follows:
|
||||
|
||||
```text
|
||||
64000 PRINT "Mapblock loaded"
|
||||
64010 RETURN
|
||||
```
|
||||
|
||||
To restart the program from the beginning, call the `RESET` function.
|
||||
The `RESET` function is used to reset the program to the first line.
|
||||
|
||||
```text
|
||||
64000 PRINT "Mapblock loaded"
|
||||
64010 RESET()
|
||||
```
|
||||
|
||||
### CMD
|
||||
|
||||
Format:
|
||||
|
Loading…
Reference in New Issue
Block a user