Page 1 of 1

I can insert a lua script in my mod?

PostPosted: Mon Dec 28, 2015 17:49
by MineYoshi
I mean i can insert a little and simple lua program as a calculator in my mod?
insert the script and by example:
i touch a calculator block now i have in minetest a lua calculator!
How i make this!

Re: I can insert a lua script in my mod?

PostPosted: Tue Jan 05, 2016 21:10
by AiTechEye
looks like you need to learn some coding :-)
its easiest way is to look in other people's mods and see how they is doing & try it and much testing

here is a calculator block
the block mod-name is excalc:calcblock you need to change it if you want to use it in another mod

Code: Select all
function excalc_form(pos,text)
local meta = minetest.get_meta(pos)

if not text then               -- if void (nil)

   "size[8,3]" ..            --the window
   "button[0,0; 1.5,1;but1;+]" ..
   "button[2,0; 1.5,1;but2;-]" ..
   "button[4,0; 1.5,1;but3;x]" ..
   "button[6,0; 1.5,1;but4;/]" ..
   "textarea[0,2.5;9,1;text3;Output; ".. text .."]"   -- ("") text string (..) adding to textstring

minetest.register_node("excalc:calcblock", {
   description = "Calculator block",
   tiles = {"default_steel_block.png"},
   groups = {dig_immediate = 3,not_in_creative_inventory = 0},
   paramtype2 = "facedir",
after_place_node = function(pos, placer, itemstack)
      local meta = minetest.get_meta(pos)
      meta:set_string("infotext", "Calculator block")
on_receive_fields = function(pos, formname, fields, sender)
      local meta = minetest.get_meta(pos)      --get block text / data
      local num1 = tonumber(fields.text1)   -- comverts text to number
      local num2 = tonumber(fields.text2)   -- comverts text to number
      if num1==nil or num2==nil then   -- will crash if someone is empty
      if fields.but1 then
      if fields.but2 then
      if fields.but3 then
      if fields.but4 then

Re: I can insert a lua script in my mod?

PostPosted: Sat Feb 20, 2016 00:04
by MineYoshi
Thanks! Dude