How to access a mods functions

User avatar
Sane
Member
 
Posts: 103
Joined: Tue Jun 17, 2014 09:31
GitHub: mt-sane
In-game: Sane

How to access a mods functions

by Sane » Tue Jun 17, 2014 11:46

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.
Last edited by Sane on Tue Jun 17, 2014 17:32, edited 1 time in total.
Trying to stay me.
 

User avatar
Krock
Member
 
Posts: 3598
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker

Re: How to access a mods functions

by Krock » Tue Jun 17, 2014 13:41

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!
Newest Win32 builds - Find a mod - All my mods
ALL YOUR DONATION ARE BELONG TO PARAMAT (Please support him and Minetest)
New DuckDuckGo !bang: !mtmod <keyword here>
 

User avatar
Sane
Member
 
Posts: 103
Joined: Tue Jun 17, 2014 09:31
GitHub: mt-sane
In-game: Sane

Re: How to access a mods functions

by Sane » Tue Jun 17, 2014 16:42

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
Trying to stay me.
 

User avatar
Krock
Member
 
Posts: 3598
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker

Re: How to access a mods functions

by Krock » Tue Jun 17, 2014 16:44

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
Newest Win32 builds - Find a mod - All my mods
ALL YOUR DONATION ARE BELONG TO PARAMAT (Please support him and Minetest)
New DuckDuckGo !bang: !mtmod <keyword here>
 

User avatar
Sane
Member
 
Posts: 103
Joined: Tue Jun 17, 2014 09:31
GitHub: mt-sane
In-game: Sane

Re: How to access a mods functions

by Sane » Tue Jun 17, 2014 17:20

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
Trying to stay me.
 

User avatar
Sane
Member
 
Posts: 103
Joined: Tue Jun 17, 2014 09:31
GitHub: mt-sane
In-game: Sane

Re: How to access a mods functions

by Sane » Tue Jun 17, 2014 17:26

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
Trying to stay me.
 

User avatar
Sane
Member
 
Posts: 103
Joined: Tue Jun 17, 2014 09:31
GitHub: mt-sane
In-game: Sane

Closing

by Sane » Tue Jul 29, 2014 11:21

Updating to mt 0.4.10 solved the problem.
Trying to stay me.
 


Return to Minetest Problems

Who is online

Users browsing this forum: No registered users and 7 guests