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

0 Members and 1 Guest are viewing this topic.

dpro_games

  • Newbie
  • *
  • Posts: 47
    • View Profile
I have not understand the save of items (small_key)
« on: August 02, 2016, 11:51:01 PM »
I have a problem to initialize the "small_key" save. :-\

I want to create a door in a dongeon which can be open with a small key but solarus display an error in the consol...I still read the documentation but i don't understand how can I do to solarus doesn't display that: : Error: In create_door: bad argument #1 to ? (Bad field 'opening_condition' (equipment item 'small_key' is not saved)).
 :'( Thank to help me !!!

Sorry for the bad translation, I'm french...
« Last Edit: August 03, 2016, 12:06:39 AM by dpro_games »

Diarandor

  • Hero Member
  • *****
  • Posts: 1062
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Pas compris sauvegarde des items (small_key)
« Reply #1 on: August 03, 2016, 12:07:54 AM »
Pouvez-vous coller ici une copie de tout le code de votre script où la fonction "create_door" se trouve ? Ça nous aidera trouver le problème.
Translation: could you paste a copy here of all code of the script where the function "create_door" is defined? That will help us to find the problem.

PS: il serait mieux si vouz écrivez en anglais (si vous pouvez) parce que la plupart des gens d'ici ne parlent pas le français, et plus de gens pourrait vous aider.
Translation: PS: it would be better if you write in English (if you can) because most people here do not speak French, and more people would be able to help you.
« Last Edit: August 03, 2016, 12:09:44 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 #2 on: August 03, 2016, 12:14:18 AM »
Code of the small_key:
Code: [Select]
local item = ...
 
function item:on_created()
 
   
    item:set_shadow("small")
    item:set_can_disappear(false)
    item:set_brandish_when_picked(true)
    item:set_sound_when_picked("picked_small_key")
end
 
function item:on_obtaining()
 
end

And the door is create with solarus with the option : hero need an item to open the door (small_key)

Diarandor

  • Hero Member
  • *****
  • Posts: 1062
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: I have not understand the save of items (small_key)
« Reply #3 on: August 03, 2016, 12:27:25 AM »
Hi again. This is not the script I was asking for (but it may help too).
We need to see the script where the function "create_door" is defined (it's probably your map script).
“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 #4 on: August 03, 2016, 12:31:32 AM »
This is my map script :
Code: [Select]
-- Lua script of map Outdoor_hero_house.
-- This script is executed every time the hero enters this map.

-- Feel free to modify the code below.
-- You can add more events and remove the ones you don't need.

-- See the Solarus Lua API documentation:
-- http://www.solarus-games.org/doc/latest

local map = ...
local game = map:get_game()

-- Event called at initialization time, as soon as this map becomes is loaded.
function map:on_started()

  -- You can initialize the movement and sprites of various
  -- map entities here.
end

-- Event called after the opening transition effect of the map,
-- that is, when the player takes control of the hero.
function map:on_opening_transition_finished()

end

Diarandor

  • Hero Member
  • *****
  • Posts: 1062
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: I have not understand the save of items (small_key)
« Reply #5 on: August 03, 2016, 12:37:08 AM »
Nope, I was wrong, hehe, it is not in your map script, or at least not in this one.
Since you got this error:
Code: [Select]
Error: In create_door: bad argument #1 to ? (Bad field 'opening_condition' (equipment item 'small_key' is not saved))we need to find the script where the function create_door is being used, because the error is happening there.
Does the error indicate in which file the error is it happening? (If so, that will be the script that we need to check.)

Edit: maybe the script we need is the script of another map, and not that one.
“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 #6 on: August 03, 2016, 12:46:43 AM »

Diarandor

  • Hero Member
  • *****
  • Posts: 1062
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: I have not understand the save of items (small_key)
« Reply #7 on: August 03, 2016, 01:11:02 AM »
Ok, I found the problem (I have never used a built-in door since I use my custom ones, so I did not know about this thing).

The problem is that the amount of keys you have has to be saved in some variable, and you have not indicated to the engine in which variable (this has to be done for any type of item, so you may get the same problem for other items you create).
You just need to add something like this
Code: [Select]
item:set_savegame_variable("id_for_the_amount_of_keys")inside the function "item:on_created()".
(you can use there any string you want (so change the string to a shorter one if you want), and that variable will be used for all keys of your game).

You will have something like this:
Code: [Select]
function item:on_created()

  item:set_savegame_variable("id_for_the_amount_of_keys")   
  item:set_shadow("small")
  item:set_can_disappear(false)
  item:set_brandish_when_picked(true)
  item:set_sound_when_picked("picked_small_key")
end

You can now delete the previous link to your data in mediafire.

PS: you can also ask on the IRC chat whenever you want, and don't hesitate to ask if you have any problem. :)
« Last Edit: August 03, 2016, 01:13:11 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 #8 on: August 03, 2016, 01:12:49 AM »
Ok, thanks a lot !!!  ;)

dpro_games

  • Newbie
  • *
  • Posts: 47
    • View Profile
Re: I have not understand the save of items (small_key)
« Reply #9 on: August 03, 2016, 01:22:30 AM »
It is possible to increment this variable when we take a other key ?

MetalZelda

  • Hero Member
  • *****
  • Posts: 551
    • View Profile
Re: I have not understand the save of items (small_key)
« Reply #10 on: August 03, 2016, 01:30:02 AM »
It is possible to increment this variable when we take a other key ?

Just add in item:on_created()

Code: (lua) [Select]
self:set_amount_savegame_variable("your_variable")
http://www.solarus-games.org/doc/1.5/lua_api_item.html#lua_api_item_set_amount_savegame_variable

There is a lot of way to do it, you should take a look at how Mystery of Solarus DX manage small keys, this is the best way to do small keys
« Last Edit: August 03, 2016, 01:31:43 AM by MetalZelda »

dpro_games

  • Newbie
  • *
  • Posts: 47
    • View Profile
Re: I have not understand the save of items (small_key)
« Reply #11 on: August 03, 2016, 01:38:46 AM »
It does not work...
Where I need to add this ligne ?

Code: [Select]
local item = ...
 
function item:on_created()

  item:set_savegame_variable("small_key_save")
  self:set_amount_savegame_variable("small_key_save")
  item:set_shadow("small")
  item:set_can_disappear(false)
  item:set_brandish_when_picked(true)
  item:set_sound_when_picked("picked_small_key")

end

Diarandor

  • Hero Member
  • *****
  • Posts: 1062
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: I have not understand the save of items (small_key)
« Reply #12 on: August 03, 2016, 01:42:32 AM »
Yes. In that variable the engine saves the amount of keys you have.
You should take a look to the functions in the Lua API:
Code: (Lua) [Select]
item:get_amount_savegame_variable()
item:set_amount_savegame_variable()
here
http://www.solarus-games.org/doc/1.5/lua_api_item.html#lua_api_item_methods

By the way, @Christopho: there is something wrong in the API, for the function "item:set_amount_savegame_variable()", where it says:
"Returns the name of the integer savegame value that stores the amount of this item."
I think that line should be removed, the last paragraph
"Return value (string): The savegame variable that should store the possessed amount of this item, or nil to make this item have no associated amount."
seems to be wrong too, and the function should appear as
"item:set_amount_savegame_variable(savegame_variable)",
if I am not wrong.

EDIT: whoops, I posted too late. You already read the API.
« Last Edit: August 03, 2016, 01:50: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.”

Diarandor

  • Hero Member
  • *****
  • Posts: 1062
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: I have not understand the save of items (small_key)
« Reply #13 on: August 03, 2016, 01:46:41 AM »
I was wrong in what I said before:
"item:set_savegame_variable(savegame_variable)" is used for the possesion, not the amount. For the amount the engine uses:
"item:set_amount_savegame_variable(savegame_variable)"
“If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you.”

Diarandor

  • Hero Member
  • *****
  • Posts: 1062
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: I have not understand the save of items (small_key)
« Reply #14 on: August 03, 2016, 01:49:14 AM »
It does not work...
Where I need to add this ligne ?

Code: [Select]
local item = ...
 
function item:on_created()

  item:set_savegame_variable("small_key_save")
  self:set_amount_savegame_variable("small_key_save")
  item:set_shadow("small")
  item:set_can_disappear(false)
  item:set_brandish_when_picked(true)
  item:set_sound_when_picked("picked_small_key")

end

You should use a different variable for the amount, so you should not use the same variable for both things (the variable "small_key_save").
“If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you.”