You can't. Combine the code into one function.GreenDimond wrote:I seem to be having trouble with registering 2 'on_punch' to the same node.
Post your modding questions here
Re: Post your modding questions here
- GreenXenith
- Member
- Posts: 1356
- Joined: Wed Oct 28, 2015 01:26
- GitHub: GreenXenith
- Location: UTC-8:00
- Contact:
Re: Post your modding questions here
I have realized this, but now I am having trouble with that aswell. I will post here if I cant fix.sofar wrote:You can't. Combine the code into one function.GreenDimond wrote:I seem to be having trouble with registering 2 'on_punch' to the same node.
YouTube | Mods | Patreon | Minetest Discord @greenxenith
You should not be able to read this message.
You should not be able to read this message.
- GreenXenith
- Member
- Posts: 1356
- Joined: Wed Oct 28, 2015 01:26
- GitHub: GreenXenith
- Location: UTC-8:00
- Contact:
Re: Post your modding questions here
Still working on this, but apparently I still cant seem to be able to lua.
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.
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
YouTube | Mods | Patreon | Minetest Discord @greenxenith
You should not be able to read this message.
You should not be able to read this message.
- GreenXenith
- Member
- Posts: 1356
- Joined: Wed Oct 28, 2015 01:26
- GitHub: GreenXenith
- Location: UTC-8:00
- Contact:
Re: Post your modding questions here
This code lets the game start and actually does something when I punch the node. My game crashes.
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:
In case you are wondering, I use "modname" and "nodename" and stuff to keep the mod a secret :P
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
})
error code:
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>
YouTube | Mods | Patreon | Minetest Discord @greenxenith
You should not be able to read this message.
You should not be able to read this message.
- D00Med
- Member
- Posts: 949
- Joined: Sat Feb 07, 2015 22:49
- GitHub: D00Med
- Location: Australia...somewhere
Re: Post your modding questions here
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.
^ 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 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.
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
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: viewtopic.php?f=15&t=14051#p207242
My subgame: viewtopic.php?f=15&t=14051#p207242
- orwell
- Member
- Posts: 958
- Joined: Wed Jun 24, 2015 18:45
- GitHub: orwell96
- IRC: orwell96_mt
- In-game: orwell
- Location: Raxacoricofallapatorius
Re: Post your modding questions here
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
-- ...
})
Also, 'node' is not ' node definition'.
- orwell
- Member
- Posts: 958
- Joined: Wed Jun 24, 2015 18:45
- GitHub: orwell96
- IRC: orwell96_mt
- In-game: orwell
- Location: Raxacoricofallapatorius
Re: Post your modding questions here
I have a function advtrains.minAngleDiffRad in advtrains/helpers.lua. maybe this is helpful.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.
^ yaw is the player's yawCode: 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
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?
Returns how far to rotate from first angle in which direction to reach second angle
Link is in signature
- Desour
- Member
- Posts: 1469
- Joined: Thu Jun 19, 2014 19:49
- GitHub: Desour
- IRC: Desour
- In-game: DS
- Location: I'm scared that if this is too exact, I will be unable to use my keyboard.
Re: Post your modding questions here
@GreenDimond: Try it like this:
Perhaps it will work.
Btw where is this code? Is it in minetest.reister_node ?
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
})
Btw where is this code? Is it in minetest.reister_node ?
he/him; Codeberg; GitHub; ContentDB; public personal TODO list; "DS" is preferred (but often too short)
- GreenXenith
- Member
- Posts: 1356
- Joined: Wed Oct 28, 2015 01:26
- GitHub: GreenXenith
- Location: UTC-8:00
- Contact:
Re: Post your modding questions here
@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:
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?
@DS-minetest: I tried your answer before orwells (just cuz it was a copy/past). I get this:
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>
@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?
YouTube | Mods | Patreon | Minetest Discord @greenxenith
You should not be able to read this message.
You should not be able to read this message.
- orwell
- Member
- Posts: 958
- Joined: Wed Jun 24, 2015 18:45
- GitHub: orwell96
- IRC: orwell96_mt
- In-game: orwell
- Location: Raxacoricofallapatorius
Re: Post your modding questions here
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
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
- GreenXenith
- Member
- Posts: 1356
- Joined: Wed Oct 28, 2015 01:26
- GitHub: GreenXenith
- Location: UTC-8:00
- Contact:
Re: Post your modding questions here
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:
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?
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:
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,
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?
YouTube | Mods | Patreon | Minetest Discord @greenxenith
You should not be able to read this message.
You should not be able to read this message.
- orwell
- Member
- Posts: 958
- Joined: Wed Jun 24, 2015 18:45
- GitHub: orwell96
- IRC: orwell96_mt
- In-game: orwell
- Location: Raxacoricofallapatorius
Re: Post your modding questions here
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.
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.
- GreenXenith
- Member
- Posts: 1356
- Joined: Wed Oct 28, 2015 01:26
- GitHub: GreenXenith
- Location: UTC-8:00
- Contact:
Re: Post your modding questions here
Is that not the code I currently have?
We could talk about this in IRC if you like (#minetest).
We could talk about this in IRC if you like (#minetest).
YouTube | Mods | Patreon | Minetest Discord @greenxenith
You should not be able to read this message.
You should not be able to read this message.
- orwell
- Member
- Posts: 958
- Joined: Wed Jun 24, 2015 18:45
- GitHub: orwell96
- IRC: orwell96_mt
- In-game: orwell
- Location: Raxacoricofallapatorius
Re: Post your modding questions here
No not exactly. The .name went elsewhere. IRC not today.GreenDimond wrote:Is that not the code I currently have?
We could talk about this in IRC if you like (#minetest).
- GreenXenith
- Member
- Posts: 1356
- Joined: Wed Oct 28, 2015 01:26
- GitHub: GreenXenith
- Location: UTC-8:00
- Contact:
Re: Post your modding questions here
I see...trying this.orwell wrote:No not exactly. The .name went elsewhere. IRC not today.GreenDimond wrote:Is that not the code I currently have?
We could talk about this in IRC if you like (#minetest).
EDIT: It works! Thanks!
YouTube | Mods | Patreon | Minetest Discord @greenxenith
You should not be able to read this message.
You should not be able to read this message.
- GreenXenith
- Member
- Posts: 1356
- Joined: Wed Oct 28, 2015 01:26
- GitHub: GreenXenith
- Location: UTC-8:00
- Contact:
Re: Post your modding questions here
Functions hate me :(
I am trying to get a simple function to work, and it doesn't.
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 trying to get a simple function to work, and it doesn't.
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)}
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.
YouTube | Mods | Patreon | Minetest Discord @greenxenith
You should not be able to read this message.
You should not be able to read this message.
Re: Post your modding questions here
GreenDimond wrote:This code lets the game start and actually does something when I punch the node. My game crashes.I think I am about 90% of the way there, but am now moving as fast as a brick. So wat do now?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 })
error code:In case you are wondering, I use "modname" and "nodename" and stuff to keep the mod a secret :PCode: 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>
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,
Re: Post your modding questions here
tell us the fix - this way everyone learns from the mistake!GreenDimond wrote:Functions hate me :(
I am trying to get a simple function to work, and it doesn't.This is inside a register_node.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)}
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.
- rubenwardy
- Moderator
- Posts: 6972
- 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
This was the fix:GreenDimond wrote:Functions hate me :(
I am trying to get a simple function to work, and it doesn't.This is inside a register_node.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)}
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.
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,
Here is a corrected version of their original code (Although it's not the right fix)
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
})
- D00Med
- Member
- Posts: 949
- Joined: Sat Feb 07, 2015 22:49
- GitHub: D00Med
- Location: Australia...somewhere
Re: Post your modding questions here
Thanks, this improves it a lot. The problem still occurs a little, but it's not as commonorwell wrote: 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
Look! I have a signature :]
My subgame: viewtopic.php?f=15&t=14051#p207242
My subgame: viewtopic.php?f=15&t=14051#p207242
Re: Post your modding questions here
A little question.
I need something like get_camera_pos() but nothing found.
Is there a simple way to get it ?
I need something like get_camera_pos() but nothing found.
Is there a simple way to get it ?
I am a noob. still yet. Not so noob ) [vml] WIP and a little proof for fun PlantedTorch )))
MT Strike 78a36b468554d101e0be3b0d1f587a555f396452 Great! Somebody have found it )
"My english isn't well" I know. I'm sorry )
MT Strike 78a36b468554d101e0be3b0d1f587a555f396452 Great! Somebody have found it )
"My english isn't well" I know. I'm sorry )
- 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
There's no access to camera, but you can get the player's position and add the eye offset:Nyarg wrote:A little question.
I need something like get_camera_pos() but nothing found.
Is there a simple way to get it ?
Code: Select all
local pos = player:getpos()
pos.y = pos.y + 1.625
Getting third person camera position is possible by doing some maths with looking direction, but since there's no way to detect if a player is in third person view mode (AFAIK) it's kinda useless.
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
Hi experts.
How i can get (pos) of the particles in time.
Is the some function for example?
minetest.get particle(id)
return:
pos - position of particle
meta - meta of particle
------------
P.S. If this is not. Please write the post in issues GitHub.
It is very necessary.
Thank.
How i can get (pos) of the particles in time.
Is the some function for example?
minetest.get particle(id)
return:
pos - position of particle
meta - meta of particle
------------
P.S. If this is not. Please write the post in issues GitHub.
It is very necessary.
Thank.
I am groot!
-
- Member
- Posts: 818
- Joined: Tue Apr 14, 2015 01:59
- GitHub: raymoo
- IRC: Hijiri
- In-game: Raymoo + Clownpiece
Re: Post your modding questions here
The server does not keep track of particles (or their positions), and if you look at the specification of add_particle, you will notice that it does not return an id. If you want something you can keep track of the position of, I would use an entity.googol wrote:Hi experts.
How i can get (pos) of the particles in time.
Is the some function for example?
minetest.get particle(id)
return:
pos - position of particle
meta - meta of particle
------------
P.S. If this is not. Please write the post in issues GitHub.
It is very necessary.
Thank.
What is your use case for getting the position of a particle? Maybe there is a better way that is already possible.
Every time a mod API is left undocumented, a koala dies.
Re: Post your modding questions here
Thank Byakuren.
I tried the "entity", and think you're right.
I tried the "entity", and think you're right.
I am groot!
Who is online
Users browsing this forum: No registered users and 5 guests