Swap Node On Rightclick Problem

User avatar
octacian
Member
 
Posts: 408
Joined: Mon Dec 21, 2015 22:18
GitHub: octacian
IRC: octacian
In-game: octacian

Swap Node On Rightclick Problem

by octacian » Tue Jul 12, 2016 04:16

I'm trying to use minetest.swap_node to turn a computer on when it is rightclicked. First the computer is set to the bios version, then using minetest.after it is set to the fully on computer after 3.5 seconds. Full code is at the bottom of this post.

The first of my issues, is that on rightclick, I get this error in the chat and the node does not change, though the 3.5 second counter still attempts to run and fails.
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[Server]: Map::setNode(): Not allowing to place CONTENT_IGNORE while trying to replace "digiterm:basic" at (179,6,-51) (block (11,0,-4))


After 3.5 seconds, the game crashes with:
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
2016-07-11 21:00:34: ERROR[Main]: ServerError: Runtime error from mod 'creative' in callback environment_Step(): ...local/share/minetest/games/testing/mods/digiterm/api.lua:21: attempt to index local 'pos' (a nil value)
2016-07-11 21:00:34: ERROR[Main]: stack traceback:
2016-07-11 21:00:34: ERROR[Main]:    ...local/share/minetest/games/testing/mods/digiterm/api.lua:21: in function 'func'
2016-07-11 21:00:34: ERROR[Main]:    /usr/local/share/minetest/builtin/game/misc.lua:34: in function </usr/local/share/minetest/builtin/game/misc.lua:11>
2016-07-11 21:00:34: ERROR[Main]:    /usr/local/share/minetest/builtin/game/register.lua:369: in function </usr/local/share/minetest/builtin/game/register.lua:349>


Swap node 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
-- turn on (not functional)
function digiterm.system.on(pos, node)
  minetest.swap_node({x = pos.x, y = pos.y, z = pos.z}, {name = node.."_bios"}) -- set node to bios
  minetest.after(3.5, function(pos)
    minetest.swap_node({x = pos.x, y = pos.y, z = pos.z}, {name = node.."_on"}) -- set node to on after 5 seconds
  end)
end
-- turn off
function digiterm.system.off(pos, termstring)
  minetest.swap_node(pos, "digiterm:"..termstring.."_bios") -- set node to on
end
-- reboot
function digiterm.system.reboot(pos, termstring)
  digiterm.system.off(pos, termstring)
  digiterm.system.on(pos, termstring)
end


I tried manually entering the info, which worked, but cannot be relied upon when more nodes are added. I can do all this manually within the node register, though I think such a function is more effecient as I will also be using it later. However, though this did work, the node was placed facing the wrong direction. What can I do to fix this?

+ Full Code (API)


+ Node Register using API
God isn't dead!

My Coolest Mods:
MicroExpansion, Working Computers, Interchangeable Hands

Check out my YouTube channel! (octacian)
 

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

Re: Swap Node On Rightclick Problem

by Krock » Tue Jul 12, 2016 07:36

Try this one:
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(3.5, function(pos_)
   minetest.swap_node(pos_, {name = node.."_on"}) -- set node to on after 5 seconds
end, vector.new(pos))

When you define a function with a parameter in "minetest.after", you must also give the parameters to be sent.
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
addi
Member
 
Posts: 605
Joined: Thu Sep 20, 2012 03:16

Re: Swap Node On Rightclick Problem

by addi » Tue Jul 12, 2016 08:19

hmm in api you define the node as minetest.register_node("digiterm:"..termstring,
but in your on() function you want to swap the node {name = node.."_bios"}) . which fails, because that nodename is not registered. the probably correct function might be:

function digiterm.system.on(pos, node)
minetest.swap_node(pos, {name ="digiterm:".. node.."_bios"}) -- set node to bios
minetest.after(3.5, function(pos)
minetest.swap_node(pos, {name ="digiterm:".. node.."_on"}) -- set node to on after 5 seconds
end, pos)
end
 

User avatar
octacian
Member
 
Posts: 408
Joined: Mon Dec 21, 2015 22:18
GitHub: octacian
IRC: octacian
In-game: octacian

Re: Swap Node On Rightclick Problem

by octacian » Tue Jul 12, 2016 15:51

Thanks! Putting both of your responses together fixed the problem. Now for my other problem. How do I use facedir (paramtype2) with swap node?
God isn't dead!

My Coolest Mods:
MicroExpansion, Working Computers, Interchangeable Hands

Check out my YouTube channel! (octacian)
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 5 guests

cron