Scripting Interface Like Raspberry Pi Python?

Post Reply
davegoopot
Member
Posts: 15
Joined: Sat Apr 06, 2013 08:43
GitHub: davegoopot

Scripting Interface Like Raspberry Pi Python?

by davegoopot » Post

Hi,

I run a local code club and due to the recent Bukkit/Minecraft/Microsoft malarkey we're going to have a go with Minetest. We had extensively used the python API to Minecraft ([1] and [2]) to allow kids to write python code that would change a running world. Is there anything equivalent in Minetest? The user experience I'm thinking about is that child 1 is playing in game while child 2 can run some code against the world, sending chat messages, setting blocks, etc.

Any advice greatly appreciated.

Dave.

[1] https://mcpipy.wordpress.com/about/
[2] http://dev.bukkit.org/bukkit-plugins/raspberryjuice/

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

Re: Scripting Interface Like Raspberry Pi Python?

by rubenwardy » Post

Minetest uses lua. It will probably be quite hard to add python support, but you can do Lua.
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

davegoopot
Member
Posts: 15
Joined: Sat Apr 06, 2013 08:43
GitHub: davegoopot

Re: Scripting Interface Like Raspberry Pi Python?

by davegoopot » Post

Thanks @rubenwardy. From my digging so far I've seen using Lua to build mods, but those don't seem to be scripting in the sense of being able to write code separate from the running server to interact with the running server -- unless I'm missing something!

Dave.

User avatar
Calinou
Moderator
Posts: 3169
Joined: Mon Aug 01, 2011 14:26
GitHub: Calinou
IRC: Calinou
In-game: Calinou
Location: Troyes, France
Contact:

Re: Scripting Interface Like Raspberry Pi Python?

by Calinou » Post

There's not much you can do to interact with a running server, except telling it to run the contents of a file every n seconds or similar.

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

Re: Scripting Interface Like Raspberry Pi Python?

by rubenwardy » Post

This is very insecure, and it is not recommended that you use it on an actual server. Install it as a mod by pasting it into mods/lua_run/init.lua

Code: Select all

minetest.register_chatcommand("l", {
	params = "lua code",
	description = "Run lua code",
	func = function(name, param)
		f = loadstring("minetest.chat_send_player(\"" .. name .. "\", \"Result: \" .. dump("..param.."))")
		f()
	end
})
For example, typing /l 2+2 in the chat box (Key: T) returns Result: 4
That is the letter L, for Lua, just in case it is hard to see.
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

Sokomine
Member
Posts: 4289
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine
IRC: Sokomine
In-game: Sokomine

Re: Scripting Interface Like Raspberry Pi Python?

by Sokomine » Post

davegoopot wrote: We had extensively used the python API to Minecraft ([1] and [2]) to allow kids to write python code that would change a running world. Is there anything equivalent in Minetest? The user experience I'm thinking about is that child 1 is playing in game while child 2 can run some code against the world, sending chat messages, setting blocks, etc.
Minetest mods are diffrent in that they're run on the server exclusively. What you could do would be something similar to what Calinou already said - write a mini-server in Lua that listens on some port of your choice, accepts commands in the way your existing api expected them, and translates them for the Minetest api.
The question is how useful that'd be. Interacting with a 3d world through commands without seeing it is tricky, and I'm not sure how much might be gained that way. How complex are the existing programs written by the kids?
Also please take a look at the irc mod. That allows to set permissions of players via irc and of course to chat with players.
A list of my mods can be found here.

gamergardencat
Member
Posts: 55
Joined: Wed Oct 01, 2014 11:58

Re: Scripting Interface Like Raspberry Pi Python?

by gamergardencat » Post

If it's a separate executable that listens to a port of your choice then any language can do that it doesn't have to be LUA. I am assuming this mean Minetest is somehow sending some kind of data to another program somewhere else on the server? There would be read write executable security concerns there other players might be able to issue commands that inject code somehow. his might be possible still anyways if the code allows that kind of leak somehow. If you're looking to make the Minetest server communicate to another machine that's another story yet still any language can be used for that as well. A lot of API's are designed to be androgynous by way of using JSON or serialization of data into unicode. I have tried using php and python together on an apache server and yes the scripts can talk to each other either by calling the other script by URL or through a wrapper. I have thought about looking into the wrapper for LUA in Minetest. Fastest way it to learn some LUA. If they can learn some LUA all the better. Programmers like to know how other languages work since it really helps to solidify many concepts since they are implemented a little differently like objects. Objects in LUA to me like very C like but yet act a lot like objects do in PHP to created controllers. C# and JAVA to me looked so much the same to me when I was studying both I have to start writing the code different so it would be easier to figure out what I am looking at when I'm getting tired and foggy. C++ is easy to get lost in the nut and bolt since more power is given to the user to do crazy things wanting something like tie in templating and operation overloading with custom getters and setters, very verbose, so it's a lot like playing in the mud.
superman slices a giant apple into 3 and hands it to guest220

User avatar
aldobr
Member
Posts: 316
Joined: Sun Nov 25, 2012 05:46

Re: Scripting Interface Like Raspberry Pi Python?

by aldobr » Post

What you want sounds like client side lua scripting. We dont have that yet.

What can be done is a lua client for minetest. I can do one, but i cannot understand minetest protocol (yet). I might write a binary lua host that runs lua code and connects to the server, automatizing player actions. Then you connect with the normal minetest client and watch the robot walk and act on the world.

The only obstacle is to understand minetest protocol.

I wrote a actor model library (carl hewitt's actor model) in freepascal that allows heavy multithreading. Actor model scales very well into thousands and thousands of threads (its a kind of message passing). So i can write a lua interpreter actor and a minetest interface actor. Then you can run various lua scripts in parallel that talk to the server and do actions on the server. Pascal generates quite fast code (pls dont post speed comparision sites, they only prove that one piece of testcode received more work to become faster than others) and is quite easy to learn. (i wrote a pascal interpreter once).

We might end up with a robot system that accepts multiple language back-ends (there is python bindings for freepascal, just as there is lua bindings for freepascal).

PascalScript, Squirrel, Lua, Javascript (theres a full jit javascript interpreter for freepascal) and Python.

Like i said, only obstacle is to understand server protocol (or to implement an alternative back-door like protocol into minetest that allows bot connections).

Thats where my project stoped (i have a lot of projects in the freezer).

Sokomine
Member
Posts: 4289
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine
IRC: Sokomine
In-game: Sokomine

Re: Scripting Interface Like Raspberry Pi Python?

by Sokomine » Post

aldobr wrote: We might end up with a robot system that accepts multiple language back-ends (there is python bindings for freepascal, just as there is lua bindings for freepascal).
We ought to be a bit careful with that. An easy-to-use-bot that could roam around any server might not be a good idea. I won't want to see such a bot on a server I play on (though I tolerate that one on Redcrabs server - it was, after all, written by the player who uses it). My suggestion was to write a tiny server in lua which could interact with MT (by beeing running on the server as a mod) and provide an interface to the outside world. Might require some additional libraries.
The original poster does not seem to have any further intrest. Perhaps allowing the kids to write real Lua mods would be more satisfying anyway.
A list of my mods can be found here.

User avatar
aldobr
Member
Posts: 316
Joined: Sun Nov 25, 2012 05:46

Re: Scripting Interface Like Raspberry Pi Python?

by aldobr » Post

What you say implies security by obfuscation and was proven repeatedly to not work. We might have unknown bots right now due to this.

Sokomine
Member
Posts: 4289
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine
IRC: Sokomine
In-game: Sokomine

Re: Scripting Interface Like Raspberry Pi Python?

by Sokomine » Post

aldobr wrote: What you say implies security by obfuscation and was proven repeatedly to not work. We might have unknown bots right now due to this.
Hm, no, it may sound similar but it's not the same. I'm not talking about deliberate obfuscation here - anyone who wants to can already write such a bot, provided he/she has the general knowledge and is willing to learn the rest. Same as with any other not-yet-implemented functionality. And it's not a security issue either since the integrity of a MT server is not violated by a bot who does behave like a player.
Weather or not such bots would be desirable on servers is another matter. I see no point in it apart from the fun someome might have in understanding the source code so far as to be able to write such a bot and test it. Multiplayer servers are for players to interact with each other. Giving a bot to new and inexperienced players who don't know enough about what they're doing wouldn't be helpful to anyone. The only reason it was talked about here is as a compatibility layer for a specific situation.
A list of my mods can be found here.

User avatar
aldobr
Member
Posts: 316
Joined: Sun Nov 25, 2012 05:46

Re: Scripting Interface Like Raspberry Pi Python?

by aldobr » Post

Your answer looks a lot like cautionary tales. Are we here to educate people ?

arpruss
Member
Posts: 39
Joined: Sat Sep 26, 2015 14:01
GitHub: arpruss

Re: Scripting Interface Like Raspberry Pi Python?

by arpruss » Post

I've just written a mod that implements most of the Raspberry PI Minecraft API, so many of the python scripts for Raspberry PI Minecraft should work. A big collection of scripts is here (get either the python2 or python3 version, but the python3 ones are likely to be buggy).

The mod requires the win32 build of Minetest as it includes the binaries for the luasockets library. If you replace these with appropriate alternate binaries, it should work on other operating systems.

There are probably a bunch of bugs, as I'm new to Lua/Minetest. (But I'm not new to implementing the Raspberry PI Minecraft API, since I've already implemented as a desktop minecraft mod and an Android Minecraft PE mod.)

Image

Sokomine
Member
Posts: 4289
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine
IRC: Sokomine
In-game: Sokomine

Re: Scripting Interface Like Raspberry Pi Python?

by Sokomine » Post

arpruss wrote: I've just written a mod that implements most of the Raspberry PI Minecraft API, so many of the python scripts for Raspberry PI Minecraft should work. A big collection of scripts is here (get either the python2 or python3 version, but the python3 ones are likely to be buggy).
Please also open a new thread for your mod in the WIP mods section of the forum. I'm sure there will be people out there who seek what you've implemented. A short video on Youtube might also help some intrested players to learn about the existance of your mod.
A list of my mods can be found here.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 12 guests