A bit of a bug...

User avatar
programmingchicken
Member
 
Posts: 537
Joined: Sat Apr 18, 2015 02:20
GitHub: ProgrammingChicken
IRC: gamer chicken
In-game: gamerdude

A bit of a bug...

by programmingchicken » Tue May 12, 2015 00:52

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
I'm bold. I'm sarcastic. I'm PChicken.
 

User avatar
Nathan.S
Member
 
Posts: 679
Joined: Wed Sep 24, 2014 17:47
GitHub: NathanSalapat
IRC: NathanS21
In-game: NathanS21

Re: A bit of a bug...

by Nathan.S » Tue May 12, 2015 02:03

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
I record Minetest videos, Mod reviews, Modding tutorials, and Lets plays.
Check out my website.
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: A bit of a bug...

by rubenwardy » Tue May 12, 2015 07:32

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'},
   }
})
Last edited by rubenwardy on Tue May 12, 2015 07:50, edited 3 times in total.
 

User avatar
jp
Member
 
Posts: 705
Joined: Wed Dec 18, 2013 09:03
GitHub: kilbith

Re: A bit of a bug...

by jp » Tue May 12, 2015 07:36

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.
Last edited by jp on Tue May 12, 2015 07:52, edited 1 time in total.
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: A bit of a bug...

by rubenwardy » Tue May 12, 2015 07:45

jp, inb4. :P

You missed user:set_hp
 

User avatar
programmingchicken
Member
 
Posts: 537
Joined: Sat Apr 18, 2015 02:20
GitHub: ProgrammingChicken
IRC: gamer chicken
In-game: gamerdude

Re: A bit of a bug...

by programmingchicken » Tue May 12, 2015 23:06

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!
I'm bold. I'm sarcastic. I'm PChicken.
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: A bit of a bug...

by rubenwardy » Wed May 13, 2015 11:45

Unfortunately it is not possible to increase your max health in Minetest, afaik :(
 

User avatar
Krock
Member
 
Posts: 3598
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker

Re: A bit of a bug...

by Krock » Wed May 13, 2015 15:50

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
Newest Win32 builds - Find a mod - All my mods
ALL YOUR DONATION ARE BELONG TO PARAMAT (Please support him and Minetest)
New DuckDuckGo !bang: !mtmod <keyword here>
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 8 guests

cron