[Solived] Reusable Function

Post Reply
User avatar
Semmett9
Member
Posts: 157
Joined: Sun Oct 07, 2012 13:48
Location: Gallifrey
Contact:

[Solived] Reusable Function

by Semmett9 » Post

I'm working on a scaffolding mod which auto builds the scaffolding.

Since some code is the same for, is they a way to make a reusable function, where the mod passes the information such as Position and Node name to the function.

Example;

1. Wood scaffolding Node sends the information to the function (node, pos)
2. The function puts uses the values given to it

below is what I have so far

Code: Select all

local scaffolfing = function (node, pos)
-- code for the building 
end


on_rightclick = function(pos, node, player, itemstack, pointed_thing)
    if itemstack:get_name() == "scaffolding:platform" then

        scaffolfing = function(node, pos)
        end
    end
end,



on_rightclick = function(pos, node, player, itemstack, pointed_thing)
if itemstack:get_name() == "scaffolding:platform" then

scaffolfing = function(node)
end
end
end,


[/code]
Last edited by Semmett9 on Wed Jan 11, 2017 18:08, edited 1 time in total.

User avatar
stu
Member
Posts: 923
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11
Location: United Kingdom

Re: Reusable Function

by stu » Post

Semmett9 wrote:is they a way to make a reusable function, where the mod passes the information such as Position and Node name to the function.
The code you have written is almost correct, it should look something like this

Code: Select all

local scaffolding = function(node, pos)
-- code for the building
end

on_rightclick = function(pos, node, player, itemstack, pointed_thing)
	if itemstack:get_name() == "scaffolding:platform" then
		scaffolding(node, pos)
	end
end,

User avatar
Semmett9
Member
Posts: 157
Joined: Sun Oct 07, 2012 13:48
Location: Gallifrey
Contact:

Re: [Solived] Reusable Function

by Semmett9 » Post

Many thanks for the help.

got it working.

Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests