Author Topic: I have not understand the save of items (small_key)  (Read 11219 times)

0 Members and 1 Guest are viewing this topic.

MetalZelda

  • Hero Member
  • *****
  • Posts: 551
    • View Profile
Re: I have not understand the save of items (small_key)
« Reply #15 on: August 03, 2016, 01:55:06 AM »
Yes, use another savegame variable for the amounts, otherwise the engine would be confused

dpro_games

  • Newbie
  • *
  • Posts: 47
    • View Profile
Re: I have not understand the save of items (small_key)
« Reply #16 on: August 03, 2016, 02:01:47 AM »
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   :'(...

MetalZelda

  • Hero Member
  • *****
  • Posts: 551
    • View Profile
Re: I have not understand the save of items (small_key)
« Reply #17 on: August 03, 2016, 02:05:02 AM »
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.
« Last Edit: August 03, 2016, 02:07:51 AM by MetalZelda »

Diarandor

  • Hero Member
  • *****
  • Posts: 1062
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: I have not understand the save of items (small_key)
« Reply #18 on: August 03, 2016, 02:07:45 AM »
I don't know because I have never used the key-door system. But what MetalZelda says is surely the correct thing to do.
« Last Edit: August 03, 2016, 02:11:56 AM by Diarandor »
“If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you.”

dpro_games

  • Newbie
  • *
  • Posts: 47
    • View Profile
Re: I have not understand the save of items (small_key)
« Reply #19 on: August 03, 2016, 02:10:10 AM »
Oh thank !!! It works !!! It's the first time than I do something which works with solarus ! Thank you !  ;)

MetalZelda

  • Hero Member
  • *****
  • Posts: 551
    • View Profile
Re: I have not understand the save of items (small_key)
« Reply #20 on: August 03, 2016, 02:10:42 AM »
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
« Last Edit: August 03, 2016, 02:13:25 AM by MetalZelda »

Diarandor

  • Hero Member
  • *****
  • Posts: 1062
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: I have not understand the save of items (small_key)
« Reply #21 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)".
“If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you.”

MetalZelda

  • Hero Member
  • *****
  • Posts: 551
    • View Profile
Re: I have not understand the save of items (small_key)
« Reply #22 on: August 03, 2016, 02:15:28 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)

dpro_games

  • Newbie
  • *
  • Posts: 47
    • View Profile
Re: I have not understand the save of items (small_key)
« Reply #23 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))

Diarandor

  • Hero Member
  • *****
  • Posts: 1062
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: I have not understand the save of items (small_key)
« Reply #24 on: August 03, 2016, 02:21:23 AM »
As the error says "integer expected, got nil",
so write something like "item:add_amount(1)".

EDIT: when I wrote above:
Quote
You 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...  :-\
« Last Edit: August 03, 2016, 02:24:06 AM by Diarandor »
“If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you.”

MetalZelda

  • Hero Member
  • *****
  • Posts: 551
    • View Profile
Re: I have not understand the save of items (small_key)
« Reply #25 on: August 03, 2016, 02:21:47 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)

dpro_games

  • Newbie
  • *
  • Posts: 47
    • View Profile
Re: I have not understand the save of items (small_key)
« Reply #26 on: August 03, 2016, 02:28:12 AM »
Realy thanks ! I can sleeping well now ! Bye ! Maybe later... to help me pass the beginner steps !  :D