Simple code issue maybe a misplaced , or a missing end IDK

Post Reply
User avatar
Still_Harbor
New member
Posts: 8
Joined: Wed Jun 20, 2018 01:48

Simple code issue maybe a misplaced , or a missing end IDK

by Still_Harbor » Post

I have tried resolving on my own from prior mods I've done with sound BUT! this one is tripping me up hard. May just be the long dive into HTML and Bootstrap for the last few months.. throwing errors on line 14 15 16 25,000 etc soon as I fix one "I thought" another crys PLZ Help me :'( x))) I figured out SOoosoooOoOo Much on my on and NOW I am stuck on a 2 second "maybe" issue... -__-

Code: Select all

minetest.register_node("piano:piano", {
		description = "Grand Piano",
		inventory_image = "9.png",
		wield_image = "9.png",
		drawtype = "mesh",
		mesh = "piano.obj",
		paramtype = "facedir",
		tiles = {""},
		groups = {cracky=3, snappy=3},
		is_ground_content = true,
		sunlight_propagates = false,
		use_texture_alpha = true,
	},
              }, -- This may be an Issue IDK not great at this mess 

	if minetest.get_node(pointed_thing.under).name == "piano:piano" then
		     minetest.sound_play("tas",
				{pos=pointed_thing.under, max_hear_distance = 20,})

	else

	if minetest.get_node(pointed_thing.under).name == "moreblocks:circular_saw" then
		     minetest.sound_play("vam",
				{pos=pointed_thing.under, max_hear_distance = 20,})

	else

		end
	end
end

})
In the darkest moments, a ray of light is very easy to see.. think positively life is so short.

entuland
Member
Posts: 123
Joined: Wed May 09, 2018 15:47
GitHub: entuland
IRC: entuland
In-game: entuland

Re: Simple code issue maybe a misplaced , or a missing end I

by entuland » Post

Hey there Still Harbor, not sure what you're really trying to do with those conditionals, but register call should look something like this:

Code: Select all

minetest.register_node("piano:piano", {
	description = "Grand Piano",
	inventory_image = "9.png",
	wield_image = "9.png",
	drawtype = "mesh",
	mesh = "piano.obj",
	paramtype = "facedir",
	tiles = {""},
	groups = {cracky=3, snappy=3},
	is_ground_content = true,
	sunlight_propagates = false,
	use_texture_alpha = true,
}) 
(notice how the table is wrapped by curly braces at the first and last line)

Then there are your conditionals, which if I'm not mistaken can be rewritten like this:

Code: Select all

if minetest.get_node(pointed_thing.under).name == "piano:piano" then
	   minetest.sound_play("tas", {pos=pointed_thing.under, max_hear_distance = 20,})
elseif minetest.get_node(pointed_thing.under).name == "moreblocks:circular_saw" then
	   minetest.sound_play("vam", {pos=pointed_thing.under, max_hear_distance = 20,})
end
The register_node() call must be performed at loading time, whereas your conditionals should be running in some function where you can properly fill all the required variables (pointed_thing and the alike).

User avatar
Still_Harbor
New member
Posts: 8
Joined: Wed Jun 20, 2018 01:48

Re: Simple code issue maybe a misplaced , or a missing end I

by Still_Harbor » Post

Thank You for the Reply Entuland!
My Goal is to Play a sound file when the grand piano mesh I made is punched and it seems like I am on the verge of completion BUT every change I make throws an error.. One after another Maybe I should just toss this idea in the trash and go back to basic nodes x) I thought it would be awesome to have a players piano on MT and so I built one it displays BUT as soon as I add

Code: Select all

 if minetest.get_node(pointed_thing.under).name == "piano:piano" then
      minetest.sound_play("tas", {pos=pointed_thing.under, max_hear_distance = 20,})
elseif minetest.get_node(pointed_thing.under).name == "moreblocks:circular_saw" then
      minetest.sound_play("vam", {pos=pointed_thing.under, max_hear_distance = 20,})
end 
Errors everywhere! YAY confetti -_-
IDK what I am doing wrong here as I have done this before and the code is identical Oo
In the darkest moments, a ray of light is very easy to see.. think positively life is so short.

User avatar
Still_Harbor
New member
Posts: 8
Joined: Wed Jun 20, 2018 01:48

Re: Simple code issue maybe a misplaced , or a missing end I

by Still_Harbor » Post

Also.. plays varied piano tunes when punched with various junk in your hand ... Forgot to mention.. I know the saw is a weird item to play a Grand Piano with but I use it so much in building it seemed right at the time :}}}}
In the darkest moments, a ray of light is very easy to see.. think positively life is so short.

User avatar
Still_Harbor
New member
Posts: 8
Joined: Wed Jun 20, 2018 01:48

Re: Simple code issue maybe a misplaced , or a missing end I

by Still_Harbor » Post

I was also thinking of using "on_punch" But IDK if I can assign Nodes to that or if it can only play one tune
Hence the get_node
In the darkest moments, a ray of light is very easy to see.. think positively life is so short.

entuland
Member
Posts: 123
Joined: Wed May 09, 2018 15:47
GitHub: entuland
IRC: entuland
In-game: entuland

Re: Simple code issue maybe a misplaced , or a missing end I

by entuland » Post

Still_Harbor, I guess you want to add a line reading something like this to your register_node() call:

Code: Select all

-- other table entries in register_node()
    on_punch = function(pos, node, puncher, pointed_thing)
      -- your code here
    end,
-- other table entries
Or if you prefer, you define your handler before calling register_node() and then you bind it, something like this:

Code: Select all

local function punch_handler(pos, node, puncher, pointed_thing)
  -- your code here
end

-- other table entries inside register_node()
    on_punch = punch_handler,
-- other table entries
Two useful links:
https://rubenwardy.com/minetest_modding_book
https://github.com/minetest/minetest/bl ... .txt#L3521

User avatar
Still_Harbor
New member
Posts: 8
Joined: Wed Jun 20, 2018 01:48

Re: Simple code issue maybe a misplaced , or a missing end I

by Still_Harbor » Post

:DDDDDDDDDD I am Sooooooooo HAPPY Thank You Thank You Thank YOU! Thank You very much entuland :DD
All is well now Plays the songs Perfectly! GENIUS! EPIC! GENIUS!
In the darkest moments, a ray of light is very easy to see.. think positively life is so short.

User avatar
Still_Harbor
New member
Posts: 8
Joined: Wed Jun 20, 2018 01:48

Re: Simple code issue maybe a misplaced , or a missing end I

by Still_Harbor » Post

Code: Select all

     -- other table entries in register_node()
        on_punch = function(pos, node, puncher, pointed_thing)
          -- your code here
        end,
    -- other table entries
That was the winner
Beautiful :}}}}
In the darkest moments, a ray of light is very easy to see.. think positively life is so short.

entuland
Member
Posts: 123
Joined: Wed May 09, 2018 15:47
GitHub: entuland
IRC: entuland
In-game: entuland

Re: Simple code issue maybe a misplaced , or a missing end I

by entuland » Post

Still_Harbor wrote:

Code: Select all

     -- other table entries in register_node()
        on_punch = function(pos, node, puncher, pointed_thing)
          -- your code here
        end,
    -- other table entries
That was the winner
Beautiful :}}}}
Eheheheh, you're welcome, glad it's working :)

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests