[Solived] Reusable Function

User avatar
Semmett9
Member
 
Posts: 149
Joined: Sun Oct 07, 2012 13:48

[Solived] Reusable Function

by Semmett9 » Sat Jan 07, 2017 14:08

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]
Last edited by Semmett9 on Wed Jan 11, 2017 18:08, edited 1 time in total.
 

User avatar
stu
Member
 
Posts: 737
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11

Re: Reusable Function

by stu » Sat Jan 07, 2017 19:22

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,
 

User avatar
Semmett9
Member
 
Posts: 149
Joined: Sun Oct 07, 2012 13:48

Re: [Solived] Reusable Function

by Semmett9 » Wed Jan 11, 2017 18:09

Many thanks for the help.

got it working.
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 6 guests