It isn't a recursive call. You just "push" or "queue" a function to be called later. At the time the next call to your function actually happens, the original call to your function already returned (regardless of the `after` timeout).AnxiousInfusion wrote:Interesting, in making my first timer I wanted to use minetest.after in that way but I was afraid it would hit a recursion limit after continuously calling the function from within itself for long enough. Does lua not suffer from this problem? Regardless, I ended up using minetest.register_globalstep to serve that purpose.
Post your modding questions here
- kaeza
- Moderator
- Posts: 2162
- Joined: Thu Oct 18, 2012 05:00
- GitHub: kaeza
- IRC: kaeza diemartin blaaaaargh
- In-game: kaeza
- Location: Montevideo, Uruguay
- Contact:
Re: Post your modding questions here
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!
Check out my stuff! | Donations greatly appreciated! PayPal
Check out my stuff! | Donations greatly appreciated! PayPal
Re: Post your modding questions here
This is safe.AnxiousInfusion wrote:Interesting, in making my first timer I wanted to use minetest.after in that way but I was afraid it would hit a recursion limit after continuously calling the function from within itself for long enough. Does lua not suffer from this problem? Regardless, I ended up using minetest.register_globalstep to serve that purpose.rubenwardy wrote:to run code every X seconds, the best way is to use minetest.after:
Replace X with a number, whole ones work best.Code: Select all
local function timerRun() -- code to run minetest.after(X, timerRun) end minetest.after(X, timerRun)
Timers that are inserted during the execution of timers are not executed until the next global step ever.
This is done explicitly to allow this usage and to make it safe.
The way it works in detail is that if timers are added to the list of timers, they will never be processed in the current timer execution cycle, because the timer execution code goes from the BACK of the table to the front, and so it will not see new timers until it runs again at a later time.
Please use this minetest.after() "recursion" instead of globalstep if you don't need to be running every globalstep!
- rubenwardy
- Moderator
- Posts: 6978
- Joined: Tue Jun 12, 2012 18:11
- GitHub: rubenwardy
- IRC: rubenwardy
- In-game: rubenwardy
- Location: Bristol, United Kingdom
- Contact:
Re: Post your modding questions here
It doesn't call itself from within itself. It adds the function onto a priority queue to be run again
Re: Post your modding questions here
How do I search for a node in all loaded blocks?
- Hybrid Dog
- Member
- Posts: 2836
- Joined: Thu Nov 01, 2012 12:46
- GitHub: HybridDog
You could use lbm to catch specific nodes when they get loaded.pithy wrote:How do I search for a node in all loaded blocks?
Re: Post your modding questions here
How do I make a sound play (with minetest.sound_play) for an entire multiplayer server?
My friend has been getting an error in the logs and were not sure if it's possible:
My friend has been getting an error in the logs and were not sure if it's possible:
Code: Select all
Undeclared global variable "playedmus" accessed at init.lua (Line 14)"
"Assignment to undeclared global "playedmus" inside a function at init.lua (Line 17)
Mod List: PlayMus Cooked Stick
- ErrorNull
- Member
- Posts: 274
- Joined: Thu Mar 03, 2016 00:43
- GitHub: ErrorNull0
Re: Post your modding questions here
hello everyone. i have two modding questions:
#1. how can i replicate the on-screen effect of flashing color when something happens to the player? ex. I've made a mod that incorporates player exhaustion states.. and would like the screen to flash different color like white when player is exhausted. would this be done via huds? if there is existing mod as an example, I'd be happy to learn from that.
I know that i can fake the effect by reducing the player's hp by 1 and giving it back. But i don't want to hinge my effect up the back of an existing (and important) mechanism like the player's health. Plus i want to control the color the of the flashing.
#2. i want to pretty particle effects shower over the player upon consumption of some magic potions... because, you know... all potions have to do that right?! can someone direct me to api or mod example on how to do this... or even some basics on how to call particles into minetest? thanks!
#1. how can i replicate the on-screen effect of flashing color when something happens to the player? ex. I've made a mod that incorporates player exhaustion states.. and would like the screen to flash different color like white when player is exhausted. would this be done via huds? if there is existing mod as an example, I'd be happy to learn from that.
I know that i can fake the effect by reducing the player's hp by 1 and giving it back. But i don't want to hinge my effect up the back of an existing (and important) mechanism like the player's health. Plus i want to control the color the of the flashing.
#2. i want to pretty particle effects shower over the player upon consumption of some magic potions... because, you know... all potions have to do that right?! can someone direct me to api or mod example on how to do this... or even some basics on how to call particles into minetest? thanks!
Re: Post your modding questions here
Make a HUD element that is fullscreen and contains a semi-transparent texture.ErrorNull wrote:hello everyone. i have two modding questions:
#1. how can i replicate the on-screen effect of flashing color when something happens to the player? ex. I've made a mod that incorporates player exhaustion states.. and would like the screen to flash different color like white when player is exhausted. would this be done via huds? if there is existing mod as an example, I'd be happy to learn from that.
I know that i can fake the effect by reducing the player's hp by 1 and giving it back. But i don't want to hinge my effect up the back of an existing (and important) mechanism like the player's health. Plus i want to control the color the of the flashing.
read the entire section from here:ErrorNull wrote:#2. i want to pretty particle effects shower over the player upon consumption of some magic potions... because, you know... all potions have to do that right?! can someone direct me to api or mod example on how to do this... or even some basics on how to call particles into minetest? thanks!
https://github.com/minetest/minetest/bl ... .txt#L2298
Re: Post your modding questions here
For every player on the server, play a sound exclusively to that player.Sirmentio wrote:How do I make a sound play (with minetest.sound_play) for an entire multiplayer server?
put `local` in front of the place where `playedmus` is first defined or used.Sirmentio wrote:My friend has been getting an error in the logs and were not sure if it's possible:Code: Select all
Undeclared global variable "playedmus" accessed at init.lua (Line 14)" "Assignment to undeclared global "playedmus" inside a function at init.lua (Line 17)
- swordpaint12
- Member
- Posts: 191
- Joined: Sat Aug 22, 2015 00:50
- In-game: [swordpaint12][Belching_Balladeer]
- Location: Foobass, isle of Atlantis, castle of Bardvendelle
Re: Post your modding questions here
A HUD question. Suppose I wanted to change the hud at certain times so that a certain picture would be on the screen for an amount of time. Kind of like the bubbles. How would I do that? Thanks!
God's not dead; remember that!
Yay for MT! No MC here!
I am a human. I'm younger than 100 years old.
I've been playing Minetest since December 2014.
I'm amazed that I haven't been on here in so long! My latest minetest accomplishment was mining by hand (well, as close as you can get in a computer game) a circle 30 blocks in diameter. It took forever but it's pretty cool.
Yay for MT! No MC here!
I am a human. I'm younger than 100 years old.
I've been playing Minetest since December 2014.
I'm amazed that I haven't been on here in so long! My latest minetest accomplishment was mining by hand (well, as close as you can get in a computer game) a circle 30 blocks in diameter. It took forever but it's pretty cool.
- kaeza
- Moderator
- Posts: 2162
- Joined: Thu Oct 18, 2012 05:00
- GitHub: kaeza
- IRC: kaeza diemartin blaaaaargh
- In-game: kaeza
- Location: Montevideo, Uruguay
- Contact:
Re: Post your modding questions here
The function `player:hud_add` returns the ID of the HUD item. Save that somewhere, then just call `player:hud_change(id, "someparam", somevalue)`. See the function's description in `lua_api.txt`.swordpaint12 wrote:A HUD question. Suppose I wanted to change the hud at certain times so that a certain picture would be on the screen for an amount of time. Kind of like the bubbles. How would I do that? Thanks!
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!
Check out my stuff! | Donations greatly appreciated! PayPal
Check out my stuff! | Donations greatly appreciated! PayPal
- swordpaint12
- Member
- Posts: 191
- Joined: Sat Aug 22, 2015 00:50
- In-game: [swordpaint12][Belching_Balladeer]
- Location: Foobass, isle of Atlantis, castle of Bardvendelle
Re: Post your modding questions here
Thank you!
Okay, new question. In the default mod in the minetest_game, which .lua file contains all the coding for the apple? I want to figure out how you put it down.
Okay, new question. In the default mod in the minetest_game, which .lua file contains all the coding for the apple? I want to figure out how you put it down.
God's not dead; remember that!
Yay for MT! No MC here!
I am a human. I'm younger than 100 years old.
I've been playing Minetest since December 2014.
I'm amazed that I haven't been on here in so long! My latest minetest accomplishment was mining by hand (well, as close as you can get in a computer game) a circle 30 blocks in diameter. It took forever but it's pretty cool.
Yay for MT! No MC here!
I am a human. I'm younger than 100 years old.
I've been playing Minetest since December 2014.
I'm amazed that I haven't been on here in so long! My latest minetest accomplishment was mining by hand (well, as close as you can get in a computer game) a circle 30 blocks in diameter. It took forever but it's pretty cool.
Re: Post your modding questions here
Hopefully a quick question:
I am trying to edit the default farming mod to add a new crop. I have register_plant and register_craftitem for the crop in the init file, and I can plant the seed and watch the crop grow - but there is no drop when I harvest it. According to the commented init file, the register_craftitem is for registering the harvest - so why is it not dropping the item?
I am trying to edit the default farming mod to add a new crop. I have register_plant and register_craftitem for the crop in the init file, and I can plant the seed and watch the crop grow - but there is no drop when I harvest it. According to the commented init file, the register_craftitem is for registering the harvest - so why is it not dropping the item?
- swordpaint12
- Member
- Posts: 191
- Joined: Sat Aug 22, 2015 00:50
- In-game: [swordpaint12][Belching_Balladeer]
- Location: Foobass, isle of Atlantis, castle of Bardvendelle
Re: Post your modding questions here
Did you code the line that says drop item?KCoombes wrote:Hopefully a quick question:
I am trying to edit the default farming mod to add a new crop. I have register_plant and register_craftitem for the crop in the init file, and I can plant the seed and watch the crop grow - but there is no drop when I harvest it. According to the commented init file, the register_craftitem is for registering the harvest - so why is it not dropping the item?
Code: Select all
drop = "farming:example_food"
God's not dead; remember that!
Yay for MT! No MC here!
I am a human. I'm younger than 100 years old.
I've been playing Minetest since December 2014.
I'm amazed that I haven't been on here in so long! My latest minetest accomplishment was mining by hand (well, as close as you can get in a computer game) a circle 30 blocks in diameter. It took forever but it's pretty cool.
Yay for MT! No MC here!
I am a human. I'm younger than 100 years old.
I've been playing Minetest since December 2014.
I'm amazed that I haven't been on here in so long! My latest minetest accomplishment was mining by hand (well, as close as you can get in a computer game) a circle 30 blocks in diameter. It took forever but it's pretty cool.
Re: Post your modding questions here
Hopefully this can be easy to understand:
on mobs redo, how could I m,ake an event/function occur upon the mob being punched? Aswell as this, how could I make an event occur when the mob spawns? Thank you in advance
Edit: one more thing (I PROMISE!) is it possible to do an event onjce the mob is down certain health?
on mobs redo, how could I m,ake an event/function occur upon the mob being punched? Aswell as this, how could I make an event occur when the mob spawns? Thank you in advance
Edit: one more thing (I PROMISE!) is it possible to do an event onjce the mob is down certain health?
Mod List: PlayMus Cooked Stick
Re: Post your modding questions here
Using the do_custom function within the mob definition gives you a lot of freedom when creating customised features, e.g.
when Evil Bonny is spawned into the world it displays a message in chat only once:
...or... if health is at a certain level then it shows a message:
when Evil Bonny is spawned into the world it displays a message in chat only once:
Code: Select all
do_custom = function(self)
if not self.evil_bonny then
minetest.chat_send_all(">>> Evil Bonny has been unleashed on this world <<<")
self.evil_bonny = 1
end
end,
Code: Select all
do_custom = function(self)
if self.health <= 10 then
minetest.chat_send_all("Mob health is kinda low, play nice now")
end
end,
Re: Post your modding questions here
Thanks! I'm very grateful, the context here is that I'm trying to create a boss event for a private server with my friends, now thinking ab out it, is it possible with this to get this theoretical evil bunny's position? Thank you in advance!
Mod List: PlayMus Cooked Stick
Re: Post your modding questions here
Code: Select all
on_rightclick = function(pos, node, puncher)
local nodes = {}
do
local start = minetest.find_nodes_in_area({x = pos.x - 1, y = pos.y - 1, z = pos.z - 1}, {x = pos.x + 1, y = pos.y + 1, z = pos.z + 1}, {"group:wireworld"})
for k,v in pairs(start) do
table.insert(nodes, v)
end
end
local total = {}
for k,v in pairs(nodes) do table.insert(total, v) end
repeat
local next = {}
for k,v in pairs(nodes) do
local find = minetest.find_nodes_in_area({x = v.x - 1, y = v.y - 1, z = v.z - 1}, {x = v.x + 1, y = v.y + 1, z = v.z + 1}, {"group:wireworld"})
for k,v in pairs(find) do
if not table.contains(total, v) then
local meta = minetest.get_meta(v)
table.insert(next, v)
end
end
end
local nodes = {}
for k,v in pairs(next) do table.insert(nodes, v) end
for k,v in pairs(nodes) do table.insert(total, v) end
local count = 0
for _ in pairs(nodes) do count = count + 1 end
until count == 0
for k,v in pairs(total) do
local meta = minetest.get_meta(v)
meta:set_string("wireworld", "stop")
end
minetest.swap_node(pos, {name = "wireworld:wireworld_off"})
end,
My suspicion is count never reaches 0.
Re: Post your modding questions here
I simplified it to this but it still does the same thing
and the table.contains function is
Code: Select all
on_rightclick = function(pos, node, puncher)
local nodes = minetest.find_nodes_in_area({x = pos.x - 1, y = pos.y - 1, z = pos.z - 1}, {x = pos.x + 1, y = pos.y + 1, z = pos.z + 1}, {"group:wireworld"})
for i,v in ipairs(nodes) do
local find = minetest.find_nodes_in_area({x = v.x - 1, y = v.y - 1, z = v.z - 1}, {x = v.x + 1, y = v.y + 1, z = v.z + 1}, {"group:wireworld"})
for i,v in ipairs(find) do
if not table.contains(nodes, v) then
local meta = minetest.get_meta(v)
meta:set_string("wireworld", "stop")
nodes[#nodes+1] = v
end
end
end
minetest.swap_node(pos, {name = "wireworld:wireworld_off"})
end,
Code: Select all
function table.contains(table, element)
for _, value in pairs(table) do
if value == element then
return true
end
end
return false
end
Re: Post your modding questions here
to late my brain figured it out
Re: Post your modding questions here
How should I register a node, so that it disappears on digging without appearing in player's inventory and without dropping anything?
- azekill_DIABLO
- Member
- Posts: 7507
- Joined: Wed Oct 29, 2014 20:05
- GitHub: azekillDIABLO
- In-game: azekill_DIABLO
- Location: OMICRON
- Contact:
Re: Post your modding questions here
Code: Select all
minetest.register_node("fruitgrow:apples", {
description = "Apples",
paramtype = "light",
tiles = {"default_apple.png^default_leaves.png^default_torch_animated.png"},
drawtype = "allfaces_optional",
is_ground_content = false,
groups = {dig_immediate=3, leafdecay=1, leaves=1},
drop = {
max_items = 0,
},
})
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!
DMs are always open if you want to get in touch!
Re: Post your modding questions here
azekill_DIABLO, thank you!
I wrote "drops = " instead of "drop = ", and couldn't understand why it doesn't work.
I wrote "drops = " instead of "drop = ", and couldn't understand why it doesn't work.
init.lua error can't figure it out please help.
Ok so I am attempting to make my own mod and it is one that is adding a few more "modern" weapons to the game. This is the error I get
init.lua:4: '<eof>' expected near 'end'
First my init.lua looks like this
and I do have a separate lua called guns.lua and it looks like this
init.lua:4: '<eof>' expected near 'end'
First my init.lua looks like this
Code: Select all
local modpath = minetest.get_modpath(minetest.get_current_modname())
dofile(modpath.."/guns.lua")
end
Code: Select all
modernguns:register_weapon("modernguns:mp5holo", {
description = "MP5(ranged damage 3|max ammo 30)",
inventory_image = "modernguns_mp5holo.png",
rounds = 10,
shots = 3,
spec = {
range = 285,
step = 20,
tool_caps = {full_punch_interval=0.125, damage_groups={fleshy=3}},
groups = {snappy=3, fleshy=3, oddly_breakable_by_hand=3},
sound = "modernguns_mp5",
particle = "modernguns_bullet.png",
},
})
Re: Post your modding questions here
Remove "end" in the first file.
Who is online
Users browsing this forum: No registered users and 6 guests