Post your modding questions here

Hybrid Dog
Member
 
Posts: 2460
Joined: Thu Nov 01, 2012 12:46

Re: Post your modding questions here

by Hybrid Dog » Fri Jan 30, 2015 16:35

Fox wrote:
Hybrid Dog wrote:l tried to find "legacy_mineral" (with grep -rl) in other files but it's only in ./games/minimal/mods/default/init.lua and ./games/minetest_game/mods/default/nodes.lua. Maybe it's used for decoration.


Hello Hybrd Dog,

Yes, I couldn't find it anywhere else either. Not a mention in lua_api.txt. I didn't know if it was maybe an outdated property, something like decoration as you said, or what. I don't seem to see it in the other mods I have either, so maybe it's something I can ignore like everyone else seems to be doing. xD That it doesn't do anything special I might want, maybe even just does nothing.

Just can't help but wonder though.

found it: viewtopic.php?p=46658#p46658
l need to remove it from my mod…
 

User avatar
Merlin
Member
 
Posts: 63
Joined: Tue Dec 09, 2014 22:07
GitHub: sct-0
In-game: my

Re: Post your modding questions here

by Merlin » Fri Jan 30, 2015 17:01

Thanks for the great explanation 4aiman! :D
I will toy around with it a bit this weekend. I think I'll first do a simple mob similar to Minecrafts slime thingy.
 

User avatar
BrunoMine
Member
 
Posts: 902
Joined: Thu Apr 25, 2013 17:29
GitHub: BrunoMine

how to declare a variable?

by BrunoMine » Fri Feb 06, 2015 20:30

I know it sounds very simple, but I can not declare variables. Only constants.
example:
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 day = 1;

It does not change value even if I change its value in a function.
 

Hybrid Dog
Member
 
Posts: 2460
Joined: Thu Nov 01, 2012 12:46

Re: how to declare a variable?

by Hybrid Dog » Fri Feb 06, 2015 20:44

brunob.santos wrote:It does not change value even if I change its value in a function.

Which function do you mean?
 

User avatar
BrunoMine
Member
 
Posts: 902
Joined: Thu Apr 25, 2013 17:29
GitHub: BrunoMine

Re: how to declare a variable?

by BrunoMine » Fri Feb 06, 2015 20:55

Hybrid Dog wrote:Which function do you mean?


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 slot1_image = ""

function brazutec_instalar_em_laptop(texture)
   local slot1_imagem = textura
end

brazutec_laptop = {
   desktop = "size[12,9]"..
      "bgcolor[#080808BB;true]"..
      "image[0,0;15,10;brazutec_desktop.png]"..
      "image[0,0;5,5;"..slot1_imagem.."]",
}


in extra mod
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 new_image = "brazutec_botao_off.png"

minetest.register_on_joinplayer(function(player)
   brazutec_instalar_em_laptop(new_image)
end)


to sum up

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
ERROR[main]:    
ERROR[main]: GUIFormSpecMenu::drawMenu() Draw images unable to load texture:
 

User avatar
Krock
Member
 
Posts: 3598
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker

Re: how to declare a variable?

by Krock » Sat Feb 07, 2015 08:40

brunob.santos wrote:<snip>

Try this code:

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 get_laptop_formspec(texture)
   return (laptop_formspec.desktop..
      "image[0,0;5,5;"..texture.."]")
end

laptop_formspec = {
   desktop = "size[12,9]"..
      "bgcolor[#080808BB;true]"..
      "image[0,0;15,10;brazutec_desktop.png]"
}

---------------

local new_image = "brazutec_botao_off.png"

minetest.register_on_joinplayer(function(player)
   minetest.show_formspec(player:get_player_name(), "form:name", get_laptop_formspec(new_image))
end)
Newest Win32 builds - Find a mod - All my mods
ALL YOUR DONATION ARE BELONG TO PARAMAT (Please support him and Minetest)
New DuckDuckGo !bang: !mtmod <keyword here>
 

User avatar
lag01
Member
 
Posts: 190
Joined: Sun Mar 16, 2014 03:41
GitHub: AndrejIT
IRC: lag01
In-game: lag

Re: how to declare a variable?

by lag01 » Sat Feb 07, 2015 08:45

Krock wrote:
brunob.santos wrote:<snip>

Try this code:
<snip2>


Original brunob.santos's code seems crude, good idea to rewrite it.
 

Hybrid Dog
Member
 
Posts: 2460
Joined: Thu Nov 01, 2012 12:46

Re: how to declare a variable?

by Hybrid Dog » Sat Feb 07, 2015 09:31

brunob.santos wrote:
Hybrid Dog wrote:Which function do you mean?


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 slot1_image = ""

function brazutec_instalar_em_laptop(texture)
   local slot1_imagem = textura
end

brazutec_laptop = {
   desktop = "size[12,9]"..
      "bgcolor[#080808BB;true]"..
      "image[0,0;15,10;brazutec_desktop.png]"..
      "image[0,0;5,5;"..slot1_imagem.."]",
}

You made some typos, l think (slot1_image and slot1_imagem, texture and textura).

If you write "local slot1_image = texture" in the function, slot1_image is only set to texture till "end", so slot1_image doesn't get changed, just remove the "local" in the function.

You need to change brazutec_laptop.desktop, too, because it's set to a string and slot1_image isn't linked. This would only work for tables, l think, e.g. "a={2,3} b=a b[1]=6 return a[1]==2"→false
 

User avatar
BrunoMine
Member
 
Posts: 902
Joined: Thu Apr 25, 2013 17:29
GitHub: BrunoMine

Re: Post your modding questions here

by BrunoMine » Sat Feb 07, 2015 11:27

Thank you, problem solved.
Link to github repository.

now slotlivre button does not exhibit the formspec brazutec_laptop.slotlivre
https://github.com/BrunoMine/brazutec/blob/master/interface.lua
 

User avatar
BrunoMine
Member
 
Posts: 902
Joined: Thu Apr 25, 2013 17:29
GitHub: BrunoMine

How to concatenate a variable?

by BrunoMine » Sat Feb 07, 2015 13:11

Example:
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
slot1_formspec = "example.form1"

minetest.register_on_player_receive_fields(function(player, meta, fields)
   if fields.button1 then
      minetest.show_formspec(player:get_player_name(), "", slot1_formspec)
   end
end


The problem
The minetest.show_formspec command takes slot1_formspec as a formspec and not as a variable.
as should be the syntax for recognition as a variable?
 

User avatar
BrunoMine
Member
 
Posts: 902
Joined: Thu Apr 25, 2013 17:29
GitHub: BrunoMine

Problem solved

by BrunoMine » Sat Feb 07, 2015 14:38

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
slot1_formspec = "example.form1"

function get_example_formspec(slot_formspec)
   return slot_formspec
end

minetest.register_on_player_receive_fields(function(player, meta, fields)
   if fields.button1 then
      minetest.show_formspec(player:get_player_name(), "", get_example_formspec(slot1_formspec))
   end
end
 

User avatar
false_chicken
Member
 
Posts: 35
Joined: Wed Feb 04, 2015 23:41
GitHub: falsechicken
In-game: false_chicken

Re: Post your modding questions here

by false_chicken » Mon Feb 09, 2015 21:16

Is it possible to change an items description tool tip dynamically? For example a key. Crafted it may say "Blank Key" but after using it on a door it would change to "Key To: <name of door>". Thanks.
DISCLAIMER: I am probably wrong.
 

User avatar
Krock
Member
 
Posts: 3598
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker

Re: Post your modding questions here

by Krock » Tue Feb 10, 2015 19:01

false_chicken wrote:Is it possible to change an items description tool tip dynamically? For example a key. Crafted it may say "Blank Key" but after using it on a door it would change to "Key To: <name of door>". Thanks.

That's not possible. You must define multiple different keys.
Newest Win32 builds - Find a mod - All my mods
ALL YOUR DONATION ARE BELONG TO PARAMAT (Please support him and Minetest)
New DuckDuckGo !bang: !mtmod <keyword here>
 

User avatar
false_chicken
Member
 
Posts: 35
Joined: Wed Feb 04, 2015 23:41
GitHub: falsechicken
In-game: false_chicken

Re: Post your modding questions here

by false_chicken » Tue Feb 10, 2015 19:23

Krock wrote:
false_chicken wrote:Is it possible to change an items description tool tip dynamically? For example a key. Crafted it may say "Blank Key" but after using it on a door it would change to "Key To: <name of door>". Thanks.

That's not possible. You must define multiple different keys.


Ah I see. Thanks.
DISCLAIMER: I am probably wrong.
 

User avatar
false_chicken
Member
 
Posts: 35
Joined: Wed Feb 04, 2015 23:41
GitHub: falsechicken
In-game: false_chicken

Re: Post your modding questions here

by false_chicken » Tue Feb 10, 2015 19:30

One more question. Can one disable an item from a base game/mod via lua? Like cleanly removing the Locked Chest from minetest_game or disabling the crafting recipe without editing the base game itself.
DISCLAIMER: I am probably wrong.
 

Hybrid Dog
Member
 
Posts: 2460
Joined: Thu Nov 01, 2012 12:46

Re: Post your modding questions here

by Hybrid Dog » Wed Feb 11, 2015 17:19

false_chicken wrote:One more question. Can one disable an item from a base game/mod via lua? Like cleanly removing the Locked Chest from minetest_game or disabling the crafting recipe without editing the base game itself.

you could write
default?
in depends.txt and
local craft = minetest.register_craft
function minetest.register_craft(a)
if a.output == "default:chest_locked" then
return
end
return craft(a)
end

in init.lua
 

User avatar
false_chicken
Member
 
Posts: 35
Joined: Wed Feb 04, 2015 23:41
GitHub: falsechicken
In-game: false_chicken

Re: Post your modding questions here

by false_chicken » Wed Feb 11, 2015 20:12

Hybrid Dog wrote:
false_chicken wrote:One more question. Can one disable an item from a base game/mod via lua? Like cleanly removing the Locked Chest from minetest_game or disabling the crafting recipe without editing the base game itself.

you could write
default?
in depends.txt and
local craft = minetest.register_craft
function minetest.register_craft(a)
if a.output == "default:chest_locked" then
return
end
return craft(a)
end

in init.lua

Thanks! I'll give that a shot.
DISCLAIMER: I am probably wrong.
 

User avatar
false_chicken
Member
 
Posts: 35
Joined: Wed Feb 04, 2015 23:41
GitHub: falsechicken
In-game: false_chicken

Re: Post your modding questions here

by false_chicken » Wed Feb 11, 2015 20:31

Hybrid Dog wrote:
false_chicken wrote:One more question. Can one disable an item from a base game/mod via lua? Like cleanly removing the Locked Chest from minetest_game or disabling the crafting recipe without editing the base game itself.

you could write
default?
in depends.txt and
local craft = minetest.register_craft
function minetest.register_craft(a)
if a.output == "default:chest_locked" then
return
end
return craft(a)
end

in init.lua


I am a bit confused now. Sorry! I tried it out but I was still able to craft the Locked Chest. The formatted code looks 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 craft = minetest.register_craft

function minetest.register_craft(a)
   if a.output == "default:chest_locked" then
      return
   end
   
   return craft(a)

end


I am unsure as to what this is actually supposed to do. I never call the function explicitly so I am not sure when it is actually supposed to run. From what I can see it never does.
DISCLAIMER: I am probably wrong.
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Post your modding questions here

by rubenwardy » Wed Feb 11, 2015 20:47

That won't work as the default mod declares the recipe before you add the check to stop it being declared.

You could try:

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
minetest.registered_nodes["default:locked_chest_or_whatever"] = nil
minetest.registered_items["default:locked_chest_or_whatever"] = nil
 

User avatar
false_chicken
Member
 
Posts: 35
Joined: Wed Feb 04, 2015 23:41
GitHub: falsechicken
In-game: false_chicken

Re: Post your modding questions here

by false_chicken » Wed Feb 11, 2015 20:53

rubenwardy wrote:That won't work as the default mod declares the recipe before you add the check to stop it being declared.

You could try:

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
minetest.registered_nodes["default:locked_chest_or_whatever"] = nil
minetest.registered_items["default:locked_chest_or_whatever"] = nil


That did the trick! I can still craft it but when placed it simply disappears and does not exist in the creative menu. Thanks!

If anyone has any info on disabling the recipe as well that would be great but this is good enough.
DISCLAIMER: I am probably wrong.
 

User avatar
BrunoMine
Member
 
Posts: 902
Joined: Thu Apr 25, 2013 17:29
GitHub: BrunoMine

Starting a function 1 second after the start of server?

by BrunoMine » Thu Feb 12, 2015 00:40

Starting a function 1 second after the start of server?
Example:
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
minetest.chat_send_all("Server started!")

I know it's ridiculous, but tell me how to do this?
 

User avatar
false_chicken
Member
 
Posts: 35
Joined: Wed Feb 04, 2015 23:41
GitHub: falsechicken
In-game: false_chicken

Re: Starting a function 1 second after the start of server?

by false_chicken » Thu Feb 12, 2015 00:53

brunob.santos wrote:Starting a function 1 second after the start of server?
Example:
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
minetest.chat_send_all("Server started!")

I know it's ridiculous, but tell me how to do this?


I am not sure the proper way to do that. But what I would do just based on what little knowledge I have now would be to register a timed event with a global variable like "message_printed = false" then set it to true with a check in the event so it never runs again.

Simple example based on the wiki example:

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
message_printed = false

local timer = 0
minetest.register_globalstep(function(dtime)
   
   if message_printed == false then
      timer = timer + dtime;
      if timer >= 10 and message_printed == false then
         -- Send "Server Started!" to all players after 10 seconds
         minetest.chat_send_all("Server Started!")
         timer = 0
         message_printed = true -- Set to true so it never prints again.
      end
   end
end)


http://dev.minetest.net/minetest.register_globalstep
Last edited by false_chicken on Thu Feb 12, 2015 01:27, edited 1 time in total.
DISCLAIMER: I am probably wrong.
 

User avatar
BrunoMine
Member
 
Posts: 902
Joined: Thu Apr 25, 2013 17:29
GitHub: BrunoMine

Re: Post your modding questions here

by BrunoMine » Thu Feb 12, 2015 01:06

appears to be correct. thank you
 

User avatar
false_chicken
Member
 
Posts: 35
Joined: Wed Feb 04, 2015 23:41
GitHub: falsechicken
In-game: false_chicken

Re: Post your modding questions here

by false_chicken » Thu Feb 12, 2015 05:36

How do you manually call a callback? I have modified on_place and have found that after_place_node never fires and the wiki says:

Rather than being used by the core game engine itself the following callbacks are called indirectly by the default implementations of the above primary callbacks, so installing a callback for the primary events may result in these methods not being called. For example, if you implement on_place with a custom event handler callback, then after_place_node will not be called unless you explicitly call it, since it is the default on_place callback (minetest.item_place) that calls after_place_node.


So how do I got about calling it myself? Thanks again!
DISCLAIMER: I am probably wrong.
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Starting a function 1 second after the start of server?

by rubenwardy » Thu Feb 12, 2015 14:38

brunob.santos wrote:Starting a function 1 second after the start of server?
Example:
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
minetest.chat_send_all("Server started!")

I know it's ridiculous, but tell me how to do this?


Use:

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
minetest.after(1, function()
    minetest.chat_...
end)


Or something like that.
 

User avatar
false_chicken
Member
 
Posts: 35
Joined: Wed Feb 04, 2015 23:41
GitHub: falsechicken
In-game: false_chicken

Re: Post your modding questions here

by false_chicken » Thu Feb 12, 2015 15:57

How do you use a library in the context of Minetest? I have created one and tried putting 'require "libname"' into into my init.lua but I get:

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
10:53:00: ERROR[main]: ...jects/Repos/minetest/bin/../mods/modname/init.lua:35: module 'libname' not found:
10:53:00: ERROR[main]:    no field package.preload['libname']
10:53:00: ERROR[main]:    no file './libname.lua'
10:53:00: ERROR[main]:    no file '/usr/local/share/lua/5.1/libname.lua'
10:53:00: ERROR[main]:    no file '/usr/local/share/lua/5.1/libname/init.lua'
10:53:00: ERROR[main]:    no file '/usr/local/lib/lua/5.1/libname.lua'
10:53:00: ERROR[main]:    no file '/usr/local/lib/lua/5.1/libname/init.lua'
10:53:00: ERROR[main]:    no file '/home/user/ownCloud/Projects/Repos/minetest/bin/../mods/modname.lua'
10:53:00: ERROR[main]:    no file './libname.so'
10:53:00: ERROR[main]:    no file '/usr/local/lib/lua/5.1/libname.so'
10:53:00: ERROR[main]:    no file '/usr/local/lib/lua/5.1/libname.so'


It seems like it is not searching in my mods directory.
DISCLAIMER: I am probably wrong.
 

Hybrid Dog
Member
 
Posts: 2460
Joined: Thu Nov 01, 2012 12:46

Re: Post your modding questions here

by Hybrid Dog » Thu Feb 12, 2015 16:25

@12Me21:
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
minetest.register_on_craft(function(itemstack, _, old_craft_grid, craft_inv)
   if itemstack:get_name() == "default:chest_locked" then
      craft_inv:set_list("craft", old_craft_grid)
      itemstack:set_name("")
   end
end)

false_chicken wrote:
Hybrid Dog wrote:
false_chicken wrote:One more question. Can one disable an item from a base game/mod via lua? Like cleanly removing the Locked Chest from minetest_game or disabling the crafting recipe without editing the base game itself.

you could write
default?
in depends.txt and
local craft = minetest.register_craft
function minetest.register_craft(a)
if a.output == "default:chest_locked" then
return
end
return craft(a)
end

in init.lua


I am a bit confused now. Sorry! I tried it out but I was still able to craft the Locked Chest. The formatted code looks 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 craft = minetest.register_craft

function minetest.register_craft(a)
   if a.output == "default:chest_locked" then
      return
   end
   
   return craft(a)

end


I am unsure as to what this is actually supposed to do. I never call the function explicitly so I am not sure when it is actually supposed to run. From what I can see it never does.

1. This code should override the function which registers a craft recipe to abort if the output is "default:chest_locked" before the default mod is loaded.
2. l'm sorry, l did a mistake, it would be default! and not default?
3. And l tried it but it still didn't work, maybe letting mods become loaded before default is impossible…

But l found another solution:
minetest.register_on_craft(function(itemstack, _, old_craft_grid, craft_inv)
if itemstack:get_name() == "default:chest_locked" then
craft_inv:set_list("craft", old_craft_grid)
itemstack:set_name("")
end
end)

The locked chest appears but if you click on it, nothing happens. G:
lf you want, l can disable showing it.
Last edited by Hybrid Dog on Fri Mar 06, 2015 16:20, edited 1 time in total.
 

TeTpaAka
Member
 
Posts: 131
Joined: Sat Dec 28, 2013 21:54

Re: Post your modding questions here

by TeTpaAka » Thu Feb 12, 2015 16:45

I think, writing something into depends.txt forces the Engine to load the mod before yours, so your code would be executed after default registered the items.
 

Hybrid Dog
Member
 
Posts: 2460
Joined: Thu Nov 01, 2012 12:46

Re: Post your modding questions here

by Hybrid Dog » Thu Feb 12, 2015 19:15

TeTpaAka wrote:I think, writing something into depends.txt forces the Engine to load the mod before yours, so your code would be executed after default registered the items.

but if you add a ! after the modname, your mod is loaded after this one l think
 

TeTpaAka
Member
 
Posts: 131
Joined: Sat Dec 28, 2013 21:54

Re: Post your modding questions here

by TeTpaAka » Thu Feb 12, 2015 19:38

Hybrid Dog wrote:but if you add a ! after the modname, your mod is loaded after this one l think


Well, you're right. According to the dev-wiki, this is true. But it doesn't seem to work. I made a quick test and it seems minetest simply ignores the ! and treats it like it was missing.
 

PreviousNext

Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 15 guests

cron