Post your modding questions here

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

by Hybrid Dog » Fri Feb 10, 2017 10:33

ABJ, you can use the on_place, on_construct etc. in the node definition.
 

ozkur
Member
 
Posts: 180
Joined: Wed Oct 07, 2015 20:59
In-game: ozkur or XoRoUZ

Re: Post your modding questions here

by ozkur » Fri Feb 10, 2017 21:33

Sorry that this is the derpiest of all derpy and stupid questions:

How do I upload a mod to the forums?
Biplanes! 'Nuff said

I am a native English speaker, Ich spreche kein Deuscht, mais je parle un pue français.
 

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

by Hybrid Dog » Fri Feb 10, 2017 22:41

ozkur, there are lots of ways to upload a mod, e.g. here's the init.lua of my version of the drippingwater mod as png:
Image
(it's grey because ascii)
Attachments
tmp.png
tmp.png (2.65 KiB) Viewed 5698 times
 

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

Re: Post your modding questions here

by BrunoMine » Fri Feb 10, 2017 23:16

Hello guys.
I'm having trouble for detect objects in an area. I have used the minetest.get_objects_inside_radius method, but it does not work correctly. Sometimes it does not work, usually when I'm at a disancia of approximately 20 blocks.
Is there any more consistent way to perform this verification?
 

ozkur
Member
 
Posts: 180
Joined: Wed Oct 07, 2015 20:59
In-game: ozkur or XoRoUZ

Re:

by ozkur » Fri Feb 10, 2017 23:29

Hybrid Dog wrote:ozkur, there are lots of ways to upload a mod, e.g. here's the init.lua of my version of the drippingwater mod as png:
Image
(it's grey because ascii)

Thanks for trying, but I still am confused.
Are you saying I do something like turn the entire folder into a .png file?
Biplanes! 'Nuff said

I am a native English speaker, Ich spreche kein Deuscht, mais je parle un pue français.
 

User avatar
kaeza
Member
 
Posts: 2141
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

Re: Post your modding questions here

by kaeza » Sat Feb 11, 2017 03:39

ozkur wrote:Sorry that this is the derpiest of all derpy and stupid questions:

How do I upload a mod to the forums?

Use an archiving program(*) to compress your folder in a ZIP file, create a new topic for it in the WIP Mods subforum(**), and upload the ZIP file as an attachment ("Upload attachment" tab under the posting text box).

(*) Windows comes with support to compress folders, or you can use an external program like 7-zip.
(**) See also the guidelines for mod releases.
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 | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

ozkur
Member
 
Posts: 180
Joined: Wed Oct 07, 2015 20:59
In-game: ozkur or XoRoUZ

Re: Post your modding questions here

by ozkur » Sat Feb 11, 2017 12:55

kaeza wrote:
ozkur wrote:Sorry that this is the derpiest of all derpy and stupid questions:

How do I upload a mod to the forums?

Use an archiving program(*) to compress your folder in a ZIP file, create a new topic for it in the WIP Mods subforum(**), and upload the ZIP file as an attachment ("Upload attachment" tab under the posting text box).

(*) Windows comes with support to compress folders, or you can use an external program like 7-zip.
(**) See also the guidelines for mod releases.

Thanks!
Biplanes! 'Nuff said

I am a native English speaker, Ich spreche kein Deuscht, mais je parle un pue français.
 

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

Re: Post your modding questions here

by Hybrid Dog » Sat Feb 11, 2017 21:00

BrunoMine, you can only get active objects. Maybe you need to forceload some chunks.
 

User avatar
orwell
Member
 
Posts: 467
Joined: Wed Jun 24, 2015 18:45
GitHub: orwell96
In-game: orwell

Re: Post your modding questions here

by orwell » Sat Feb 11, 2017 21:27

Hybrid Dog wrote:BrunoMine, you can only get active objects. Maybe you need to forceload some chunks.

Are you scanning for objects that your mod defines? Then let them save their last active position in a table and just search this yourself. Then just forceload that area(*)
#screwminetestsbuggyobjectmanagementsystem
To work consistently, that table has to be saved on shutdown.

(*) use that forceload anchors library, it handles forceloads better than minetest's internal.
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...
 

User avatar
burli
Member
 
Posts: 1313
Joined: Fri Apr 10, 2015 13:18

Re: Post your modding questions here

by burli » Mon Feb 13, 2017 06:00

How can I place a locked chest and a key to unlock to a map from a script?
 

User avatar
GreenDimond
Member
 
Posts: 460
Joined: Wed Oct 28, 2015 01:26
GitHub: GreenXenith
IRC: GreenDimond
In-game: GreenDimond

Re: Post your modding questions here

by GreenDimond » Tue Feb 14, 2017 02:17

I seem to be having trouble with registering 2 'on_punch' to the same node.
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
on_punch = function(pos, node, player, pointed_thing)
      local inv = player:get_inventory()
      inv:add_item("main", "modname:node")
on_punch = function(pos, node, puncher, pointed_thing)
      minetest.set_node(pos, {name = "modename:othernode", param2 = node.param2})
   end
   end

This is only one example of what I have tried. In this particular case, only the first function happens. Other times it was just the latter. I want both to happen. How do I do this?
I am Green. I tend to binge-post. "All of this over a 16x16 representation of a cartoon cat ?!?! what has this world come to..." -TenPlus1, 2017.
Diz mah mods! :D ↑ github.com/minetest/minetest_game/issues/1647#issuecomment-288134572 ↑
Sand Plus - Tac Nayn - Waffles - Coming Soon: Caverealms Plus
 

sofar
Member
 
Posts: 781
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: Post your modding questions here

by sofar » Tue Feb 14, 2017 04:02

GreenDimond wrote:I seem to be having trouble with registering 2 'on_punch' to the same node.


You can't. Combine the code into one function.
 

User avatar
GreenDimond
Member
 
Posts: 460
Joined: Wed Oct 28, 2015 01:26
GitHub: GreenXenith
IRC: GreenDimond
In-game: GreenDimond

Re: Post your modding questions here

by GreenDimond » Tue Feb 14, 2017 04:06

sofar wrote:
GreenDimond wrote:I seem to be having trouble with registering 2 'on_punch' to the same node.


You can't. Combine the code into one function.

I have realized this, but now I am having trouble with that aswell. I will post here if I cant fix.
I am Green. I tend to binge-post. "All of this over a 16x16 representation of a cartoon cat ?!?! what has this world come to..." -TenPlus1, 2017.
Diz mah mods! :D ↑ github.com/minetest/minetest_game/issues/1647#issuecomment-288134572 ↑
Sand Plus - Tac Nayn - Waffles - Coming Soon: Caverealms Plus
 

User avatar
GreenDimond
Member
 
Posts: 460
Joined: Wed Oct 28, 2015 01:26
GitHub: GreenXenith
IRC: GreenDimond
In-game: GreenDimond

Re: Post your modding questions here

by GreenDimond » Tue Feb 14, 2017 04:45

Still working on this, but apparently I still cant seem to be able to lua.
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
   get_item = function ()
--        function(pos, node, player, pointed_thing)
        local inv = player:get_inventory()
        inv:add_item("main", "modname:nodedame")
    end,
    replace_model = function ()
--        function(pos, node, puncher, pointed_thing)
        minetest.set_node(pos, {name = "modname:othernodename", param2 = node.param2})
    end,
    do_punch = function do_punch()
      get_item()
      replace_model()
   end,
    on_punch = do_punch

commenting the function(pos, blablabla) out allows the mod to run. Otherwise it wants '<name>' at the first function(pos, node, player, blablabla). No idea what to do.
I am Green. I tend to binge-post. "All of this over a 16x16 representation of a cartoon cat ?!?! what has this world come to..." -TenPlus1, 2017.
Diz mah mods! :D ↑ github.com/minetest/minetest_game/issues/1647#issuecomment-288134572 ↑
Sand Plus - Tac Nayn - Waffles - Coming Soon: Caverealms Plus
 

User avatar
GreenDimond
Member
 
Posts: 460
Joined: Wed Oct 28, 2015 01:26
GitHub: GreenXenith
IRC: GreenDimond
In-game: GreenDimond

Re: Post your modding questions here

by GreenDimond » Tue Feb 14, 2017 05:07

This code lets the game start and actually does something when I punch the node. My game crashes.
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
   get_item = function (player)
--      function(pos, node, player, pointed_thing)
      local inv = player:get_inventory()
      inv:add_item("main", "modname:nodename")
   end,
   replace_model = function (pos, node)
--      function(pos, node, puncher, pointed_thing)
      minetest.set_node(pos, {name = "modname:othernodename", param2 = node.param2})
   end,

   on_punch = function (pos, node, player, pointed_thing)
      node.get_item(player)
      node.replace_model(pos, node)
   end
})

I think I am about 90% of the way there, but am now moving as fast as a brick. So wat do now?
error 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
2017-02-13 21:02:12: ERROR[Main]: ServerError: Lua: Runtime error from mod 'modname' in callback node_on_punch(): /home/alex/.minetest/mods/modname/nodes.lua:68: attempt to call field 'get_item' (a nil value)
2017-02-13 21:02:12: ERROR[Main]: stack traceback:
2017-02-13 21:02:12: ERROR[Main]:    /home/alex/.minetest/mods/modname/nodes.lua:68: in function </home/alex/.minetest/mods/modname/nodes.lua:67>

In case you are wondering, I use "modname" and "nodename" and stuff to keep the mod a secret :P
I am Green. I tend to binge-post. "All of this over a 16x16 representation of a cartoon cat ?!?! what has this world come to..." -TenPlus1, 2017.
Diz mah mods! :D ↑ github.com/minetest/minetest_game/issues/1647#issuecomment-288134572 ↑
Sand Plus - Tac Nayn - Waffles - Coming Soon: Caverealms Plus
 

User avatar
D00Med
Member
 
Posts: 712
Joined: Sat Feb 07, 2015 22:49
GitHub: D00Med

Re: Post your modding questions here

by D00Med » Tue Feb 14, 2017 09:49

I have a maths related question.
I can make an entity rotate so that it matches the player's yaw. Now I'm trying to make the entity 'catch-up' to the player's yaw. There's a problem with this though. When the player's yaw crosses 0/2pi the difference between the player's yaw and the entity's yaw makes the entity spin around in the opposite direction(the long way around).
At the moment the rotation of the entity is divided into four steps. The higher the number of steps it takes to catch up, the more noticeable the problem 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 target_yaw = yaw+math.pi+math.pi/2
local entity_yaw = entity.object:getyaw()
if target_yaw <= 6.2 and target_yaw >= 0.2 then --this is the only method I have to stop the problem
   entity.object:setyaw(entity_yaw+(target_yaw-entity_yaw)/4)
   else
   entity.object:setyaw(target_yaw)
end

^ yaw is the player's yaw

How can I do this so that the shortest difference is used?

@GreenDimond:
Have you tried just using get_item and replace_model rather than node.get_item and node.replace_model?
Look! I have a signature :]
My subgame: https://forum.minetest.net/viewtopic.php?f=15&t=14051#p207242
dmobs2 is coming...
 

User avatar
orwell
Member
 
Posts: 467
Joined: Wed Jun 24, 2015 18:45
GitHub: orwell96
In-game: orwell

Re: Post your modding questions here

by orwell » Tue Feb 14, 2017 13:45

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
-- before the node definition, make these as local functions
local function get_item(player)
      local inv = player:get_inventory()
      inv:add_item("main", "modname:nodename")
end
local function replace_model(pos, node)
--      function(pos, node, puncher, pointed_thing)
      minetest.set_node(pos, {name = "modname:othernodename", param2 = node.param2})
end
minetest.register_node("name",{
-- ...
   on_punch = function (pos, node, player, pointed_thing)
      get_item(player)
      replace_model(pos, node)
   end
-- ...
})

get_item and replace_model are functions local to the lua file. Because the node is defined in this scope, you can call the functions from there.
Also, 'node' is not ' node definition'.
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...
 

User avatar
orwell
Member
 
Posts: 467
Joined: Wed Jun 24, 2015 18:45
GitHub: orwell96
In-game: orwell

Re: Post your modding questions here

by orwell » Tue Feb 14, 2017 13:48

D00Med wrote:I have a maths related question.
I can make an entity rotate so that it matches the player's yaw. Now I'm trying to make the entity 'catch-up' to the player's yaw. There's a problem with this though. When the player's yaw crosses 0/2pi the difference between the player's yaw and the entity's yaw makes the entity spin around in the opposite direction(the long way around).
At the moment the rotation of the entity is divided into four steps. The higher the number of steps it takes to catch up, the more noticeable the problem 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 target_yaw = yaw+math.pi+math.pi/2
local entity_yaw = entity.object:getyaw()
if target_yaw <= 6.2 and target_yaw >= 0.2 then --this is the only method I have to stop the problem
   entity.object:setyaw(entity_yaw+(target_yaw-entity_yaw)/4)
   else
   entity.object:setyaw(target_yaw)
end

^ yaw is the player's yaw

How can I do this so that the shortest difference is used?

@GreenDimond:
Have you tried just using get_item and replace_model rather than node.get_item and node.replace_model?

I have a function advtrains.minAngleDiffRad in advtrains/helpers.lua. maybe this is helpful.
Returns how far to rotate from first angle in which direction to reach second angle
Link is in signature
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...
 

User avatar
DS-minetest
Member
 
Posts: 707
Joined: Thu Jun 19, 2014 19:49
GitHub: DS-Minetest
In-game: DS

Re: Post your modding questions here

by DS-minetest » Tue Feb 14, 2017 15:15

@GreenDimond: Try it 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
   get_item = function(pos, node, player)
      local inv = player:get_inventory()
      inv:add_item("main", "modname:nodename")
   end,
   replace_model = function(pos, node)
      minetest.set_node(pos, {name = "modname:othernodename", param2 = node.param2})
   end,

   on_punch = function(pos, node, player, pointed_thing)
      node.get_item(player)
      node.replace_model(pos, node)
   end
})

Perhaps it will work.
Btw where is this code? Is it in minetest.reister_node ?
Do not call me -minetest.
Call me DS or DS-minetest.
I am German, so you don't have to pm me English if you are also German.
The background is a lie.
 

User avatar
GreenDimond
Member
 
Posts: 460
Joined: Wed Oct 28, 2015 01:26
GitHub: GreenXenith
IRC: GreenDimond
In-game: GreenDimond

Re: Post your modding questions here

by GreenDimond » Tue Feb 14, 2017 16:26

@D00Med: Yes, I believe I have tried that.

@DS-minetest: I tried your answer before orwells (just cuz it was a copy/past). I get 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
2017-02-14 08:16:04: ERROR[Main]: ServerError: Lua: Runtime error from mod 'modname' in callback node_on_punch(): /home/alex/.minetest/mods/modname/nodes.lua:66: attempt to call field 'get_item' (a nil value)
2017-02-14 08:16:04: ERROR[Main]: stack traceback:
2017-02-14 08:16:04: ERROR[Main]:    /home/alex/.minetest/mods/modname/nodes.lua:66: in function </home/alex/.minetest/mods/modname/nodes.lua:65>

For reference, the first line of your code is line 57. Yes, this code is inside a register_node.

@orwell: :D :D :D It worked! So what I get from that, is whenever I want to combine 2 functions for one node, I must define the functions outside the register_node. Is this correct?
I am Green. I tend to binge-post. "All of this over a 16x16 representation of a cartoon cat ?!?! what has this world come to..." -TenPlus1, 2017.
Diz mah mods! :D ↑ github.com/minetest/minetest_game/issues/1647#issuecomment-288134572 ↑
Sand Plus - Tac Nayn - Waffles - Coming Soon: Caverealms Plus
 

User avatar
orwell
Member
 
Posts: 467
Joined: Wed Jun 24, 2015 18:45
GitHub: orwell96
In-game: orwell

Re: Post your modding questions here

by orwell » Tue Feb 14, 2017 16:57

Everything inside {} is a table definition. Statements like key=value, declare a new table entry.
So, if you define replace_model inside the {}, they become a member of the definition table. You can't access values of a table from functions defined in that table unless you can reference the whole table object, which in your case would be the node definition (which is stored in minetest.registered_nodes).
In contrast, you can always call functions that are identified in the global or local namespace.
Answer to question: basically yes, but depends on the use case
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...
 

User avatar
GreenDimond
Member
 
Posts: 460
Joined: Wed Oct 28, 2015 01:26
GitHub: GreenXenith
IRC: GreenDimond
In-game: GreenDimond

Re: Post your modding questions here

by GreenDimond » Tue Feb 14, 2017 17:03

Ok :D
New question:
I am defining a tool that replaces a model, but when it does, the model has a fixed rotation. I want it to be the same rotation as the node the player is punching.
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
   on_use = function(itemstack, user, pointed_thing)

      if pointed_thing.type ~= "node" then
         return
      end

      local pos = pointed_thing.under
      local pname = user:get_player_name()

      if minetest.is_protected(pos, pname) then
         minetest.record_protection_violation(pos, pname)
         return
      end

      local node = minetest.get_node(pos).name

      if node == "modename:node1" then

--         minetest.swap_node(pos, {name = "modename:node2"})
         minetest.set_node(pos, {name = "modename:node2", param2 = node.param2})

         return itemstack
      end

   end,

The commented out line was the original one, but I don't think I want to swap, so I used the set_node.
This code currently makes it so no matter which direction the original node is facing, the new node faces in a fixed direction (which I don't want). How do I make it the same orientation as the node the player replaced?
I am Green. I tend to binge-post. "All of this over a 16x16 representation of a cartoon cat ?!?! what has this world come to..." -TenPlus1, 2017.
Diz mah mods! :D ↑ github.com/minetest/minetest_game/issues/1647#issuecomment-288134572 ↑
Sand Plus - Tac Nayn - Waffles - Coming Soon: Caverealms Plus
 

User avatar
orwell
Member
 
Posts: 467
Joined: Wed Jun 24, 2015 18:45
GitHub: orwell96
In-game: orwell

Re: Post your modding questions here

by orwell » Tue Feb 14, 2017 18:28

I guess you get an error "attempt to index a string"
Your local var "node" is misleading, since it's a node name and not a node table representation.

local node=minetest.get_node(pos)
If node.name=="whatever" then
mt.set_node(pos, {name="whatever", param2=node.param2})

Param2 is the value that stores the rotation of the node, you need to keep it when you set the new node.
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...
 

User avatar
GreenDimond
Member
 
Posts: 460
Joined: Wed Oct 28, 2015 01:26
GitHub: GreenXenith
IRC: GreenDimond
In-game: GreenDimond

Re: Post your modding questions here

by GreenDimond » Tue Feb 14, 2017 18:30

Is that not the code I currently have?
We could talk about this in IRC if you like (#minetest).
I am Green. I tend to binge-post. "All of this over a 16x16 representation of a cartoon cat ?!?! what has this world come to..." -TenPlus1, 2017.
Diz mah mods! :D ↑ github.com/minetest/minetest_game/issues/1647#issuecomment-288134572 ↑
Sand Plus - Tac Nayn - Waffles - Coming Soon: Caverealms Plus
 

User avatar
orwell
Member
 
Posts: 467
Joined: Wed Jun 24, 2015 18:45
GitHub: orwell96
In-game: orwell

Re: Post your modding questions here

by orwell » Tue Feb 14, 2017 18:47

GreenDimond wrote:Is that not the code I currently have?
We could talk about this in IRC if you like (#minetest).

No not exactly. The .name went elsewhere. IRC not today.
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...
 

User avatar
GreenDimond
Member
 
Posts: 460
Joined: Wed Oct 28, 2015 01:26
GitHub: GreenXenith
IRC: GreenDimond
In-game: GreenDimond

Re: Post your modding questions here

by GreenDimond » Tue Feb 14, 2017 18:49

orwell wrote:
GreenDimond wrote:Is that not the code I currently have?
We could talk about this in IRC if you like (#minetest).

No not exactly. The .name went elsewhere. IRC not today.

I see...trying this.
EDIT: It works! Thanks!
I am Green. I tend to binge-post. "All of this over a 16x16 representation of a cartoon cat ?!?! what has this world come to..." -TenPlus1, 2017.
Diz mah mods! :D ↑ github.com/minetest/minetest_game/issues/1647#issuecomment-288134572 ↑
Sand Plus - Tac Nayn - Waffles - Coming Soon: Caverealms Plus
 

User avatar
GreenDimond
Member
 
Posts: 460
Joined: Wed Oct 28, 2015 01:26
GitHub: GreenXenith
IRC: GreenDimond
In-game: GreenDimond

Re: Post your modding questions here

by GreenDimond » Tue Feb 14, 2017 19:28

Functions hate me :(
I am trying to get a simple function to work, and it doesn't.
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() replace_donemodel(pos, node)
      minetest.set_node(pos, {name = "modname:nodename", param2 = node.param2})
   end,
   on_place = {
      minetest.after(2.0, replace_donemodel)}

This is inside a register_node.
I want the model to be replaced 2 seconds after it is placed (or set).
I have tried registering the function outside the register node aswell, but nothing works. What do?
EDIT: Fixed.
I am Green. I tend to binge-post. "All of this over a 16x16 representation of a cartoon cat ?!?! what has this world come to..." -TenPlus1, 2017.
Diz mah mods! :D ↑ github.com/minetest/minetest_game/issues/1647#issuecomment-288134572 ↑
Sand Plus - Tac Nayn - Waffles - Coming Soon: Caverealms Plus
 

sofar
Member
 
Posts: 781
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: Post your modding questions here

by sofar » Tue Feb 14, 2017 21:01

GreenDimond wrote:This code lets the game start and actually does something when I punch the node. My game crashes.
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
   get_item = function (player)
--      function(pos, node, player, pointed_thing)
      local inv = player:get_inventory()
      inv:add_item("main", "modname:nodename")
   end,
   replace_model = function (pos, node)
--      function(pos, node, puncher, pointed_thing)
      minetest.set_node(pos, {name = "modname:othernodename", param2 = node.param2})
   end,

   on_punch = function (pos, node, player, pointed_thing)
      node.get_item(player)
      node.replace_model(pos, node)
   end
})

I think I am about 90% of the way there, but am now moving as fast as a brick. So wat do now?
error 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
2017-02-13 21:02:12: ERROR[Main]: ServerError: Lua: Runtime error from mod 'modname' in callback node_on_punch(): /home/alex/.minetest/mods/modname/nodes.lua:68: attempt to call field 'get_item' (a nil value)
2017-02-13 21:02:12: ERROR[Main]: stack traceback:
2017-02-13 21:02:12: ERROR[Main]:    /home/alex/.minetest/mods/modname/nodes.lua:68: in function </home/alex/.minetest/mods/modname/nodes.lua:67>

In case you are wondering, I use "modname" and "nodename" and stuff to keep the mod a secret :P



get_item() is declared as a member of the node definition. `node` is not a `node definition`.

you probably want to do something like this instead:

local function my_mod_get_item(params...) ...
end

(entirely OUTSIDE the minetest.registered_node() call)

and then call *that* function from the on punch handler directly:

on_punch = my_mod_get_item,
 

sofar
Member
 
Posts: 781
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: Post your modding questions here

by sofar » Tue Feb 14, 2017 21:01

GreenDimond wrote:Functions hate me :(
I am trying to get a simple function to work, and it doesn't.
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() replace_donemodel(pos, node)
      minetest.set_node(pos, {name = "modname:nodename", param2 = node.param2})
   end,
   on_place = {
      minetest.after(2.0, replace_donemodel)}

This is inside a register_node.
I want the model to be replaced 2 seconds after it is placed (or set).
I have tried registering the function outside the register node aswell, but nothing works. What do?
EDIT: Fixed.


tell us the fix - this way everyone learns from the mistake!
 

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 » Tue Feb 14, 2017 21:10

GreenDimond wrote:Functions hate me :(
I am trying to get a simple function to work, and it doesn't.
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() replace_donemodel(pos, node)
      minetest.set_node(pos, {name = "modname:nodename", param2 = node.param2})
   end,
   on_place = {
      minetest.after(2.0, replace_donemodel)}

This is inside a register_node.
I want the model to be replaced 2 seconds after it is placed (or set).
I have tried registering the function outside the register node aswell, but nothing works. What do?
EDIT: Fixed.


This was the fix:

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
-- in definition of node A

on_punch = function(pos, node, puncher, pointed_thing)
    minetest.set_node(pos, { name = "nodeBName", param2 = node.param2 })
    minetest.after(2, minetest.set_node, pos, { name = "nodeCName", param2 = node.param2 })
end,


Turns out they wanted a node to go from A -> B when punched, then to C a few seconds later.

Here is a corrected version of their original code (Although it's not the right fix)

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 replace_donemodel(pos, node)
    minetest.set_node(pos, {name = "waffles:wafflemaker_open_done", param2 = node.param2})
end

minetest.register_node("node:name", {
     after_place_node = function(pos, placer, itemstack, pointed_thing)
        local node = minetest.get_node(pos)
        minetest.after(2.0, replace_donemodel, pos, node)
    end
})
 

PreviousNext

Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 3 guests

cron