When I run the below script, the minetest.chat appears in the hud and increments, showing the loop is going through the sequence but the player never moves until it reaches the last coords by way of the loop. I've tried an extended counting for loop after setpos to slow it down, but I'm not sure that is having the effect I want either (does doing this cause the engine to be tied up in a way that even though I'm injecting 5 seconds of pause, nothing else occurs?). The CPU activity goes through the roof when I do a triple nested for (x,y,z) so I know that it is computing.
Bottom line: the for loop is looping, but the player doesn't seem to be moving until the loop exits. Enabling the position (F5) confirms that while the loop is reporting xpos increasing, the player coords remain static until the final.
What I'm looking for:
- Can someone give me a working example of sleep
- Does setpos need special care in some way
Thanks,
Bob
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
print '[MAPTELE]LOADED'
minetest.register_chatcommand('MAPTELE',{
description = 'Begin Teleport Routine',
privs = {privs=false},
func = function(name, params)
local player = minetest.env:get_player_by_name(name)
zpos=8000
ypos=20
for xpos = -2000, 2000, 50 do
player:setpos({x=xpos,y=ypos,z=zpos})
minetest.chat_send_player(name, 'Teleported to '..xpos..','..ypos..','..zpos..'')
--sleep(500)
end
end
})