Skip to content

Implement a RESET (STOP+SAVE+RESTART) button #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 39 additions & 20 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -834,10 +834,11 @@ local robot_spawner_update_form = function (pos, mode)
"button_exit[-0.25,-0.25;1.25,1;OK;SAVE]"..
"button_exit[-0.25, 0.75;1.25,1;spawn;START]"..
"button[-0.25, 1.75;1.25,1;despawn;STOP]"..
"field[0.25,3.;1.,1;id;id;"..id.."]"..
"button[-0.25, 3.6;1.25,1;inventory;storage]"..
"button[-0.25, 4.6;1.25,1;library;library]"..
"button[-0.25, 5.6;1.25,1;help;help]";
"button[-0.25, 2.75;1.25,1;reset;RESET]"..
"field[0.25,4.;1.,1;id;id;"..id.."]"..
"button[-0.25, 4.6;1.25,1;inventory;storage]"..
"button[-0.25, 5.6;1.25,1;library;library]"..
"button[-0.25, 6.6;1.25,1;help;help]";

else -- when robot clicked
form =
Expand Down Expand Up @@ -1264,8 +1265,8 @@ local on_receive_robot_form = function(pos, formname, fields, sender)

local name = sender:get_player_name();
if minetest.is_protected(pos,name) then return end
if fields.OK then

local save = function()
local meta = minetest.get_meta(pos);

if fields.code then
Expand Down Expand Up @@ -1296,6 +1297,29 @@ local on_receive_robot_form = function(pos, formname, fields, sender)
end

robot_spawner_update_form(pos);
end

local robotstop = function()
local meta = minetest.get_meta(pos);
local owner = meta:get_string("owner");
local id = meta:get_int("id");
local name = owner..id;

if id<=0 then meta:set_int("codechange",1) end

if not basic_robot.data[name] then return end
if basic_robot.data[name].obj then
basic_robot.data[name].obj:remove();
basic_robot.data[name].obj = nil;
end
end

local robotstart = function()
spawn_robot(pos,0,0);
end

if fields.OK then
save()
return
end

Expand Down Expand Up @@ -1325,26 +1349,21 @@ local on_receive_robot_form = function(pos, formname, fields, sender)
end

if fields.spawn then
spawn_robot(pos,0,0);
robotstart()
return
end

if fields.despawn then

local meta = minetest.get_meta(pos);
local owner = meta:get_string("owner");
local id = meta:get_int("id");
local name = owner..id;

if id<=0 then meta:set_int("codechange",1) end

if not basic_robot.data[name] then return end
if basic_robot.data[name].obj then
basic_robot.data[name].obj:remove();
basic_robot.data[name].obj = nil;
end
robotstop()
return
end

if fields.reset then
save()
robotstop()
robotstart()
return
end

if fields.inventory then
local list_name = "nodemeta:"..pos.x..','..pos.y..','..pos.z ;
Expand Down