Page 1 of 1

ABM running only on blocks under Y=(some number here)?

PostPosted: Thu Oct 11, 2012 22:44
by SegFault22
Hey all, I am working on another mod. This mod requires that an ABM running in it only affects blocks below Y=13. I have searched everywhere, and can find nothing about how to make this work.
Any ideas?

PostPosted: Thu Oct 11, 2012 23:02
by VanessaE
Inside your ABM code, in the code where you take some action, add an explicit check there for pos.y < 14 just ahead of doing whatever action you had planned.

PostPosted: Thu Oct 11, 2012 23:14
by SegFault22
I don't mean to ask so many questions, but, what's an ''explicit check'' - and can you give an example to that dude who's working on the Minetest Online API, for future reference?
Thank you for your help.

PostPosted: Fri Oct 12, 2012 00:04
by VanessaE
If you have some code inside your ABM that actually does something, for example adding a new node somewhere, like this:

minetest.env:add_node(pos, {name = "widgets:fooblock"})

...then you would wrap it in a simple check routine, so your ABM might look something like this:

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
minetest.register_abm({
     nodenames = { list of nodenames to operate on },
     ...
     ... other ABM settings here...
     ...
     action = function(pos, node, active_object_count, active_object_count_wider)
          if pos.y < 14 then
               minetest.env:add_node(pos, {name = "widgets:fooblock"})
          end
     end
})


The idea is to check the Y position of the node the ABM is about to operate on before you actually DO anything to that node. If Y < 14 then do whatever you were gonna do, otherwise do nothing.

PostPosted: Fri Oct 12, 2012 00:24
by SegFault22
Ah, thank you :D
Now I can finish the crab mod and release v1.0...