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!
function excalc_form(pos,text)
local meta = minetest.get_meta(pos)
if not text then -- if void (nil)
text=""
end
meta:set_string("formspec",
"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,1;4,1;text1;Calculate;]"..
"textarea[4.6,1;4,1;text2;with;]"..
"textarea[0,2.5;9,1;text3;Output; ".. text .."]" -- ("") text string (..) adding to textstring
)
end
minetest.register_node("excalc:calcblock", {
description = "Calculator block",
tiles = {"default_steel_block.png"},
groups = {dig_immediate = 3,not_in_creative_inventory = 0},
paramtype2 = "facedir",
light_source=0,
sounds=default.node_sound_stone_defaults(),
after_place_node = function(pos, placer, itemstack)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Calculator block")
excalc_form(pos)
end,
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
num1=0
num2=0
end
if fields.but1 then
excalc_form(pos,num1+num2)
end
if fields.but2 then
excalc_form(pos,num1-num2)
end
if fields.but3 then
excalc_form(pos,num1*num2)
end
if fields.but4 then
excalc_form(pos,num1/num2)
end
end,
})
Users browsing this forum: No registered users and 12 guests