Page 1 of 1

[Solived] Reusable Function

PostPosted: Sat Jan 07, 2017 14:08
by Semmett9
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

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
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]

Re: Reusable Function

PostPosted: Sat Jan 07, 2017 19:22
by stu
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
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
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,

Re: [Solived] Reusable Function

PostPosted: Wed Jan 11, 2017 18:09
by Semmett9
Many thanks for the help.

got it working.