Help with my mod

User avatar
Menche
Member
 
Posts: 994
Joined: Sat Jul 02, 2011 00:43

Help with my mod

by Menche » Sat Jul 21, 2012 04:54

I'm making a mod that adds a node that can be pushed around, moving one block whenever it's punched. It seems to work, but a lot of the time the node moves two blocks over rather than one. I can't figure out why, can someone more experienced look at it? The block only moves if hit from one angle, I haven't done the others yet.
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_node("pushblocks:pushstone", {
        description = "Test Pushstone",
        tiles = {"default_cobble.png"},
        is_ground_content = true,
        groups = {cracky=3},
})

minetest.register_on_punchnode(function(pos, node, puncher)
        if node.name == "pushblocks:pushstone" then
                if minetest.dir_to_facedir(puncher:get_look_dir()) == 0 then
                        pos.z = pos.z + 1
                        if minetest.env:get_node(pos).name == "air" then
                                minetest.env:add_node(pos,{name = "pushblocks:pushstone"})
                                pos.z = pos.z - 1
                                minetest.env:remove_node(pos)
                        end
                end
        end
end)

Last edited by Menche on Sat Jul 21, 2012 05:11, edited 1 time in total.
An innocent kitten dies every time you top-post.
I am on the Voxelands Forums more often than here.
Try Voxelands (forked from Minetest 0.3) by darkrose
 

User avatar
Jeija
Member
 
Posts: 686
Joined: Fri Dec 23, 2011 21:46

by Jeija » Sat Jul 21, 2012 05:40

The code is 100% working. The reason for that it moves 2 blocks sometimes is that you punch it twice (once before it moves, second time after it moved), although you don`t release the mouse button.
You could put some timer in or use on_dignode instead. Feel free to ask if you need help in coding that.
Last edited by Jeija on Sat Jul 21, 2012 05:41, edited 1 time in total.
Redstone for minetest: Mesecons (mesecons.net)
 

User avatar
mauvebic
Member
 
Posts: 1550
Joined: Fri Jan 27, 2012 11:32

by mauvebic » Sat Jul 21, 2012 10:05

you have this bit in twice:
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
pos.z = pos.z - 1


right here:
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
------------------->                        pos.z = pos.z + 1
                        if minetest.env:get_node(pos).name == "air" then
                                minetest.env:add_node(pos,{name = "pushblocks:pushstone"})
------------------->                                pos.z = pos.z - 1


which would result in a pos.z decreasing by two
Last edited by mauvebic on Sat Jul 21, 2012 10:06, edited 1 time in total.
"Fuck the hat." - Paulie Gualtieri
 

User avatar
Jeija
Member
 
Posts: 686
Joined: Fri Dec 23, 2011 21:46

by Jeija » Sun Jul 22, 2012 07:39

No mauvebic, thats fine. One time it is +1, the other time -1.
I tried the mod and it was possible to push the moving thing just 1 block over.
Redstone for minetest: Mesecons (mesecons.net)
 

User avatar
cactuz_pl
Member
 
Posts: 874
Joined: Tue Jun 05, 2012 16:34

by cactuz_pl » Sun Jul 22, 2012 09:01

I think this is due to that the game interpret click mouse button like hold mouse button, and "minetest.register_on_punchnode" counts twice or even triple, if you try click mouse button very shortly, node will move only one block length.

Try add some "wait" command, if is there any.

Edit: Jeija sorry I did not notice your post, which is about the same.
Last edited by cactuz_pl on Sun Jul 22, 2012 10:10, edited 1 time in total.
Nope
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 14 guests

cron