I have not understand the save of items (small_key)

Started by dpro_games, August 02, 2016, 11:51:01 PM

Previous topic - Next topic
Yes, use another savegame variable for the amounts, otherwise the engine would be confused

With this code, if I take two keys, I just can open one door after...  :(

How can I and where I need to inizialize a other variable for the amouts ?

I really sorry because I am a real beginners   :'(...

August 03, 2016, 02:05:02 AM #17 Last Edit: August 03, 2016, 02:07:51 AM by MetalZelda
I don't remember if you need to use item:add_amount(item:get_amount() + 1) in on_obtaining() or if the engine does it automatically. I'm sure that this would fix your problem.

August 03, 2016, 02:07:45 AM #18 Last Edit: August 03, 2016, 02:11:56 AM by Diarandor
I don't know because I have never used the key-door system. But what MetalZelda says is surely the correct thing to do.
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

Oh thank !!! It works !!! It's the first time than I do something which works with solarus ! Thank you !  ;)

August 03, 2016, 02:10:42 AM #20 Last Edit: August 03, 2016, 02:13:25 AM by MetalZelda
Also if you are a true begginer (we all passed this step), I recommand you to watch all of Solarus Tutorial videoes by Christopho

https://www.youtube.com/watch?v=DKLrGyMqvaU

These are a bit old and would be replaced by the new ones, but the engine is a bit similar and it would help you to understand the basics of the engine and the map editor.

If you want to make a game with Solarus (which I guess is what you're here for), I recommand you to learn the basics of lua
https://www.lua.org/pil/contents.html#P1

You can also use the function "item:add_amount(amount)",
which should be equivalent to "item:add_amount(item:get_amount() + 1)".
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

Quote from: Diarandor on August 03, 2016, 02:12:05 AM
You can also use the function "item:add_amount(amount)",
which should be equivalent to "item:add_amount(item:get_amount() + 1)".

Yes that works too, I just didn't remember how it worked  ;D (It's been a long time since I didn't look at items)

But there is an eroor in the consol with that : Error: In on_obtaining: [string "items/small_key.lua"]:16: bad argument #1 to add_amount (integer expected, got nil))

August 03, 2016, 02:21:23 AM #24 Last Edit: August 03, 2016, 02:24:06 AM by Diarandor
As the error says "integer expected, got nil",
so write something like "item:add_amount(1)".

EDIT: when I wrote above:
QuoteYou can also use the function "item:add_amount(amount)",
which should be equivalent to "item:add_amount(item:get_amount() + 1)".
I wanted to say:
You can also use the function "item:add_amount(amount)",
which should be equivalent to "item:set_amount(item:get_amount() + 1)".

Sorry for the mistakes, it's quite late and we are all tired...  :-\
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

Quote from: dpro_games on August 03, 2016, 02:17:22 AM
But there is an eroor in the consol with that : Error: In on_obtaining: [string "items/small_key.lua"]:16: bad argument #1 to add_amount (integer expected, got nil))

integer expected means that eigher tou enterred a letter and not a number in add_amount()

In Diarandor's example, what he means is

Code (lua) Select
item:add_amount(amount)

amount can be replaced by a number, 1

So, it is

Code (lua) Select
item:add_amount(1)


Realy thanks ! I can sleeping well now ! Bye ! Maybe later... to help me pass the beginner steps !  :D