[Mod] Mesecons (= redstone) [GitHub] [minetest-mod-mesecons]

User avatar
Jeija
Member
 
Posts: 686
Joined: Fri Dec 23, 2011 21:46

by Jeija » Sun Jan 20, 2013 08:04

Sure I will, before it gets upstream. But the functions still are sort of unstable and may change, so not yet. Just let me give you a quick reference here:

event = {type=<string>, iid=<any>} : a parameter, possible types are "on"/"off"/"digiline"/"interrupt"/"program"
port ={a=<bool>, b=<bool>, c=<bool>, d=<bool>} : The port states of the controller, the outputs; This is what you must write to
pin = {a=<bool>, b=<bool>, c=<bool>, d=<bool>} : The port states of the controller, the inputs; This is propably what you want to read your ports from
interrupt(time, id) : runs the code after time again with event.iid = id
print(<any>) : prints/dumps the value
mem = {...} : A preserved table that contains the memory of the µC
digiline_send(chnl, msg) : Sends a digiline message msg to all outputs on channel chnl;
Other controllers receive this message as event.type = "interrupt" and event.iid = {channel=<string>, msg=<string>}
Last edited by Jeija on Sun Jan 20, 2013 08:05, edited 1 time in total.
Redstone for minetest: Mesecons (mesecons.net)
 

Nore
Member
 
Posts: 468
Joined: Wed Nov 28, 2012 11:35
GitHub: Ekdohibs

by Nore » Sun Jan 20, 2013 08:08

Thanks!
 

Nore
Member
 
Posts: 468
Joined: Wed Nov 28, 2012 11:35
GitHub: Ekdohibs

by Nore » Sun Jan 20, 2013 08:16

About loops, why did you disable for loops? They can't be infinite...
 

User avatar
Jeija
Member
 
Posts: 686
Joined: Fri Dec 23, 2011 21:46

by Jeija » Sun Jan 20, 2013 08:30

If you use high values they can still lag the server a lot (like for days).
Redstone for minetest: Mesecons (mesecons.net)
 

glomie
Member
 
Posts: 141
Joined: Sun Aug 07, 2011 19:41

by glomie » Sun Jan 20, 2013 09:59

Try to make objet-detector detect only player
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
-- Object detector
-- Detects all entities in a certain radius
-- The radius can be specified in mesecons/settings.lua

minetest.register_node("mesecons_detector:object_detector_off", {
    tiles = {"default_steel_block.png", "default_steel_block.png", "jeija_object_detector_off.png", "jeija_object_detector_off.png", "jeija_object_detector_off.png", "jeija_object_detector_off.png"},
    paramtype = "light",
    walkable = true,
    groups = {cracky=3},
    description="Player Detector",
    mesecons = {receptor = {
        state = mesecon.state.off
    }}
})

minetest.register_node("mesecons_detector:object_detector_on", {
    tiles = {"default_steel_block.png", "default_steel_block.png", "jeija_object_detector_on.png", "jeija_object_detector_on.png", "jeija_object_detector_on.png", "jeija_object_detector_on.png"},
    paramtype = "light",
    walkable = true,
    groups = {cracky=3,not_in_creative_inventory=1},
    drop = 'mesecons_detector:object_detector_off',
    mesecons = {receptor = {
        state = mesecon.state.on
    }}
})

minetest.register_craft({
    output = 'mesecons_detector:object_detector_off',
    recipe = {
        {"default:steelblock", '', "default:steelblock"},
        {"default:steelblock", "mesecons_microcontroller:microcontroller0000", "default:steelblock"},
        {"default:steelblock", "group:mesecon_conductor_craftable", "default:steelblock"},
    }
})

minetest.register_abm(
    {nodenames = {"mesecons_detector:object_detector_off"},
    interval = 1.0,
    chance = 1,
    action = function(pos, node, active_object_count, active_object_count_wider)
        local objs = minetest.env:get_objects_inside_radius(pos, OBJECT_DETECTOR_RADIUS)
        for k, obj in pairs(objs) do
            if obj~=nil then
                if obj:get_is_player()==true then
                    minetest.env:add_node(pos, {name="mesecons_detector:object_detector_on"})
                    mesecon:receptor_on(pos)
                end
            end
        end
    end,
})

minetest.register_abm(
    {nodenames = {"mesecons_detector:object_detector_on"},
    interval = 1.0,
    chance = 1,
    action = function(pos, node, active_object_count, active_object_count_wider)
        local objs = minetest.env:get_objects_inside_radius(pos, OBJECT_DETECTOR_RADIUS)
        local objectfound=0
        for k, obj in pairs(objs) do
            if obj ~= nil then
                if obj:get_is_player()==true then
                    objectfound=objectfound+1
                end
            end
        end
        if objectfound==0 then
            minetest.env:add_node(pos, {name="mesecons_detector:object_detector_off"})
            mesecon:receptor_off(pos)
        end
    end,
})

but i have this error:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
10:40:16: ERROR[main]: ERROR: An unhandled exception occurred: ServerError: LuaError: error: .../bin/../mods/gl
o/mesecons/mesecons_detector/init.lua:44: attempt to call method 'get_is_player' (a nil value)   
10:40:16: ERROR[main]: stack traceback:

In thread 7fca6f406720:
/home/minetest/celeron55-minetest-5d18dc3/src/main.cpp:1760: int main(int, char**): Assertion '0' failed.
Debug stacks:
DEBUG STACK FOR THREAD 7fca6f406720:
#0  int main(int, char**)
(Leftover data: #1  Dedicated server branch)
(Leftover data: #2  virtual void ServerMap::save(ModifiedState))
(Leftover data: #3  virtual void ServerMap::saveBlock(MapBlock*))
(Leftover data: #4  void ItemStack::serialize(std::ostream&) const)
Abandon
Sorry for my bad english...
 

User avatar
Jeija
Member
 
Posts: 686
Joined: Fri Dec 23, 2011 21:46

by Jeija » Sun Jan 20, 2013 10:18

I think it should be is_player() not get_is_player()
Redstone for minetest: Mesecons (mesecons.net)
 

glomie
Member
 
Posts: 141
Joined: Sun Aug 07, 2011 19:41

by glomie » Sun Jan 20, 2013 10:44

Jeija wrote:I think it should be is_player() not get_is_player()

Thank, it work fine now.
Sorry for my bad english...
 

Nore
Member
 
Posts: 468
Joined: Wed Nov 28, 2012 11:35
GitHub: Ekdohibs

by Nore » Sun Jan 20, 2013 11:14

I have a piston that pushes sand upwards: what happens is that sand is dropped and is pushed normally upwards, so it gets duplicated. Moreover, if there is another node between the sand and the piston, it gets replaced by sand.
 

User avatar
Jeija
Member
 
Posts: 686
Joined: Fri Dec 23, 2011 21:46

by Jeija » Sun Jan 20, 2013 12:02

Should be fixed, Nore, thanks for reporting.
Redstone for minetest: Mesecons (mesecons.net)
 

Temperest
Member
 
Posts: 651
Joined: Tue Nov 15, 2011 23:13
GitHub: Uberi

by Temperest » Sun Jan 20, 2013 17:37

Hey Jeija, is there a solution for disallowing a LuaController function from calling itself repeatedly and crashing the server? I think I mentioned this little snippet before:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
x = function() x() end; x()


To me, it seems the best way to go about this is to either limit the stack size (very difficult, but the best solution), or also blacklist the "function" keyword. However, this would limit what the script could do quite severely.

Just to test, I've re-implemented the while loop without using any loops:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
w_h_i_l_e =  function(condition, body)
    if condition() then
        body()
        return w_h_i_l_e(condition, body)
    end
end

x = 0
w_h_i_l_e(function() return x < 5 end, function()
    x = x + 1
    print("Iteration number " + tostring(x))
end)


Since the function is tail recursive and Lua supports tail call optimization, it even uses constant memory! And of course, the following is an infinite loop:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
w_h_i_l_e(function() return true end, function() end)
Last edited by Temperest on Sun Jan 20, 2013 17:38, edited 1 time in total.
WorldEdit 1.0 released

The Mesecons Laboratory - the art of Mesecons circuitry
Latest article: Mesecons Basics.
 

User avatar
Jeija
Member
 
Posts: 686
Joined: Fri Dec 23, 2011 21:46

by Jeija » Sun Jan 20, 2013 18:27

I didn't think about your while loop part.
The first little snippet is no problem, lua detects a stack overflow and then stops, the second one nevertheless crashes the server. Just wondering... would it be enough to disable "return" (that wouldn't be a good solution, but maybe a starting point?)?
Redstone for minetest: Mesecons (mesecons.net)
 

Temperest
Member
 
Posts: 651
Joined: Tue Nov 15, 2011 23:13
GitHub: Uberi

by Temperest » Sun Jan 20, 2013 18:50

I think disabling "return" could technically work, but it only prevents infinite loops. It's still possible to hang up the server for a long time using a simple program:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
i = 0
x = function(i)
    if i == 100 then return end
    x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);x(i+1);
end


This is also visible when running something like the naive fibonacci number calculation function:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
function fib(n) return n<2 and n or fib(n-1)+fib(n-2) end
fib(100)
WorldEdit 1.0 released

The Mesecons Laboratory - the art of Mesecons circuitry
Latest article: Mesecons Basics.
 

dimitry
 

by dimitry » Mon Jan 21, 2013 18:04

it would be nice to add as distributor in minecraft
thank you
 

rarkenin
Member
 
Posts: 668
Joined: Tue Nov 20, 2012 20:48

by rarkenin » Mon Jan 21, 2013 18:31

dimitry wrote:it would be nice to add as distributor in minecraft
thank you


This isn;t Minecraft...
Admin pro tempore on 0gb.us:30000. Ask me if you have a problem, or just want help.
This is a signature virus. Add me to your signature so that I can multiply.
Now working on my own clone, Mosstest.
I guess I'm back for some time.
 

neron
Member
 
Posts: 82
Joined: Sat Dec 22, 2012 20:22

by neron » Mon Jan 21, 2013 20:36

I vote for Option 1. I'd even like to see maybe a fork of minetest that clones minecraft.
 

rarkenin
Member
 
Posts: 668
Joined: Tue Nov 20, 2012 20:48

by rarkenin » Mon Jan 21, 2013 21:23

neron wrote:I vote for Option 1. I'd even like to see maybe a fork of minetest that clones minecraft.


Crafttest!
Admin pro tempore on 0gb.us:30000. Ask me if you have a problem, or just want help.
This is a signature virus. Add me to your signature so that I can multiply.
Now working on my own clone, Mosstest.
I guess I'm back for some time.
 

Nore
Member
 
Posts: 468
Joined: Wed Nov 28, 2012 11:35
GitHub: Ekdohibs

by Nore » Tue Jan 22, 2013 19:54

Could you add functions like tostring, tonumber, string.gsub, ... to the luacontroller? It would be so helpful.
 

User avatar
sfan5
Member
 
Posts: 3636
Joined: Wed Aug 24, 2011 09:44
GitHub: sfan5
IRC: sfan5

by sfan5 » Tue Jan 22, 2013 19:58

Nore wrote:Could you add functions like tostring, tonumber, string.gsub, ... to the luacontroller? It would be so helpful.

It wouldn't be a lowlevel controller anymore.
Mods: Mesecons | WorldEdit | Nuke
Minetest builds for Windows (32-bit & 64-bit)
 

User avatar
Jeija
Member
 
Posts: 686
Joined: Fri Dec 23, 2011 21:46

by Jeija » Tue Jan 22, 2013 20:19

The luacontroller is not supposed to be a low-level controller, but a very powerful tool.
Let's make a deal, Nore: I removed 'function', but allowed tostring(), tonumber(), and string.* under reservation (only if they surely can't cause an error).
You can add anything you want to to the environment in function create_environment and allow functions by removing them from the prohibited table in mesecons_luacontroller/init.lua.
Redstone for minetest: Mesecons (mesecons.net)
 

Temperest
Member
 
Posts: 651
Joined: Tue Nov 15, 2011 23:13
GitHub: Uberi

by Temperest » Tue Jan 22, 2013 20:37

Great! I now consider the luacontroller mostly safe against the most common DOS attacks. I will continue to look for security vulnerabilities though.

edit: I'm also loving this new forum editor.
Last edited by Temperest on Tue Jan 22, 2013 20:38, edited 1 time in total.
WorldEdit 1.0 released

The Mesecons Laboratory - the art of Mesecons circuitry
Latest article: Mesecons Basics.
 

User avatar
LionLAD
Member
 
Posts: 307
Joined: Wed Jul 11, 2012 21:50

by LionLAD » Fri Jan 25, 2013 19:48

I've come to realize that the command block does not have a crafting recipe so i was thinking of this...

Image

if you like the crafting recipe download maby??

The Download <---- click the button to download
Last edited by LionLAD on Fri Jan 25, 2013 19:55, edited 1 time in total.
In game names:LAD,captainLAD,LionLAD
This is a signature virus. Add me to your signature so that I can multiply.
 

Temperest
Member
 
Posts: 651
Joined: Tue Nov 15, 2011 23:13
GitHub: Uberi

by Temperest » Fri Jan 25, 2013 20:23

The command block will not have a crafting recipe, since it is highly susceptible to abuse by untrusted players. For instance, chat spamming would easily become a problem if one connected a clock to a command block.

As it is now, only creative mode players and survival mode players with give privs can obtain the block.

TL;DR: it's not supposed to be available to normal players.
Last edited by Temperest on Fri Jan 25, 2013 20:24, edited 1 time in total.
WorldEdit 1.0 released

The Mesecons Laboratory - the art of Mesecons circuitry
Latest article: Mesecons Basics.
 

User avatar
RabbiBob
Member
 
Posts: 335
Joined: Sat Jan 28, 2012 22:40

by RabbiBob » Sun Jan 27, 2013 22:47

Inocudom wrote:Go with option number 2, but find a way to fix those limitations if you can. It would also be a good idea to try to improve compatibility with mods that rely on mesecons (like technic and bobblocks) since the newest version of it is not compatible with them.


Jeija wrote:The compatibility with other mods that use mesecons is the mod owners responsibility. I announced the API change a long time before it actually took place, and that change was basically there to improve depending stuff, so compatibility.


Plus it helps the mod creators if users post in the mod threads themselves if there are issues as I believe most of us subscribe to our own mod threads & we get an email if there are posts. I happened upon the top quote due to a vanity search earlier and am now aware of the problem.

I've figured out the compatibility issue, just need to code it and put out a new version. Until I do that, my thread has notes on how to get the current BobBlocks to load if you've updated Mesecons.

Cheers,
Bob
 

Kacey
Member
 
Posts: 133
Joined: Sat May 05, 2012 16:20

by Kacey » Mon Jan 28, 2013 00:36

i have made a basic RAM unit in minetest via mesecons
thank you Jeija for the great mod
screenshots to come
on a scale of 1 to 10 i am OVER 9000!!!!!!!!!!!!!!!!
 

User avatar
Jeija
Member
 
Posts: 686
Joined: Fri Dec 23, 2011 21:46

by Jeija » Mon Jan 28, 2013 07:09

Sorry, RabbiBob for not telling you. The problem is just that there are many mods using mesecons and I also don't know all of them, that's why I didn't post in all the topics.
But true, I could have told the ones I know and I will do that in case a second update is required (there are no plans however).
Redstone for minetest: Mesecons (mesecons.net)
 

User avatar
RabbiBob
Member
 
Posts: 335
Joined: Sat Jan 28, 2012 22:40

by RabbiBob » Mon Jan 28, 2013 10:55

Jeija wrote:Sorry, RabbiBob for not telling you. The problem is just that there are many mods using mesecons and I also don't know all of them, that's why I didn't post in all the topics.
But true, I could have told the ones I know and I will do that in case a second update is required (there are no plans however).


That wasn't directed to you, I actually was agreeing with your post as quoted. If I have a dependency on your mod (which I do), it's not your job to hunt me down. Life keeps me fairly busy, but I get emails from my mod thread if anyone has a comment and I check those out, so the mention was for people that use any mod that breaks - it helps the mod author if they report back to the mod thread itself, that's all.

Took me a bit to figure out what had changed, but I think I have it now :)
Last edited by RabbiBob on Mon Jan 28, 2013 10:56, edited 1 time in total.
 

User avatar
monty_oso
Member
 
Posts: 44
Joined: Wed Jun 20, 2012 05:44

by monty_oso » Tue Feb 05, 2013 19:24

Last edited by monty_oso on Sat Feb 09, 2013 18:08, edited 1 time in total.
My English sucks very hard (TM).
I'm very interesting in mesecons stuff.
 

Nore
Member
 
Posts: 468
Joined: Wed Nov 28, 2012 11:35
GitHub: Ekdohibs

by Nore » Fri Feb 08, 2013 17:50

Suggestion: use a queue instead of a stack to process signals, so that signal that have more gates in their way are more delayed than others. Without that, it is very difficult to build shift registers or things like that.
 

User avatar
Jeija
Member
 
Posts: 686
Joined: Fri Dec 23, 2011 21:46

by Jeija » Fri Feb 08, 2013 18:14

Using a queue conflicts with pistons, I made that model theoretically and also doesn't work practically.

So, why not only use a queue for gates / the microcontroller?
There is no proper way to describe e.g. a microcontroller's behaviour with implemented queue (something complicated with multiple ports receiving a signal and therefore multiple queue entries was the issue if I remember correctly).
If you succeed exactly describing a microcontroller's behaviour when using a queue, there must also be a way to code that...
Redstone for minetest: Mesecons (mesecons.net)
 

Nore
Member
 
Posts: 468
Joined: Wed Nov 28, 2012 11:35
GitHub: Ekdohibs

by Nore » Fri Feb 08, 2013 18:21

The idea is that you update all changes for a single node at once (that is, the microcontroller would only get one signal).
 

PreviousNext

Return to Mod Releases

Who is online

Users browsing this forum: No registered users and 11 guests

cron