bugfixes: preprocess_script, directions
parent
8712bb0e60
commit
532a017be7
28
commands.lua
28
commands.lua
|
@ -22,39 +22,39 @@ local function pos_in_dir(obj, dir) -- position after we move in specified direc
|
||||||
local pos = obj:getpos();
|
local pos = obj:getpos();
|
||||||
|
|
||||||
if dir == 1 then -- left
|
if dir == 1 then -- left
|
||||||
yaw = yaw - pi/2;
|
|
||||||
elseif dir == 2 then --right
|
|
||||||
yaw = yaw + pi/2;
|
yaw = yaw + pi/2;
|
||||||
|
elseif dir == 2 then --right
|
||||||
|
yaw = yaw - pi/2;
|
||||||
elseif dir == 3 then -- forward
|
elseif dir == 3 then -- forward
|
||||||
yaw = yaw+pi;
|
|
||||||
elseif dir == 4 then -- backward
|
elseif dir == 4 then -- backward
|
||||||
|
yaw = yaw+pi;
|
||||||
elseif dir == 5 then -- up
|
elseif dir == 5 then -- up
|
||||||
pos.y=pos.y+1
|
pos.y=pos.y+1
|
||||||
elseif dir == 6 then -- down
|
elseif dir == 6 then -- down
|
||||||
pos.y=pos.y-1
|
pos.y=pos.y-1
|
||||||
|
|
||||||
elseif dir == 7 then -- left_down
|
elseif dir == 7 then -- left_down
|
||||||
yaw = yaw - pi/2;pos.y=pos.y-1
|
|
||||||
elseif dir == 8 then -- right_down
|
|
||||||
yaw = yaw + pi/2;pos.y=pos.y-1
|
yaw = yaw + pi/2;pos.y=pos.y-1
|
||||||
|
elseif dir == 8 then -- right_down
|
||||||
|
yaw = yaw - pi/2;pos.y=pos.y-1
|
||||||
elseif dir == 10 then -- forward_down
|
elseif dir == 10 then -- forward_down
|
||||||
yaw = yaw + pi;pos.y=pos.y-1
|
|
||||||
elseif dir == 9 then -- backward_down
|
|
||||||
pos.y=pos.y-1
|
pos.y=pos.y-1
|
||||||
|
elseif dir == 9 then -- backward_down
|
||||||
|
yaw = yaw + pi;pos.y=pos.y-1
|
||||||
|
|
||||||
elseif dir == 11 then -- left_up
|
elseif dir == 11 then -- left_up
|
||||||
yaw = yaw - pi/2;pos.y=pos.y+1
|
|
||||||
elseif dir == 12 then -- right_up
|
|
||||||
yaw = yaw + pi/2;pos.y=pos.y+1
|
yaw = yaw + pi/2;pos.y=pos.y+1
|
||||||
|
elseif dir == 12 then -- right_up
|
||||||
|
yaw = yaw - pi/2;pos.y=pos.y+1
|
||||||
elseif dir == 14 then -- forward_up
|
elseif dir == 14 then -- forward_up
|
||||||
pos.y=pos.y+1;yaw = yaw + pi;
|
|
||||||
elseif dir == 13 then -- backward_up
|
|
||||||
pos.y=pos.y+1
|
pos.y=pos.y+1
|
||||||
|
elseif dir == 13 then -- backward_up
|
||||||
|
yaw = yaw + pi;pos.y=pos.y+1
|
||||||
end
|
end
|
||||||
|
|
||||||
if dir ~= 5 and dir ~= 6 then
|
if dir ~= 5 and dir ~= 6 then
|
||||||
pos.x = pos.x+math.sin(yaw)
|
pos.x = pos.x - math.sin(yaw) -- math.cos(yaw+pi/2)
|
||||||
pos.z = pos.z+math.cos(yaw)
|
pos.z = pos.z + math.cos(yaw) -- math.sin(yaw+pi/2)
|
||||||
end
|
end
|
||||||
|
|
||||||
return pos
|
return pos
|
||||||
|
@ -92,7 +92,7 @@ basic_robot.commands.move = function(name,dir)
|
||||||
|
|
||||||
obj:moveto(pos, true)
|
obj:moveto(pos, true)
|
||||||
|
|
||||||
-- sit and stand up for model - doenst work for overwriten obj export
|
-- sit and stand up for model - doesnt work for overwriten obj export
|
||||||
-- if dir == 5 then-- up
|
-- if dir == 5 then-- up
|
||||||
-- obj:set_animation({x=0,y=0})
|
-- obj:set_animation({x=0,y=0})
|
||||||
-- elseif dir == 6 then -- down
|
-- elseif dir == 6 then -- down
|
||||||
|
|
12
init.lua
12
init.lua
|
@ -656,6 +656,8 @@ end
|
||||||
|
|
||||||
-- COMPILATION
|
-- COMPILATION
|
||||||
|
|
||||||
|
--todo: 2018/12 this suddenly stopped working, wtf??
|
||||||
|
|
||||||
preprocess_code = function(script) -- version 07/24/2018
|
preprocess_code = function(script) -- version 07/24/2018
|
||||||
|
|
||||||
--[[ idea: in each local a = function (args) ... end insert counter like:
|
--[[ idea: in each local a = function (args) ... end insert counter like:
|
||||||
|
@ -674,17 +676,18 @@ preprocess_code = function(script) -- version 07/24/2018
|
||||||
local found = true;
|
local found = true;
|
||||||
|
|
||||||
local strings = identify_strings(script);
|
local strings = identify_strings(script);
|
||||||
|
|
||||||
local inserts = {};
|
local inserts = {};
|
||||||
|
|
||||||
local constructs = {
|
local constructs = {
|
||||||
{"while%s", "%sdo%s", 2, 6}, -- numbers: insertion pos = i2+2, after skip to i1 = i12+6
|
{"while%s", "%sdo%s", 2, 6}, -- numbers: insertion pos = i2+2, after skip to i1 = i12+6
|
||||||
{"function", ")", 0, 0},
|
{"function", ")", 0, 8},
|
||||||
{"for%s", "%sdo%s", 2, 0},
|
{"for%s", "%sdo%s", 2, 4},
|
||||||
{"goto%s", nil , -1, 5},
|
{"goto%s", nil , -1, 5},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i = 1,#constructs do
|
for i = 1,#constructs do
|
||||||
i1 = 0
|
i1 = 0; found = true
|
||||||
while (found) do -- PROCESS SCRIPT AND INSERT COUNTER AT PROBLEMATIC SPOTS
|
while (found) do -- PROCESS SCRIPT AND INSERT COUNTER AT PROBLEMATIC SPOTS
|
||||||
|
|
||||||
found = false;
|
found = false;
|
||||||
|
@ -709,7 +712,6 @@ preprocess_code = function(script) -- version 07/24/2018
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
table.sort(inserts)
|
table.sort(inserts)
|
||||||
|
@ -724,7 +726,6 @@ preprocess_code = function(script) -- version 07/24/2018
|
||||||
ret[#ret+1] = string.sub(script,i1);
|
ret[#ret+1] = string.sub(script,i1);
|
||||||
|
|
||||||
script = table.concat(ret,_increase_ccounter)
|
script = table.concat(ret,_increase_ccounter)
|
||||||
|
|
||||||
return script:gsub("pause%(%)", "_c_ = 0; pause()") -- reset ccounter at pause
|
return script:gsub("pause%(%)", "_c_ = 0; pause()") -- reset ccounter at pause
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -754,6 +755,7 @@ local function setCode( name, script ) -- to run script: 1. initSandbox 2. setCo
|
||||||
end
|
end
|
||||||
if err then return err end
|
if err then return err end
|
||||||
|
|
||||||
|
|
||||||
local bytecode, err = CompileCode ( script );
|
local bytecode, err = CompileCode ( script );
|
||||||
if err then return err end
|
if err then return err end
|
||||||
basic_robot.data[name].bytecode = bytecode;
|
basic_robot.data[name].bytecode = bytecode;
|
||||||
|
|
Loading…
Reference in New Issue