[Mod] Visual Bots [1.2] [vbots]

User avatar
Nigel
Member
 
Posts: 13
Joined: Fri May 03, 2019 09:08
GitHub: nyje
IRC: Nigel
In-game: Nigel

[Mod] Visual Bots [1.2] [vbots]

by Nigel » Fri Aug 09, 2019 08:57

Visual Bots
Visually programmable turtle bots for minetest
(c) 2019 Nigel Garnett

Image

Vbots are single block "turtle" style bots, programmable in an entirely visual way.
They came into existence to amuse my 5 year old daughters, and teach them the basics of computer programming, without too much writing.

Instructions available here...

Code: MIT, textures: CC BY-SA 3.0 Unported

Mod dependencies: none

Download v1.2:
vbots_v1.2.zip
(120.13 KiB) Downloaded 2 times

Download v1.1:
vbots1.1_stable.zip
(118.74 KiB) Downloaded 5 times

Download v1.0: vbots1.0_stable.zip
Source: Github
Attachments
2019-08-09-005554_800x600_scrot.png
vbot screenshot
(400.79 KiB) Not downloaded yet
Last edited by Nigel on Wed Aug 14, 2019 10:41, edited 6 times in total.
 

User avatar
rubenwardy
Moderator
 
Posts: 5751
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: [mod] Vbots [1.0] [visual-bots]

by rubenwardy » Fri Aug 09, 2019 09:08

Please note that "visual-bots" isn't a valid mod name. It looks like the title should be: [Mod] Visual Bots [1.0] [vbots]
 

User avatar
Nigel
Member
 
Posts: 13
Joined: Fri May 03, 2019 09:08
GitHub: nyje
IRC: Nigel
In-game: Nigel
 

User avatar
runs
Member
 
Posts: 644
Joined: Sat Oct 27, 2018 08:32
GitHub: runsy

Re: [Mod] Visual Bots [1.0] [vbots]

by runs » Fri Aug 09, 2019 09:49

Oh, cool, to learn programming. It remains me the LOGO turtle.
 

Yvanhoe
Member
 
Posts: 62
Joined: Fri Jul 05, 2019 03:18
 

User avatar
Nigel
Member
 
Posts: 13
Joined: Fri May 03, 2019 09:08
GitHub: nyje
IRC: Nigel
In-game: Nigel

Re: [Mod] Visual Bots [1.0] [vbots]

by Nigel » Fri Aug 09, 2019 10:47

@runs:
Yeah, i wanted simple LOGO style bots they can control & program themselves.

@Yvanhoe
You are welcome.
 

User avatar
DS-minetest
Member
 
Posts: 1102
Joined: Thu Jun 19, 2014 19:49
Location: I'm scared that if this is too exact, I will be unable to use my keyboard.
GitHub: DS-Minetest
In-game: DS

Re: [Mod] Visual Bots [1.0] [vbots]

by DS-minetest » Fri Aug 09, 2019 12:41

Tested.
I like it!

(There are some little bugs that can be probably fixed easily, like that you can take out the instruction items into your inventory.)

(Some things needed for complex things like conditional jumping (eg. if the node in front is stone, run the horse code) or memory would be useful.)
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
Nigel
Member
 
Posts: 13
Joined: Fri May 03, 2019 09:08
GitHub: nyje
IRC: Nigel
In-game: Nigel

Re: [Mod] Visual Bots [1.0] [vbots]

by Nigel » Fri Aug 09, 2019 13:06

Thanks for testing 8-)

I agree. the instruction items are harmless, so I'm not worried about them right now ;-), but on the next cleanup, the whole 'subprogram' inventory needs a rework.

Indeed, a conditional jump is next on the to-do list, as that will make the language 'Turing complete' allowing basically any behavior to be made ;-)

First up however is a code cleanup 8o)
 

DoyleChris
Member
 
Posts: 245
Joined: Sat Jul 25, 2015 19:54
In-game: DoyleChris

Re: [Mod] Visual Bots [1.0] [vbots]

by DoyleChris » Fri Aug 09, 2019 20:17

I will be testing this out on my server with my 7 year old. He plays a game on the table, to guide a person through a maze. This will add some more interaction for my son. Also i will be testing it out heavily to find problems, but first glance it runs good.
 

User avatar
Nigel
Member
 
Posts: 13
Joined: Fri May 03, 2019 09:08
GitHub: nyje
IRC: Nigel
In-game: Nigel

Re: [Mod] Visual Bots [1.0] [vbots]

by Nigel » Sat Aug 10, 2019 10:22

Thanks for testing. BTW I answered the issue you opened on github. more info is needed if these were not the case.
 

DoyleChris
Member
 
Posts: 245
Joined: Sat Jul 25, 2015 19:54
In-game: DoyleChris
 

User avatar
Nigel
Member
 
Posts: 13
Joined: Fri May 03, 2019 09:08
GitHub: nyje
IRC: Nigel
In-game: Nigel

Re: [Mod] Visual Bots [1.0] [vbots]

by Nigel » Sat Aug 10, 2019 18:43

There is a stop button, as it says in the instructions:
Punch a running vbot with an empty hand to stop the program.


You could help yourself a lot if you read the instructions for the mod.

Instructions are available here.

also you can fully reset by digging the bot & placing another, however I think I'll add a button to remove all the programs, I agree it would be handy. Thanks for the idea.

Have fun ;-)
 

User avatar
Nigel
Member
 
Posts: 13
Joined: Fri May 03, 2019 09:08
GitHub: nyje
IRC: Nigel
In-game: Nigel

Re: [Mod] Visual Bots [1.1] [vbots]

by Nigel » Sun Aug 11, 2019 16:13

There we go, updated to v1.1 with a new button to reset all the current programs to empty. Thanks to DoyleChris for the idea.

Enjoy...
 

CalebJ
Member
 
Posts: 141
Joined: Sat Dec 29, 2018 19:21
Location: Tunnelers' Abyss
In-game: CalebJ

Re: [Mod] Visual Bots [1.1] [vbots]

by CalebJ » Mon Aug 12, 2019 01:39

Wow, reminds me of the simplicity of Scratch ;) Great mod!
If you want realism, you're in the wrong place. Get off your mobile.
 

DoyleChris
Member
 
Posts: 245
Joined: Sat Jul 25, 2015 19:54
In-game: DoyleChris

Re: [Mod] Visual Bots [1.1] [vbots]

by DoyleChris » Tue Aug 13, 2019 22:06

I received this error when i went to rename one of the saved files.

Code: Select all
2019-08-13 18:03:22: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'vbots' in callback on_playerReceiveFields(): ...GB/minetest/bin/../mods/visual-bots/formspec_handler.lua:157: attempt to index local 'bot_data' (a nil value)
2019-08-13 18:03:22: ERROR[Main]: stack traceback:
2019-08-13 18:03:22: ERROR[Main]:       ...GB/minetest/bin/../mods/visual-bots/formspec_handler.lua:157: in function <...GB/minetest/bin/../mods/visual-bots/formspec_handler.lua:13>
2019-08-13 18:03:22: ERROR[Main]:       /mnt/700GB/minetest/bin/../builtin/game/register.lua:419: in function </mnt/700GB/minetest/bin/../builtin/game/register.lua:399>


The reset switch works well thank you.
Another idea if possible be able to rename bot.
 

User avatar
Nigel
Member
 
Posts: 13
Joined: Fri May 03, 2019 09:08
GitHub: nyje
IRC: Nigel
In-game: Nigel

Re: [Mod] Visual Bots [1.2] [vbots]

by Nigel » Wed Aug 14, 2019 10:42

I've never seen that error, and can't seem to reproduce it. I can see what the problem is, but am baffled as to how the situation came to be.

Still, I've updated the code in a way which should stop the situation happening.

Enjoy.
 

neoh4x0r
Member
 
Posts: 56
Joined: Wed Aug 29, 2018 20:16
GitHub: neoh4x0r

Re: [Mod] Visual Bots [1.2] [vbots]

by neoh4x0r » Wed Aug 14, 2019 21:19

DoyleChris wrote:I received this error when i went to rename one of the saved files.

Code: Select all
2019-08-13 18:03:22: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'vbots' in callback on_playerReceiveFields(): ...GB/minetest/bin/../mods/visual-bots/formspec_handler.lua:157: attempt to index local 'bot_data' (a nil value)
2019-08-13 18:03:22: ERROR[Main]: stack traceback:
2019-08-13 18:03:22: ERROR[Main]:       ...GB/minetest/bin/../mods/visual-bots/formspec_handler.lua:157: in function <...GB/minetest/bin/../mods/visual-bots/formspec_handler.lua:13>
2019-08-13 18:03:22: ERROR[Main]:       /mnt/700GB/minetest/bin/../builtin/game/register.lua:419: in function </mnt/700GB/minetest/bin/../builtin/game/register.lua:399>


The reset switch works well thank you.
Another idea if possible be able to rename bot.


Nigel wrote:I've never seen that error, and can't seem to reproduce it. I can see what the problem is, but am baffled as to how the situation came to be.

Still, I've updated the code in a way which should stop the situation happening.

Enjoy.


I'm not sure, but it might be due to bot_rekey() setting the bot_key to nil and creating an
inconsistency when register_on_player_receive_fields is called.

EG: when form_parts[2] is used to get the bot_data, was for the formspec updated to reference new_key ?

If the bot_key referenced the old key then it would definitely make bot_data nil, since it does not exist.

It is also possible that bot_key contained no commas which would make form_parts[2] nil, which would result in the same as above -- bot_data is nil.

Also, when acquring bot_data, and it is nil, it might be a good idea to print/log and error that the reference bot_key could not be located.

https://github.com/nyje/visual-bots/blo ... andler.lua

Code: Select all
-------------------------------------
-- generate new key & move data in table
-------------------------------------
local function bot_rekey(bot_key,meta)
    local new_key = vbots.get_key()
    vbots.bot_info[new_key] = vbots.bot_info[bot_key]
    vbots.bot_info[bot_key] = nil
    meta:set_string("key", new_key)
    return new_key
end

line 78: local form_parts = string.split(bot_key,",")
-- updated to this to ensure that bot_key contains a comma before
-- attempting to split, still need to check the length of form_parts
local form_parts = { bot_key }
if string.match(form_parts, ",") then
 form_parts = string.split(bot_key,",")
end

-- no check that form_parts[2] is not nil or an empty string, need to check the length before using it

if form_parts[2] == nil or  form_parts[2] == "" then
 -- log message
 return
end

if table.getn(form_parts) < 2 then
 -- log message
 return
end
line 156: local bot_data = vbots.bot_info[form_parts[2]]
     line 156.5: if bot_data == nil then print("Could not find bot_key ['" .. bot_key .. "']") return end
line 157: local pos=bot_data.pos
 

User avatar
Nigel
Member
 
Posts: 13
Joined: Fri May 03, 2019 09:08
GitHub: nyje
IRC: Nigel
In-game: Nigel

Re: [Mod] Visual Bots [1.2] [vbots]

by Nigel » Thu Aug 15, 2019 14:22

Thanks for looking into that, but as I stated I already fixed the way the issue could occur.

After a server restart, the bot data does not exist. The key is retrieved from the node metadata when opening a formspec, but I missed a couple of cases.

bot_rekey() does not set bot_key to nil, and bot_key is local to that function anyway (function parameters only have local scope).
bot_rekey() moves the local copy of the bot_info record to the new key, then removes the old bot_info record (if it existed).

As regards form_parts, there is no need to check for "," characters in in the source string.
If the string does not contain a "," then #form_parts ~= 2, this is checked for in each "if" clause below it.

All of this part of the code is going to be refactored in a coming update, since it is a horrible mess, and I need to add some more functionality.

Also table.getn() should not be used in lua 5.1+,(it is depreciated) the length operator "#" should be used (which it is in the code)

The issue of no bot_info record for that particular key when opening the reload/delete formspecs was overcome by explicitly calling bot_restore() when creating the formspecs in init.lua


Anyway thanks for showing an interest and making me think ;-)
 


Return to WIP Mods



Who is online

Users browsing this forum: No registered users and 2 guests