How to access a mods functions

Post Reply
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 » Post

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:

Code: Select all

default
pipeworks
init.lua:

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
Developer
Posts: 4577
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

Re: How to access a mods functions

by Krock » Post

https://github.com/minetest/minetest/bl ... i.txt#L116
https://github.com/VanessaE/pipeworks/b ... rt.lua#L32

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!
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search 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 » Post

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

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:

Code: Select all

pipework exists
but is nil
Trying to stay me.

User avatar
Krock
Developer
Posts: 4577
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

Re: How to access a mods functions

by Krock » Post

Sane wrote:

Code: Select all

if pipework == nil then
You made a typo there, it's actually "pipeworks"

EDIT: The

Code: Select all

if minetest.get_modpath("pipeworks") then
I gave you, is useless in this case because pipeworks is in depends.txt
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search 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 » Post

Krock wrote:
Sane wrote:

Code: Select all

if pipework == nil then
You made a typo there, it's actually "pipeworks"
Changed the code to:

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:

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 » Post

Actually I've grabbed the code I am fiddling with from
technic/machines/register/common.lua:

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 » Post

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

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest