[Mod] basic_robot [basic_robot]

User avatar
rnd
Member
 
Posts: 200
Joined: Sun Dec 28, 2014 12:24
IRC: ac_minetest
In-game: rnd

[Mod] basic_robot [basic_robot]

by rnd » Tue Nov 08, 2016 09:48

basic_robot is a lightweight minetest programmable robot for multiplayer. Write programs in lua - robot can move around, sense the blocks and build/dig.

License: LGPL
Dependence: default
Download: https://github.com/ac-minetest/basic_robot/
WIKI http://wiki.minetest.net/Mods/basic_robot by hajo
------------------------------------------------------------------------------------
instructions:
1. place spawner (basic_robot:spawner) and right click it to write program.
To save program click "ok".

2.START to run program, STOP to stop program/remove robot, clear to delete program
Spawner can also be activated with signal ( mesecons mod, basic_machines mod)

3. ingame help: right click spawner and click help button

robot walking along cobble road: robot can only sense nearby nodes and has to decide when to turn
Image

code for pine tree harvesting
Image

There is built in book browser, editor and loader
Robot can write text to standard minetest books in its library, also it can read books and execute code in books

Image
Attachments
robot3.jpg
(74.49 KiB) Not downloaded yet
robot2.jpg
(73.38 KiB) Not downloaded yet
robot1.jpg
(70.1 KiB) Not downloaded yet
Last edited by rnd on Wed Jan 18, 2017 12:49, edited 5 times in total.
 

User avatar
cx384
Member
 
Posts: 484
Joined: Wed Apr 23, 2014 09:38
GitHub: cx384
IRC: cx384
 

User avatar
DS-minetest
Member
 
Posts: 969
Joined: Thu Jun 19, 2014 19:49
Location: in front of my pc (which is at home)
GitHub: DS-Minetest
In-game: DS

Re: [Mod] basic_robot [basic_robot]

by DS-minetest » Tue Nov 08, 2016 14:13

interesting, ill try
Edit: nice!
Do not call me -minetest.
Call me DS or DS-minetest.
I am German, so you don't have to pm me English if you are also German.
The background is a lie.
 

User avatar
rnd
Member
 
Posts: 200
Joined: Sun Dec 28, 2014 12:24
IRC: ac_minetest
In-game: rnd

Re: [Mod] basic_robot [basic_robot]

by rnd » Tue Nov 08, 2016 19:56

this plots a function

Code: Select all
if not x then
   x=0 y = 0 h = 0 state=0
   f =  function(x)
      return (math.sin(x/5*3.14)+1)*0.5*5 end
   end

if state == 0 then -- move up
   y=f(x)
   h=h+1
   if h>y then place.left("default:dirt") state = 1 end
  dig.up();move.up(); place.down("default:glass")
end

if state == 1 then -- move down
   h=h-1
   if h>=0 then
      dig.down() move.down()
   else
      state = 0; move.forward(); h=0; x=x+1;
   end
end
 

hajo
Member
 
Posts: 586
Joined: Thu Oct 13, 2016 10:45
Location: DE

Re: [Mod] basic_robot [basic_robot]

by hajo » Wed Nov 09, 2016 18:00

rnd wrote:basic_robot is a lightweight minetest programmable robot for multiplayer.

When pointing at a robot, It would be nice if a text
like "basic_robot belongs to playerX" would be shown
(instead of "GenericCAO ...").
Giving a name to the bot would be nice and probably easy (*1).
Different colors for the bots of each player would be nice too, or maybe skins.

Could the robot emit light (i.e. like a mese-lamp, or front-only, i.e. headlights) ?

instructions:
place spawner (basic_robot:spawner) and right click it to write program

eg.
Code: Select all
say("Hi")

* press "Reset" to clear the program text
* press "OK"-button to save the program text
* press "Spawn" to create a robot, to execute the program (*2)
(changes to the code are ignored while the bot is running)
* press "Remove" to dismiss the robot.
Only one bot at a time per spawner (*3).

BTW, it would be nice to have a different picture on the front side of the CPU-box.
Also, a different texture for "ready" and "working" (maybe green/red). (*3)

The robot can 'fly' one space away from any solid nodes,
and moves right thru the player (and an RC Car, (and likely mobs too).
No inventory (yet?).
The player can stand on it, but can not ride it (like a boat).
Also, a right-click on the bot does nothing (maybe pause/resume, or tell status?)

It looks like the execution of the program is repeated, about once every second:
Code: Select all
if (i==nil) then say("Hi !"); i=0 end
turn.left()
i = i+1
say(i)

Is there a way to stop/exit a program ?

(*1) Perhaps just a command/setting like 'robotname="Hugo"'.

How about a "personal library", i.e. a book that the player creates,
with a title like "basic_robot lib#1", where the text from that book
would be included into the code for the robot (e.g. with "#include lib#1") ?
So people could have their own code for customizing their bots,
included every time, without much typing/copy/paste.

(*2) So, the buttons "Spawn" and "Remove" would better be placed at the top right,
and "Reset" renamed to "Clear".

(*3) If the spawner is picked up while the bot is running,
and placed again, it shows a form with an empty code-area,
and gives an error "robot already active".

BTW, how could the robot read button-presses on a remote-controller ?
E.g. the controller as a formspec, with some buttons like left/right/forward/action.

(*4) That means, it can build itself into the sky on top of a column, with
Code: Select all
move.up()
place.down("default:dirt")


BTW, it looks funny when the spawn-position is covered in dirt :)
Also how to check for success of an action ?

And it would be nice to have a view from the robot, e.g. in the place of the minimap.

Edit:
When using "find_nodes()", eg.
Code: Select all
f = find_nodes(3,"default:stone_with_coal")

I get an errormessage:
Code: Select all
#ROBOT ERROR: ... init.lua 69: attempt to compare number with string
 

User avatar
rnd
Member
 
Posts: 200
Joined: Sun Dec 28, 2014 12:24
IRC: ac_minetest
In-game: rnd

Re: [Mod] basic_robot [basic_robot]

by rnd » Thu Nov 10, 2016 13:21

updates: bugfixes, has inventory, names ,...

about library: just paste code on sign and then copy it. Might make it be able to read books though, like have 10 books in its book inventory and then you will be able to say which book to run

example code, making robot follow cobble road:
Code: Select all
move.forward()
node = read_node.down();
road = "default:cobble";
if node~=road then
   move.backward()
   move.left();
   if read_node.down()~=road then
      move.right(); move.right();
      if read_node.down()~=road then
         move.left(); turn.angle(180);
      else
         turn.right();
      end
   else
      turn.left();
   end
end


Image
Attachments
follow_road.jpg
(64.41 KiB) Not downloaded yet
 

User avatar
DS-minetest
Member
 
Posts: 969
Joined: Thu Jun 19, 2014 19:49
Location: in front of my pc (which is at home)
GitHub: DS-Minetest
In-game: DS

Re: [Mod] basic_robot [basic_robot]

by DS-minetest » Thu Nov 10, 2016 14:44

some of hajo's suggestions were nice, others werent. for example emitting light would cause much lag

Edit: @rnd: did you notice my PR?
Do not call me -minetest.
Call me DS or DS-minetest.
I am German, so you don't have to pm me English if you are also German.
The background is a lie.
 

hajo
Member
 
Posts: 586
Joined: Thu Oct 13, 2016 10:45
Location: DE

Re: [Mod] basic_robot [basic_robot]

by hajo » Thu Nov 10, 2016 16:23

DS-minetest wrote:some of hajo's suggestions were nice,
others werent. for example emitting light would cause much lag

You think placing a torch on every move would be better ?

BTW, can the robot detect the lightlevel, or the time-of-day ?
Also, his own hitpoints ?
 

User avatar
DS-minetest
Member
 
Posts: 969
Joined: Thu Jun 19, 2014 19:49
Location: in front of my pc (which is at home)
GitHub: DS-Minetest
In-game: DS

Re: [Mod] basic_robot [basic_robot]

by DS-minetest » Thu Nov 10, 2016 16:35

hajo wrote:
DS-minetest wrote:some of hajo's suggestions were nice,
others werent. for example emitting light would cause much lag

You think placing a torch on every move would be better ?

BTW, can the robot detect the lightlevel, or the time-of-day ?
Also, his own hitpoints ?

as much as i know placing a light emitting node (like a torch but invisible) is the only way to make an entity make light

and the robot only detects the name of the node, not more (it would be nice if the "detect_node.direction()" command would return a table, not only the node name)
also, it cant get its own health
Do not call me -minetest.
Call me DS or DS-minetest.
I am German, so you don't have to pm me English if you are also German.
The background is a lie.
 

hajo
Member
 
Posts: 586
Joined: Thu Oct 13, 2016 10:45
Location: DE

Re: [Mod] basic_robot [basic_robot]

by hajo » Thu Nov 10, 2016 17:30

rnd wrote:updates: bugfixes, has inventory, names ,...

That was quick, thanks !

I found some funny effects when placing a torch after every move:
* the torches hang in mid-air
* when collecting one of them, they all go out, and fall down

Also, the robot doesn't notice when it gets punched, and reaches 0 hp.

About bridge-building at an edge, as in
Code: Select all
move.forward()
place.down("default:dirt")

doesn't work, because the bot doesn't hover over empty space.

The player can do this by sneaking to the edge, looking down,
and building a new block at the downward edge of his block.

Perhaps new directions, like "forward-down" and "forward-up" ?

Also, is there a better way to check for success of an action
then to wrap every action into query/action/query/compare ?
 

User avatar
DS-minetest
Member
 
Posts: 969
Joined: Thu Jun 19, 2014 19:49
Location: in front of my pc (which is at home)
GitHub: DS-Minetest
In-game: DS

Re: [Mod] basic_robot [basic_robot]

by DS-minetest » Thu Nov 10, 2016 18:45

hajo wrote:I found some funny effects when placing a torch after every move:
* the torches hang in mid-air
* when collecting one of them, they all go out, and fall down

this was clear, you could also set torches with worldedit, it would have the same effect
when a player places a torch he gives a parameter
when the torch is wallmounted onto no wall and you update it (for example by digging a nearby node) it will drop because it notices that theres no wall
Do not call me -minetest.
Call me DS or DS-minetest.
I am German, so you don't have to pm me English if you are also German.
The background is a lie.
 

hajo
Member
 
Posts: 586
Joined: Thu Oct 13, 2016 10:45
Location: DE

Re: [Mod] basic_robot [basic_robot]

by hajo » Thu Nov 10, 2016 20:35

I was writing a program like
Code: Select all
function work( n )
  ok=0
--for i=1,n do
  i=1
    say("work:"..i)
    dig.forward()
    move.forward()
--end
  return ok
end

if done==nil then
  turn.left()
  say("Working...")
  work(3)
  say("Done.")
  done=1
end

but "for", "while" etc. are not allowed (not even in comments).

There is a check in init.lua:
Code: Select all
local function check_code(code)
  local bad_code = {"while ", "for ", "do ", "repeat ", "until ", "goto "}
...

What's wrong with these commands ?
 

User avatar
rnd
Member
 
Posts: 200
Joined: Sun Dec 28, 2014 12:24
IRC: ac_minetest
In-game: rnd

Re: [Mod] basic_robot [basic_robot]

by rnd » Thu Nov 10, 2016 20:57

Also, is there a better way to check for success of an action
then to wrap every action into query/action/query/compare ?


now move.. returns true if it can move or false if it cant ( going over edge for example)
so you can do do stuff like

Code: Select all
if not move.forward() then say("im stuck") end


What's wrong with these commands ?


Code: Select all
for i=1,999999999999999999999999999999999 do ... end


Code: Select all
while true do ... end


Code: Select all
a: .... goto b
b: goto a


....
Whats wrong is your server will freeze after 5 minutes of multiplayer... welcome to real world ;)

you could replace for i = 1, 10 loop with something like

Code: Select all
if not state then state = 1 i=1 end

if state==1 and i<10 then do STUFF else state = 2 end
i=i+1


it will take a bit longer to run but its safe
 

Byakuren
Member
 
Posts: 768
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

Re: [Mod] basic_robot [basic_robot]

by Byakuren » Fri Nov 11, 2016 07:07

Don't forget
Code: Select all
local function blah()
  blah()
end
Every time a mod API is left undocumented, a koala dies.
 

User avatar
rnd
Member
 
Posts: 200
Joined: Sun Dec 28, 2014 12:24
IRC: ac_minetest
In-game: rnd

Re: [Mod] basic_robot [basic_robot]

by rnd » Fri Nov 11, 2016 07:16

Byakuren great ;) ... and this seems undetectable since you can further hide it by
Code: Select all
a = function() say(1) b() end
b = function() a() end
a()


1. would be nice if there was option in pcall to terminate execution after specified time to prevent wasting time with this bs..

Btw i know about debug.sethook which can be used to call other functions when stuff like function calls happen so i set it inside pcall to raise an error with error(), which should be intercepted by pcall.. but what happened it escaped outer pcall and caused minetest crash..
Code: Select all
setfenv( ScriptFunc, basic_robot.data[name].sandbox )
 pcall(
function()
   debug.sethook(error,"l")  -- raises error when next line is called
   local Result, RuntimeError = pcall( ScriptFunc )
   if RuntimeError then
      return RuntimeError
   end
   debug.sethook(); -- clears hook
end)


but this works and it catches error :

Code: Select all
pcall(
        function()
      error()
       end)
)

EDIT: just tried the above bad code, it froze server for 8 seconds and then it resumed without further problems.. and it gives easy checkable error "stack overflow".. so i guess we just remove the robot and offenders interact privs and call it a day ;)

Image

It seems default stack size is 20, and there doesnt seem to be option to decrease that
Attachments
stack_overflow.jpg
(66.21 KiB) Not downloaded yet
Last edited by rnd on Fri Nov 11, 2016 09:48, edited 3 times in total.
 

Byakuren
Member
 
Posts: 768
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

Re: [Mod] basic_robot [basic_robot]

by Byakuren » Fri Nov 11, 2016 09:32

You can also do
Code: Select all
local function blah()
  return blah()
end

which shouldn't overflow because of TCO.
Every time a mod API is left undocumented, a koala dies.
 

User avatar
rnd
Member
 
Posts: 200
Joined: Sun Dec 28, 2014 12:24
IRC: ac_minetest
In-game: rnd

Re: [Mod] basic_robot [basic_robot]

by rnd » Fri Nov 11, 2016 09:45

right, this is harmful:

Code: Select all
say(1)
local function blah()
  return blah()
end
blah()
say(2)


One way to prevent this would be set up hook to count how many lines are executed and then throw error when exceeded. Tried that
Code: Select all
pcall(
   function()
      debug.sethook(error,"l")  -- raises error when next line is called
      
      local Result, RuntimeError = pcall( ScriptFunc )
      if RuntimeError then
         return RuntimeError
      end
   end)

but for some reasons error isnt caught by pcalls, this is what happens:

Code: Select all
terminate called after throwing an instance of 'LuaError'
  what():  Runtime error from mod 'basic_robot' in callback on_shutdown(): line
stack traceback:
        [C]: in function '__index'
        ...\rpg\minetest0414server\bin\..\builtin\game\register.lua:350: in function <...\rpg\minetest0414server\bin\..\builtin\game\register.lua:349>
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.


I tried raising error inside another pcall and even tried raising error inside script in sandbox but in both cases pcall didnt catch error and it crashed minetest.

learned something new: "Tail call optimization" ..
so if you call same function as last instruction you dont need to add new stack level, just pass the arguments and continue execution:

f = function(arg) do_stuff f(arg1) end
Last edited by rnd on Fri Nov 11, 2016 10:20, edited 5 times in total.
 

Byakuren
Member
 
Posts: 768
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

Re: [Mod] basic_robot [basic_robot]

by Byakuren » Fri Nov 11, 2016 10:03

rnd wrote:was this supposed to be harmful, cause it does absolutely nothing, no problems whatsoever:

Code: Select all
say(1)
local function blah()
  return blah()
end
say(2)


can you look at sethook in previous post, i tried raising error inside another pcall and even tried raising error inside script in sandbox but in both cases pcall didnt catch error and it crashed minetest.

Code: Select all
local function blah()
  return blah()
end
blah()

I assumed you would see to call it, since you did in your previous post (with a).
Every time a mod API is left undocumented, a koala dies.
 

hajo
Member
 
Posts: 586
Joined: Thu Oct 13, 2016 10:45
Location: DE

Re: [Mod] basic_robot [basic_robot]

by hajo » Fri Nov 11, 2016 11:20

rnd wrote:
hajo wrote:What's wrong with these commands ?

Code: Select all
for i=1,999999999999999999999999999999999 do ... end

Code: Select all
while true do ... end

Perfectly valid, just needs a break (or timeslicing, or priority,
or preemptive scheduling, or bots using energy, etc.)
Code: Select all
a: .... goto b
b: goto a

only allow forward-goto, such as "goto done", "goto errorAbort".

Whats wrong is your server will freeze after 5 minutes of multiplayer... welcome to real world ;)

Sorry for trying to do useful stuff, as opposed to
grief/exploit/wasting other people's resources :)

you could replace for i = 1, 10 loop with something

I'm aware there are several possible workarounds.

But the premise was to use such bots as an introduction to programming,
for teaching, and a fun way to get kids interested in programming.
(Also, well structured code, readable, etc. etc.)
With half the control-structures disabled, this will get hard...

I agree that addressing inefficent code/abuse etc. is important,
but maybe as a 2nd course (after everyone has seen how bad it is).
Ok, on a secured, walled-off server...

So, I would go for monitoring, reporting ("robot x crashed ..."),
and maybe disabling bots, as opposed to preventing every abuse.

There is a game trAInsported with competing bots as AI-trains,
that also uses lua as scripting language, and these bots also
get sandboxed and limited execution-time (or line-count).
Last edited by hajo on Fri Nov 11, 2016 16:24, edited 1 time in total.
 

User avatar
rnd
Member
 
Posts: 200
Joined: Sun Dec 28, 2014 12:24
IRC: ac_minetest
In-game: rnd

Re: [Mod] basic_robot [basic_robot]

by rnd » Fri Nov 11, 2016 12:42

now it is possible to safely use for, while, goto and even define functions recursively. I added preprocessing to script which inserts counting function to critical spots and throws error when exceeded. default value is

basic_robot.call_limit = 32

Here is what happens if you make mistake in while loop condition, causing infinite loop
Image

example with infinite recursion (even tail recursion), function calling itself too much
Image
Attachments
infinite_recursion.jpg
(36.8 KiB) Not downloaded yet
while_loop.jpg
(41.2 KiB) Not downloaded yet
 

hajo
Member
 
Posts: 586
Joined: Thu Oct 13, 2016 10:45
Location: DE

Re: [Mod] basic_robot [basic_robot]

by hajo » Fri Nov 11, 2016 14:30

Yesterday, I ran into some bugs and crashes with basic_robot, involving
weird behaviour after syntax-errors were found when pressing "Start".

E.g. after correcting the typo / missing "end" / whatever, and pressing "Start"
to try again, it says "robot already active" (but model is not visible).

Another bug was when pressing "Stop", the robot didn't get removed,
it didn't react to punching, and the game crashed when rightclicking it.

Logfile:
Code: Select all
2016-11-10 21:39:10: ACTION[Server]: singleplayer right-clicks object 2: LuaEntitySAO at (69,7,26)
2016-11-10 21:39:10: ERROR[Main]: ServerError: Lua: Runtime error from mod 'basic_robot' in callback luaentity_Rightclick(): Invalid position (expected table got string).
2016-11-10 21:39:10: ERROR[Main]: stack traceback:
2016-11-10 21:39:10: ERROR[Main]:    [C]: in function 'get_meta'
2016-11-10 21:39:10: ERROR[Main]:    E:\temp\minetest-0.4.14\bin\..\mods\basic_robot\init.lua:194: in function 'robot_spawner_update_form'
2016-11-10 21:39:10: ERROR[Main]:    E:\temp\minetest-0.4.14\bin\..\mods\basic_robot\init.lua:316: in function <E:\temp\minetest-0.4.14\bin\..\mods\basic_robot\init.lua:314>
--crash--


BTW, the form that appears when rightclicking the robot (as opposed to the spawner) does nothing yet.

Also, it might help to make an "ACTION"-entry into the logfile when a robot is spawned/stopped.
Last edited by hajo on Sat Nov 12, 2016 02:56, edited 1 time in total.
 

Byakuren
Member
 
Posts: 768
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

Re: [Mod] basic_robot [basic_robot]

by Byakuren » Fri Nov 11, 2016 18:35

rnd wrote:right, this is harmful:

Code: Select all
say(1)
local function blah()
  return blah()
end
blah()
say(2)


One way to prevent this would be set up hook to count how many lines are executed and then throw error when exceeded. Tried that
Code: Select all
pcall(
   function()
      debug.sethook(error,"l")  -- raises error when next line is called
      
      local Result, RuntimeError = pcall( ScriptFunc )
      if RuntimeError then
         return RuntimeError
      end
   end)

but for some reasons error isnt caught by pcalls, this is what happens:

Code: Select all
terminate called after throwing an instance of 'LuaError'
  what():  Runtime error from mod 'basic_robot' in callback on_shutdown(): line
stack traceback:
        [C]: in function '__index'
        ...\rpg\minetest0414server\bin\..\builtin\game\register.lua:350: in function <...\rpg\minetest0414server\bin\..\builtin\game\register.lua:349>
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.


I tried raising error inside another pcall and even tried raising error inside script in sandbox but in both cases pcall didnt catch error and it crashed minetest.

learned something new: "Tail call optimization" ..
so if you call same function as last instruction you dont need to add new stack level, just pass the arguments and continue execution:

f = function(arg) do_stuff f(arg1) end

Nice edit, next time could you reply normally so you don't make me look like a dummy? You could also have explicitly mentioned that you edited your post, and preserved the original content somewhere in it.

EDIT: Thanks for the info about sethook though, it looks like it could be used with coroutines to implement preemptive scheduling. Only issue then would be how to limit the memory consumption of a thread.
Every time a mod API is left undocumented, a koala dies.
 

User avatar
rnd
Member
 
Posts: 200
Joined: Sun Dec 28, 2014 12:24
IRC: ac_minetest
In-game: rnd

Re: [Mod] basic_robot [basic_robot]

by rnd » Sat Nov 12, 2016 11:18

update: fixes, can sense players around, new direction forward_down for place and read_node..

Examples:
explorer/tree harvester robot:

This will walk around, climb stairs .. It never gives up, if there is a way it will find it eventually.
When it finds pine tree it will harvest it all - if it cant reach top it will place leaves below itself so it can climb up to top of tree, after its done it digs itself back down to floor and continues exploration

Code: Select all
-- ADVANCED tree harvester/explorer
tree = "default:pine_tree";
leaves = "default:pine_needles";

if read_node.up() == tree then -- dig up
   dig.up();
   move.up();
   place.down(leaves)
else -- go down if can
   node = read_node.down()
   if node == leaves or node == tree then
      dig.down(); move.down()
   elseif node == "air" then
      move.down()
   else -- walk around
      node = read_node.forward();
      if node == tree then
         dig.forward()
      elseif node~="air" then
         move.up()
      end
      if not move.forward() then
         if math.random(2)==1 then
            turn.left()
         else
            turn.right()
         end
      end
   end
end


Greeting robot with memory - it says hi and doesnt spam
Image
Attachments
greeter_robot_with_memory.jpg
(66.48 KiB) Not downloaded yet
 

hajo
Member
 
Posts: 586
Joined: Thu Oct 13, 2016 10:45
Location: DE

Re: [Mod] basic_robot [basic_robot]

by hajo » Sat Nov 12, 2016 16:49

From the department of stupid tricks
Code: Select all
dig.down()
move.down()

will destory the spawner, then spam errormessages like
Code: Select all
2016-11-12 20:39:45: WARNING[Main]: Map::getNodeMetadata(): Block not found
2016-11-12 20:39:45: WARNING[Main]: GUIFormSpecMenu::drawList(): The inventory location "nodemeta:109,16,47" doesn't exist


Also, if the robot discovers a cave by digging down,
it will continue to hang in midair.
Same effect if the player digs away all his supporting blocks.
Last edited by hajo on Sat Nov 12, 2016 20:03, edited 2 times in total.
 

Byakuren
Member
 
Posts: 768
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

Re: [Mod] basic_robot [basic_robot]

by Byakuren » Sat Nov 12, 2016 17:47

Code: Select all
while (function() while false do end return true end)() do
  -- spin
end


I would suggest just using sethook to set up a count hook. It will run much faster than inserting function calls everywhere, and is guaranteed to eventually fire if it doesn't run out. Mesecons does this, you could look at that code. If you put the code in a coroutine, you can even make the sethook specific to the thread, then you don't have to much with the main thread hooks.
Every time a mod API is left undocumented, a koala dies.
 

Next

Return to WIP Mods



Who is online

Users browsing this forum: No registered users and 4 guests