Page 1 of 1

How to access a mods functions

PostPosted: Tue Jun 17, 2014 11:46
by Sane
Edit: using Minetest 0.4.9 on an Ubuntu system.

Hi there,

how do I access the functions of a mod?
For example the tube_item function of pipeworks.

My mod, at this point, simply consists out of these 2 files.

depends.txt:
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
default
pipeworks

init.lua:
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
print("pipeworks is: "..dump(pipeworks))


this prints:
pipeworks is: nil


So, where do I get that pipeworks object from?

Thanks in advance.

Re: How to access a mods functions

PostPosted: Tue Jun 17, 2014 13:41
by Krock
https://github.com/minetest/minetest/bl ... i.txt#L116
https://github.com/VanessaE/pipeworks/b ... rt.lua#L32
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
if minetest.get_modpath("pipeworks") ~= nil then
   --pipeworks exists
   pipeworks.tube_item(pos, item)
end

pipeworks must be enabled in the world, else it won't work.

EDIT: Oh, welcome to the minetest forums!

Re: How to access a mods functions

PostPosted: Tue Jun 17, 2014 16:42
by Sane
Krock wrote:pipeworks must be enabled in the world, else it won't work.

EDIT: Oh, welcome to the minetest forums!

Thank you for the welcome.

pipeworks is enabled.
I've changed the code to
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
if minetest.get_modpath("pipeworks") ~= nil then
   print("pipework exists")
   if pipework == nil then
      print("but is nil")
   else
      print("and is not nil")
   end
else
   print("pipework does not exists")
end

Output is now:
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
pipework exists
but is nil

Re: How to access a mods functions

PostPosted: Tue Jun 17, 2014 16:44
by Krock
Sane wrote:
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
if pipework == nil then

You made a typo there, it's actually "pipeworks"

EDIT: The
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
if minetest.get_modpath("pipeworks") then

I gave you, is useless in this case because pipeworks is in depends.txt

Re: How to access a mods functions

PostPosted: Tue Jun 17, 2014 17:20
by Sane
Krock wrote:
Sane wrote:
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
if pipework == nil then

You made a typo there, it's actually "pipeworks"


Changed the code to:
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
if minetest.get_modpath("pipeworks") ~= nil then
   print("pipeworks exists")
   if pipeworks == nil then
      print("but is nil")
   else
      print("and is not nil")
   end
else
   print("pipeworks exists")
end
print("pipeworks is: "..dump(pipeworks))


Output is still:
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
pipeworks exists
but is nil
pipeworks is: nil

Re: How to access a mods functions

PostPosted: Tue Jun 17, 2014 17:26
by Sane
Actually I've grabbed the code I am fiddling with from
technic/machines/register/common.lua:
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 technic.send_items(pos, x_velocity, z_velocity)
   -- Send items on their way in the pipe system.
   local meta = minetest.get_meta(pos)
   local inv = meta:get_inventory()
   local i = 0
   for _, stack in ipairs(inv:get_list("dst")) do
      i = i + 1
      if stack then
         local item0 = stack:to_table()
         if item0 then
            item0["count"] = "1"
            
            -- Sane -> this fails
            local item1 = pipeworks.tube_item({x=pos.x, y=pos.y, z=pos.z}, item0)
            item1:get_luaentity().start_pos = {x=pos.x, y=pos.y, z=pos.z}
            item1:setvelocity({x=x_velocity, y=0, z=z_velocity})
            item1:setacceleration({x=0, y=0, z=0})
            stack:take_item(1)
            inv:set_stack("dst", i, stack)
            return
         end
      end
   end
end

Closing

PostPosted: Tue Jul 29, 2014 11:21
by Sane
Updating to mt 0.4.10 solved the problem.