I can insert a lua script in my mod?

User avatar
MineYoshi
Member
 
Posts: 4267
Joined: Wed Jul 08, 2015 13:20
GitHub: MineYosh
IRC: MineYoshi
In-game: Kirby_Retro

I can insert a lua script in my mod?

by MineYoshi » Mon Dec 28, 2015 17:49

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!
People talk about freedom of speech, so i'll say that God exists.
Open your eyes!! See The big unicorn conspiracy.!! :D The government has been lying to us about unicorns!!
"I've learned there are three things you don't discuss with people: religion, politics and the Great Pumpkin" - Linus Van Pelt
I'm the Officially 1st ABJist in the world ( ͡° ͜ʖ ͡°)
 

User avatar
AiTechEye
Member
 
Posts: 409
Joined: Fri May 29, 2015 21:14

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

by AiTechEye » Tue Jan 05, 2016 21:10

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

1: http://dev.minetest.net/Intro
2: http://dev.minetest.net/Category:Methods
3: http://dev.minetest.net/formspec
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
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,
})


Alive AI Mine/Build AI NPC
Gravitygun HL2
Portalgun Portal
Marssurvive Survive on mars
Bows bows + arrows
SoundCloud (Music)
SoundCloud (Classic)
YouTube
 

User avatar
MineYoshi
Member
 
Posts: 4267
Joined: Wed Jul 08, 2015 13:20
GitHub: MineYosh
IRC: MineYoshi
In-game: Kirby_Retro

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

by MineYoshi » Sat Feb 20, 2016 00:04

Thanks! Dude
People talk about freedom of speech, so i'll say that God exists.
Open your eyes!! See The big unicorn conspiracy.!! :D The government has been lying to us about unicorns!!
"I've learned there are three things you don't discuss with people: religion, politics and the Great Pumpkin" - Linus Van Pelt
I'm the Officially 1st ABJist in the world ( ͡° ͜ʖ ͡°)
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 12 guests

cron