Page 1 of 1

A bit of a bug...

PostPosted: Tue May 12, 2015 00:52
by programmingchicken
Don't kill me. I'm a noob. I don't exactly make my code very readable either...
Just tell me what to do to make this error message not appear:
init.lua:1: function arguments expected near ','
Here's my 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
minetest.register_node(“superpotato:potato”, {
description = “Potato”,
inventory_image = “nonspotato”
wield_image = “nonspotato”,
wield_scale = 50,
stack_max = 99,
liquids_pointable = true,
on_use = function(itemstack, user, pointed_thing)
itemstack.take_item()
set_hp(get_hp+10)
return itemstack
minetest.register_craftitem("superpotato:superpotato", {
description = "Le Super Potato",
inventory_image = "superpotato",
wield_image = "superpotato",
wield_scale =50,
stack_max = 1,
liquids_pointable = false
on_use = function(itemstack, user, pointed_thing)
itemstack.take_item()
math.randomseed(os.time())
hp_max = hp_max+random(5)
set_hp(hp_max)
return itemstack
})
minetest.register_craft({
type = "fuel",
recipe = "supercoal:supercoal",
burntime = 20
})
minetest.register_craft({
output = 'superpotato:superpotato 2',
recipe = {{'default:diamond', 'default:gold','default:coal'},
{'default:mese', 'superpotato:potatoblock', 'default:wood'},
{default:steel'', 'default:dirt', 'default:sand'},}})

Just tell me where the problem is and what is syntactically wrong there.
I just started minetest modding today. :P

Re: A bit of a bug...

PostPosted: Tue May 12, 2015 02:03
by Nathan.S
I don't know if this is the cause of the problem, but you are missing a comma after burntime = 20,

Also your inventory and wield images should have an extension after the file name, probably .png, otherwise you'll get an error and just a random color.

Welcome to the forums by the way, you might want to check out these two resources to help you with your modding.
http://rubenwardy.com/minetest_modding_book/index.html
and
https://www.youtube.com/playlist?list=P ... Mz9lgUnuVF

Re: A bit of a bug...

PostPosted: Tue May 12, 2015 07:32
by rubenwardy
You're using the wrong quote marks. You should edit in notepad++, gedit, atom or another code editor (must be text based).
This is the right quote: "

You're also missing "end", it should look 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
    on_use = function(itemstack, user, pointed_thing)
         -- content here
    end


You're also missing user: from set_hp():

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
user:set_hp(5)


and you're missing () and user: from get_hp:

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
user:get_hp()


and it should be if itemstack:take_item() ~= nil then

You can use minetest.item_eat to eat an item and increase hp (although if hunger is installed the hunger is satisfied)

There is a comma missing from the end of line 3:

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
wield_image = "nonspotato"


and this line

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
liquids_pointable = false


also, where is hp_max defined? What do you want to do?

You don't need a file extension for textures, it looks for them automatically if you don't.
http://rubenwardy.com/minetest_modding_ ... l#textures

You should use indentation.

Fixed 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
minetest.register_node("superpotato:potato", {
   description = "Potato",
   inventory_image = "nonspotato",
   wield_image = "nonspotato",
   wield_scale = 50,
   stack_max = 99,
   liquids_pointable = true,
   on_use = function(itemstack, user, pointed_thing)
      if itemstack.take_item() ~= nil then
         user:set_hp(user:get_hp()+10)
         return itemstack
      end
   end
})
      
minetest.register_craftitem("superpotato:superpotato", {
   description = "Le Super Potato",
   inventory_image = "superpotato",
   wield_image = "superpotato",
   wield_scale =50,
   stack_max = 1,
   liquids_pointable = false,
   on_use = function(itemstack, user, pointed_thing)
      if itemstack:take_item() ~= nil then
         math.randomseed(os.time())
         local hp_max = hp_max+random(5)
         user:set_hp(hp_max)
         return itemstack
      end
   end
})

minetest.register_craft({
   type = "fuel",
   recipe = "supercoal:supercoal",
   burntime = 20
})

minetest.register_craft({
   output = 'superpotato:superpotato 2',
   recipe = {
      {'default:diamond', 'default:gold','default:coal'},
      {'default:mese', 'superpotato:potatoblock', 'default:wood'},
      {default:steel'', 'default:dirt', 'default:sand'},
   }
})


Better code



This uses minetest.item_eat and minetest.do_item_eat to increase hp, is better, supports hunger.

minetest.do_item_eat

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("superpotato:potato", {
   description = "Potato",
   inventory_image = "nonspotato",
   wield_image = "nonspotato",
   wield_scale = 50,
   stack_max = 99,
   liquids_pointable = true,
   on_use = minetest.item_eat(10)
})
      
minetest.register_craftitem("superpotato:superpotato", {
   description = "Le Super Potato",
   inventory_image = "superpotato",
   wield_image = "superpotato",
   wield_scale =50,
   stack_max = 1,
   liquids_pointable = false,
   on_use = function(itemstack, user, pointed_thing)
      -- not sure what you want to do here,
      --   this increases hp by a random number
      math.randomseed(os.time())
      return minetest.do_item_eat(random(5), nil, itemstack, user, pointed_thing)
   end
})

minetest.register_craft({
   type = "fuel",
   recipe = "supercoal:supercoal",
   burntime = 20
})

minetest.register_craft({
   output = 'superpotato:superpotato 2',
   recipe = {
      {'default:diamond', 'default:gold','default:coal'},
      {'default:mese', 'superpotato:potatoblock', 'default:wood'},
      {default:steel'', 'default:dirt', 'default:sand'},
   }
})

Re: A bit of a bug...

PostPosted: Tue May 12, 2015 07:36
by jp
Nathan.S wrote:I don't know if this is the cause of the problem, but you are missing a comma after burntime = 20,

Wrong, there's no need a comma when you finish your table definition right before a bracket.


EDIT : better correction by rubenwardy above.

Re: A bit of a bug...

PostPosted: Tue May 12, 2015 07:45
by rubenwardy
jp, inb4. :P

You missed user:set_hp

Re: A bit of a bug...

PostPosted: Tue May 12, 2015 23:06
by programmingchicken
Thanks! I'm editing the lua file as we type. Thanks again, I cannot express how truly your help helped me and my mod. BTW: "Le Super Potato" is a potato meant to drop valubles and increase your max health, but is that possible and/or useful? (lemme know) Thx!

Re: A bit of a bug...

PostPosted: Wed May 13, 2015 11:45
by rubenwardy
Unfortunately it is not possible to increase your max health in Minetest, afaik :(

Re: A bit of a bug...

PostPosted: Wed May 13, 2015 15:50
by Krock
rubenwardy wrote:Unfortunately it is not possible to increase your max health in Minetest, afaik :(

It's possible, just not with the Lua API :P
https://github.com/minetest/minetest/bl ... ants.h#L90