minetest.register_on_joinplayer(function(player) --player object
local pos = player:getpos()
local y = pos.y
end)Thegameboy wrote:Topic: Is there any update function?
Reason: Update function to place code in that updates every tick/frame, to continually check certain conditions? Also, for something like...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_joinplayer(function(player) --player object
local pos = player:getpos()
local y = pos.y
end)
...how do you get the local (or global, could be any kind really) variable outside of the function's local environment and into the script's? The script is loaded when the world starts up but the callback is executed at a later point in time...
More Info: I've checked for a bit for answers to these questions on the glossary for functions but couldn't find anything that applies.
local storage = {}
minetest.register_on_joinplayer(function(player) --player object
local pos = player:getpos()
storage.y = pos.y
end)
sofar wrote:Thegameboy wrote:Topic: Is there any update function?
Reason: Update function to place code in that updates every tick/frame, to continually check certain conditions? Also, for something like...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_joinplayer(function(player) --player object
local pos = player:getpos()
local y = pos.y
end)
...how do you get the local (or global, could be any kind really) variable outside of the function's local environment and into the script's? The script is loaded when the world starts up but the callback is executed at a later point in time...
More Info: I've checked for a bit for answers to these questions on the glossary for functions but couldn't find anything that applies.
Short answer: make a persistent variable outside the `register_on_joinplayer()` function: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 storage = {}
minetest.register_on_joinplayer(function(player) --player object
local pos = player:getpos()
storage.y = pos.y
end)
local storage = {}
minetest.register_on_joinplayer(function(player) --player object
local pos = player:getpos()
storage[player:get_player_name()] = {y = pos.y}
end)
minetest.register_on_leaveplayer(function(player)
storage[player:get_player_name()] = nil
end)
local function checkSomething(player)
local pos = storage[player:get_player_name()]
print(pos.y)
end
local function timerRun()
-- code to run
minetest.after(X, timerRun)
end
minetest.after(X, timerRun)
rubenwardy wrote:sofar wrote:Thegameboy wrote: . . .
Short answer: make a persistent variable outside the `register_on_joinplayer()` function: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 storage = {}
minetest.register_on_joinplayer(function(player) --player object
local pos = player:getpos()
storage.y = pos.y
end)
That'll only work for a single player, much better is: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 storage = {}
minetest.register_on_joinplayer(function(player) --player object
local pos = player:getpos()
storage[player:get_player_name()] = {y = pos.y}
end)
minetest.register_on_leaveplayer(function(player)
storage[player:get_player_name()] = nil
end)
local function checkSomething(player)
local pos = storage[player:get_player_name()]
print(pos.y)
end
to run code every X seconds, the best way is to use minetest.after: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 function timerRun()
-- code to run
minetest.after(X, timerRun)
end
minetest.after(X, timerRun)
Replace X with a number, whole ones work best.
To run every X seconds on a node, use ABMs or a nodetimer.
pithy wrote:How do I count how many nodes are near a node?
rubenwardy wrote:to run code every X seconds, the best way is to use minetest.after: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 function timerRun()
-- code to run
minetest.after(X, timerRun)
end
minetest.after(X, timerRun)
Replace X with a number, whole ones work best.
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.
AnxiousInfusion wrote:rubenwardy wrote:to run code every X seconds, the best way is to use minetest.after: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 function timerRun()
-- code to run
minetest.after(X, timerRun)
end
minetest.after(X, timerRun)
Replace X with a number, whole ones work best.
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.
pithy wrote:How do I search for a node in all loaded blocks?
Undeclared global variable "playedmus" accessed at init.lua (Line 14)"
"Assignment to undeclared global "playedmus" inside a function at init.lua (Line 17)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.
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!
Sirmentio wrote:How do I make a sound play (with minetest.sound_play) for an entire multiplayer server?
Sirmentio wrote:My friend has been getting an error in the logs and were not sure if it's possible: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
Undeclared global variable "playedmus" accessed at init.lua (Line 14)"
"Assignment to undeclared global "playedmus" inside a function at init.lua (Line 17)
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!
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?
drop = "farming:example_food"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,do_custom = function(self)
if self.health <= 10 then
minetest.chat_send_all("Mob health is kinda low, play nice now")
end
end, 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, 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,function table.contains(table, element)
for _, value in pairs(table) do
if value == element then
return true
end
end
return false
endUsers browsing this forum: No registered users and 6 guests