Solarus-Games English Forum

Solarus => Development => Topic started by: Lucifer on January 14, 2018, 07:04:56 PM

Title: Résolu : Menu de game-over + inventaire en 1.6
Post by: Lucifer on January 14, 2018, 07:04:56 PM
Bonsoir à tous !
Alors, je crée un jeu avec Solarus, mais je voudrais coder un menu de game-over ainsi qu'un inventaire, car quand je l'allume, ça me fait :
Info: Solarus 1.6.0
Info: Opening quest 'C:/Users/Hpo/Desktop/The legend of Zelda Hyrule Adventure'
Info: Sound volume: 100
Info: Music volume: 100
Info: Joypad support enabled: true
Info: 2D acceleration: yes
Info: Turbo mode: no
Info: Video mode: normal
Info: LuaJIT: yes (LuaJIT 2.0.3)
Info: Language: fr
Info: Lua console: yes
Info: Simulation started
Error: In on_started: scripts/menus/pause_submenu.lua:39: No value with key 'save_dialog.yes' in strings.dat for language 'fr'
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Error: In on_finished: scripts/menus/pause_inventory.lua:84: attempt to call method 'get_hud' (a nil value)
Info: Simulation finished


pour l'inventaire, et pour le game-over, je redémarre juste...
Pourriez-vous m'aider, s'il vous plaît ?
En attente de votre réponse,
Lucifer
Title: Re: Menu de game-over + inventaire en 1.6
Post by: froggy77 on January 14, 2018, 09:30:44 PM
Cela va être difficile de t'aider sans voir le contenu des fichiers en question, si tu ne connais pas quelques bases du lua et si tu ne comprends pas les messages d'erreur qui sont pourtant dans un anglais assez simple.
Que veulent dire, selon toi, ces lignes d'erreur?
QuoteError: In on_started: scripts/menus/pause_submenu.lua:39: No value with key 'save_dialog.yes' in strings.dat for language 'fr'
Error: In on_draw: scripts/menus/pause_submenu.lua:110: attempt to index field 'caption_text_2' (a nil value)
Title: Re: Menu de game-over + inventaire en 1.6
Post by: Christopho on January 14, 2018, 09:39:59 PM
D'après le premier message d'erreur, je dirais que tu as oublié de mettre en place une langue.

sol.language.set_language("fr")
Title: Re: Menu de game-over + inventaire en 1.6
Post by: Finkatore on January 15, 2018, 11:29:20 AM
If I did not read it, I would not benefit from it.
Title: Re: Menu de game-over + inventaire en 1.6
Post by: Lucifer on January 15, 2018, 05:36:02 PM
Maintenant, ça me fait ça :
Info: Solarus 1.6.0
Info: Opening quest 'C:/Users/Hpo/Desktop/The legend of Zelda Hyrule Adventure'
Info: Sound volume: 100
Info: Music volume: 100
Info: Joypad support enabled: true
Info: 2D acceleration: yes
Info: Turbo mode: no
Info: Video mode: normal
Info: LuaJIT: yes (LuaJIT 2.0.3)
Info: Language: fr
Info: Lua console: yes
Info: Simulation started
Info: Language: fr
Error: In on_started: scripts/menus/pause_submenu.lua:72: attempt to call method 'set_custom_command_effect' (a nil value)
Error: In on_draw: scripts/menus/pause_inventory.lua:195: attempt to index field 'cursor_sprite' (a nil value)
Error: In on_draw: scripts/menus/pause_inventory.lua:195: attempt to index field 'cursor_sprite' (a nil value)
Error: In on_draw: scripts/menus/pause_inventory.lua:195: attempt to index field 'cursor_sprite' (a nil value)
Error: In on_draw: scripts/menus/pause_inventory.lua:195: attempt to index field 'cursor_sprite' (a nil value)
Error: In on_draw: scripts/menus/pause_inventory.lua:195: attempt to index field 'cursor_sprite' (a nil value)
Error: In on_draw: scripts/menus/pause_inventory.lua:195: attempt to index field 'cursor_sprite' (a nil value)
Error: In on_draw: scripts/menus/pause_inventory.lua:195: attempt to index field 'cursor_sprite' (a nil value)
Error: In on_draw: scripts/menus/pause_inventory.lua:195: attempt to index field 'cursor_sprite' (a nil value)
Error: In on_draw: scripts/menus/pause_inventory.lua:195: attempt to index field 'cursor_sprite' (a nil value)
Error: In on_draw: scripts/menus/pause_inventory.lua:195: attempt to index field 'cursor_sprite' (a nil value)
Error: In on_draw: scripts/menus/pause_inventory.lua:195: attempt to index field 'cursor_sprite' (a nil value)
Error: In on_draw: scripts/menus/pause_inventory.lua:195: attempt to index field 'cursor_sprite' (a nil value)
Error: In on_draw: scripts/menus/pause_inventory.lua:195: attempt to index field 'cursor_sprite' (a nil value)
Error: In on_draw: scripts/menus/pause_inventory.lua:195: attempt to index field 'cursor_sprite' (a nil value)
Error: In on_draw: scripts/menus/pause_inventory.lua:195: attempt to index field 'cursor_sprite' (a nil value)
Error: In on_draw: scripts/menus/pause_inventory.lua:195: attempt to index field 'cursor_sprite' (a nil value)
Error: In on_draw: scripts/menus/pause_inventory.lua:195: attempt to index field 'cursor_sprite' (a nil value)
Error: In on_draw: scripts/menus/pause_inventory.lua:195: attempt to index field 'cursor_sprite' (a nil value)
Error: In on_draw: scripts/menus/pause_inventory.lua:195: attempt to index field 'cursor_sprite' (a nil value)
Error: In on_draw: scripts/menus/pause_inventory.lua:195: attempt to index field 'cursor_sprite' (a nil value)
Error: In on_draw: scripts/menus/pause_inventory.lua:195: attempt to index field 'cursor_sprite' (a nil value)
Error: In on_draw: scripts/menus/pause_inventory.lua:195: attempt to index field 'cursor_sprite' (a nil value)
Error: In on_draw: scripts/menus/pause_inventory.lua:195: attempt to index field 'cursor_sprite' (a nil value)
Error: In on_finished: scripts/menus/pause_inventory.lua:84: attempt to call method 'get_hud' (a nil value)
Info: Simulation finished

pour l'inventaire, j'ai pris les ressources de zelda xd2
Title: Re: Menu de game-over + inventaire en 1.6
Post by: Lucifer on January 16, 2018, 05:23:17 PM
Et maintenant, ça me fait
Error: In on_draw: scripts/menus/pause_inventory.lua:195: attempt to perform arithmetic on field 'cursor_column' (a nil value)
En attente de votre réponse,
Merci
Lucifer
Title: Re: Menu de game-over + inventaire en 1.6
Post by: Christopho on January 25, 2018, 06:06:10 PM
Comme a dit froggy77, tu nous donnes des messages d'erreurs puis d'autres sans donner le code. Ni ce qui a changé entre tes différents rapports d'erreurs.

Mais le message d'erreur est assez clair, il y a une variable cursor_column utilisée à la ligne 95 alors qu'elle n'est pas définie.

Title: Re: Menu de game-over + inventaire en 1.6
Post by: Lucifer on January 26, 2018, 01:04:54 PM
Voici mon code :
Code ( lua) Select
local submenu = require("scripts/menus/pause_submenu")
local inventory_submenu = submenu:new()

local item_names = {
  "feather",
  "bomb_counter",
  "bow",
  "lamp",
  "pegasus_shoes",
  "bottle_1",

  "hookshot",
  "boomerang",
  "fire_rod",
  "glove",
  "bottle_2",

  "flippers",
  "bottle_3",
}

function inventory_submenu:on_started()

  submenu.on_started(self)

  self.cursor_sprite = sol.sprite.create("menus/pause_cursor")
  self.sprites = {}
  self.counters = {}
  self.captions = {}

  for k = 1, #item_names do
    if item_names[k] ~= "" then
      -- Get the item, its possession state and amount.
      local item = self.game:get_item(item_names[k])
      local variant = item:get_variant()

      if variant > 0 then
        if item:has_amount() then
          -- Show a counter in this case.
          local amount = item:get_amount()
          local maximum = item:get_max_amount()

          self.counters[k] = sol.text_surface.create{
            horizontal_alignment = "center",
            vertical_alignment = "top",
            text = item:get_amount(),
            font = (amount == maximum) and "green_digits" or "white_digits",
          }
        end

        -- Initialize the sprite and the caption string.
        self.sprites[k] = sol.sprite.create("entities/items")
        self.sprites[k]:set_animation(item_names[k])
        self.sprites[k]:set_direction(variant - 1)
      end
    end
  end

  -- Initialize the cursor
  local index = self.game:get_value("pause_inventory_last_item_index") or 0
  local cursor_row = math.floor(index / 7)
  local cursor_column = index % 7
  self:set_cursor_position(row, column)
end

function inventory_submenu:on_finished()

  if submenu.on_finished then
    submenu.on_finished(self)
  end

  if self:is_assigning_item() then
    self:finish_assigning_item()
  end

  local hud = self.game:get_hud()
  if hud ~= nil then
    self.game:get_hud():set_item_icon_opacity(1, 255)
    self.game:get_hud():set_item_icon_opacity(2, 255)
  end
end

function inventory_submenu:set_cursor_position(row, column)

  self.cursor_row = row
  self.cursor_column = column

  local index = row * 7 + column
  self.game:set_value("pause_inventory_last_item_index", index)

  -- Update the caption text and the action icon.
  local item_name = item_names[index + 1]
  local item = item_name and item_name ~= "" and self.game:get_item(item_name) or nil
  local variant = item and item:get_variant() or 0

  local item_icon_opacity = 128
  if variant > 0 then
    self:set_caption("inventory.caption.item." .. item_name .. "." .. variant)
    self.game:set_custom_command_effect("action", "info")
    if item:is_assignable() then
      item_icon_opacity = 255
    end
  else
    self:set_caption(nil)
    self.game:set_custom_command_effect("action", nil)
  end
  self.game:get_hud():set_item_icon_opacity(1, item_icon_opacity)
  self.game:get_hud():set_item_icon_opacity(2, item_icon_opacity)
end

function inventory_submenu:get_selected_index()

  return self.cursor_row * 7 + self.cursor_column
end

function inventory_submenu:is_item_selected()

  local item_name = item_names[self:get_selected_index() + 1]
  return self.game:get_item(item_name):get_variant() > 0
end

function inventory_submenu:on_command_pressed(command)

  local handled = submenu.on_command_pressed(self, command)

  if not handled then

    if command == "action" then
      if self.game:get_command_effect("action") == nil
            and self.game:get_custom_command_effect("action") == "info" then
        self:show_info_message()
        handled = true
      end

    elseif command == "item_1" then
      if self:is_item_selected() then
        self:assign_item(1)
        handled = true
      end

    elseif command == "item_2" then
      if self:is_item_selected() then
        self:assign_item(2)
        handled = true
      end

    elseif command == "left" then
      if self.cursor_column == 0 then
        self:previous_submenu()
      else
        sol.audio.play_sound("cursor")
        self:set_cursor_position(self.cursor_row, self.cursor_column - 1)
      end
      handled = true

    elseif command == "right" then
      if self.cursor_column == 6 then
        self:next_submenu()
      else
        sol.audio.play_sound("cursor")
        self:set_cursor_position(self.cursor_row, self.cursor_column + 1)
      end
      handled = true

    elseif command == "up" then
      sol.audio.play_sound("cursor")
      self:set_cursor_position((self.cursor_row + 3) % 4, self.cursor_column)
      handled = true

    elseif command == "down" then
      sol.audio.play_sound("cursor")
      self:set_cursor_position((self.cursor_row + 1) % 4, self.cursor_column)
      handled = true

    end
  end

  return handled
end

function inventory_submenu:on_draw(dst_surface)

  self:draw_background(dst_surface)
  self:draw_caption(dst_surface)

-- Draw the cursor.
  self.cursor_sprite:draw(dst_surface, 64 + 32 * self.cursor_column, 77 + 32 * self.cursor_row)

  -- Draw each inventory item.
  local y = 82
  local k = 0

  for i = 0, 3 do
    local x = 64

    for j = 0, 6 do
      k = k + 1
      if item_names[k] ~= nil and item_names[k] ~= "" then
        local item = self.game:get_item(item_names[k])
        if item:get_variant() > 0 then
          -- The player has this item: draw it.
          self.sprites[k]:draw(dst_surface, x, y)
          if self.counters[k] ~= nil then
            self.counters[k]:draw(dst_surface, x + 8, y)
          end
        end
      end
      x = x + 32
    end
    y = y + 32
  end

  -- Draw the item being assigned if any.
  if self:is_assigning_item() then
    self.item_assigned_sprite:draw(dst_surface)
  end

  self:draw_save_dialog_if_any(dst_surface)
end

-- Shows a message describing the item currently selected.
-- The player is supposed to have this item.
function inventory_submenu:show_info_message()

  local item_name = item_names[self:get_selected_index() + 1]
  local variant = self.game:get_item(item_name):get_variant()
  local map = self.game:get_map()

  -- Position of the dialog (top or bottom).
  if self.cursor_row >= 2 then
    self.game:get_dialog_box():set_position("top")  -- Top of the screen.
  else
    self.game:get_dialog_box():set_position("bottom")  -- Bottom of the screen.
  end

  self.game:set_custom_command_effect("action", nil)
  self.game:set_custom_command_effect("attack", nil)
  self.game:start_dialog("_item_description." .. item_name .. "." .. variant, function()
    self.game:set_custom_command_effect("action", "info")
    self.game:set_custom_command_effect("attack", "save")
    self.game:get_dialog_box():set_position("auto")  -- Back to automatic position.
  end)

end

-- Assigns the selected item to a slot (1 or 2).
-- The operation does not take effect immediately: the item picture is thrown to
-- its destination icon, then the assignment is done.
-- Nothing is done if the item is not assignable.
function inventory_submenu:assign_item(slot)

  local index = self:get_selected_index() + 1
  local item_name = item_names[index]
  local item = self.game:get_item(item_name)

  -- If this item is not assignable, do nothing.
  if not item:is_assignable() then
    return
  end

  -- If another item is being assigned, finish it immediately.
  if self:is_assigning_item() then
    self:finish_assigning_item()
  end

  -- Memorize this item.
  self.item_assigned = item
  self.item_assigned_sprite = sol.sprite.create("entities/items")
  self.item_assigned_sprite:set_animation(item_name)
  self.item_assigned_sprite:set_direction(item:get_variant() - 1)
  self.item_assigned_destination = slot

  -- Play the sound.
  sol.audio.play_sound("throw")

  -- Compute the movement.
  local x1 = 60 + 32 * self.cursor_column
  local y1 = 75 + 32 * self.cursor_row
  local x2 = (slot == 1) and 20 or 72
  local y2 = 46

  self.item_assigned_sprite:set_xy(x1, y1)
  local movement = sol.movement.create("target")
  movement:set_target(x2, y2)
  movement:set_speed(500)
  movement:start(self.item_assigned_sprite, function()
    self:finish_assigning_item()
  end)
end

-- Returns whether an item is currently being thrown to an icon.
function inventory_submenu:is_assigning_item()
  return self.item_assigned_sprite ~= nil
end

-- Stops assigning the item right now.
-- This function is called when we want to assign the item without
-- waiting for its throwing movement to end, for example when the inventory submenu
-- is being closed.
function inventory_submenu:finish_assigning_item()

  -- If the item to assign is already assigned to the other icon, switch both items.
  local slot = self.item_assigned_destination
  local current_item = self.game:get_item_assigned(slot)
  local other_item = self.game:get_item_assigned(3 - slot)

  if other_item == self.item_assigned then
    self.game:set_item_assigned(3 - slot, current_item)
  end
  self.game:set_item_assigned(slot, self.item_assigned)

  self.item_assigned_sprite:stop_movement()
  self.item_assigned_sprite = nil
  self.item_assigned = nil
end

return inventory_submenu



comment puis-je faire pour la définir ?
Title: Re: Menu de game-over + inventaire en 1.6
Post by: Christopho on January 26, 2018, 03:00:23 PM
D'où vient ce script exactement ?
Title: Re: Menu de game-over + inventaire en 1.6
Post by: Lucifer on January 26, 2018, 03:40:43 PM
Zelda XD2
Title: Re: Menu de game-over + inventaire en 1.6
Post by: Christopho on January 26, 2018, 04:22:08 PM
Quote from: Lucifer on January 26, 2018, 03:40:43 PM
Zelda XD2
Peut-être mais avec des mauvais changements alors.

Voici ton code :
Code (lua) Select

...
  -- Initialize the cursor
  local index = self.game:get_value("pause_inventory_last_item_index") or 0
  local cursor_row = math.floor(index / 7)
  local cursor_column = index % 7
  self:set_cursor_position(row, column)
...


Et celui de Zelda XD2 :
(https://github.com/solarus-games/zelda-xd2-mercuris-chess/blob/dev/data/scripts/menus/pause_inventory.lua#L69)
Code (lua) Select

...
  -- Initialize the cursor
  local index = self.game:get_value("pause_inventory_last_item_index") or 0
  local row = math.floor(index / 7)
  local column = index % 7
  self:set_cursor_position(row, column)
...


Le message d'erreur pointe vers cet endroit. Il y a au moins cette différence qui explique que ton curseur soit mal initialisé.
Title: Re: Menu de game-over + inventaire en 1.6
Post by: Lucifer on January 26, 2018, 04:43:25 PM
quand je lance zelda xd2 qui a pourtant le même code, ça fonctionne, or si j'allume l'inventaire sur ma partie, ça ne marche pas
Title: Re: Menu de game-over + inventaire en 1.6
Post by: Christopho on January 26, 2018, 05:11:39 PM
Je viens de te pointer l'endroit qui montre que ce n'est pas le même code.
Title: Re: Menu de game-over + inventaire en 1.6
Post by: Lucifer on January 26, 2018, 05:14:22 PM
j'ai remis le code de zelda xd2, mais ça ne marche toujours pas...
Title: Re: Menu de game-over + inventaire en 1.6
Post by: Christopho on January 26, 2018, 05:29:29 PM
Encore une fois, il va falloir quelque chose de plus précis que "ça ne marche pas"
Title: Re: Menu de game-over + inventaire en 1.6
Post by: Lucifer on January 26, 2018, 09:40:14 PM
voici mon nouveau code :
Code ( lua) Select
local submenu = require("scripts/menus/pause_submenu")
local inventory_submenu = submenu:new()

local item_names = {
  "feather",
  "bombs_counter",
  "bow",
  "lamp",
  "pegasus_shoes",
  "lens_of_truth",
  "bottle_1",

  "hookshot",
  "boomerang",
  "fire_rod",
  "pains_au_chocolat_counter",
  "croissants_counter",
  "glove",
  "bottle_2",

  "cat_food",
  "mail_counter",
  "perfume_counter",
  "banana_skin_counter",
  "vip_card",
  "flippers",
  "bottle_3",
}

function inventory_submenu:on_started()

  submenu.on_started(self)

  self.cursor_sprite = sol.sprite.create("menus/pause_cursor")
  self.sprites = {}
  self.counters = {}
  self.captions = {}

  for k = 1, #item_names do
    if item_names[k] ~= "" then
      -- Get the item, its possession state and amount.
      local item = self.game:get_item(item_names[k])
      local variant = item:get_variant()

      if variant > 0 then
        if item:has_amount() then
          -- Show a counter in this case.
          local amount = item:get_amount()
          local maximum = item:get_max_amount()

          self.counters[k] = sol.text_surface.create{
            horizontal_alignment = "center",
            vertical_alignment = "top",
            text = item:get_amount(),
            font = (amount == maximum) and "green_digits" or "white_digits",
          }
        end

        -- Initialize the sprite and the caption string.
        self.sprites[k] = sol.sprite.create("entities/items")
        self.sprites[k]:set_animation(item_names[k])
        self.sprites[k]:set_direction(variant - 1)
      end
    end
  end

  -- Initialize the cursor
  local index = self.game:get_value("pause_inventory_last_item_index") or 0
  local row = math.floor(index / 7)
  local column = index % 7
  self:set_cursor_position(row, column)
end

function inventory_submenu:on_finished()

  if submenu.on_finished then
    submenu.on_finished(self)
  end

  if self:is_assigning_item() then
    self:finish_assigning_item()
  end

  local hud = self.game:get_hud()
  if hud ~= nil then
    self.game:get_hud():set_item_icon_opacity(1, 255)
    self.game:get_hud():set_item_icon_opacity(2, 255)
  end
end

function inventory_submenu:set_cursor_position(row, column)

  self.cursor_row = row
  self.cursor_column = column

  local index = row * 7 + column
  self.game:set_value("pause_inventory_last_item_index", index)

  -- Update the caption text and the action icon.
  local item_name = item_names[index + 1]
  local item = item_name and item_name ~= "" and self.game:get_item(item_name) or nil
  local variant = item and item:get_variant() or 0

  local item_icon_opacity = 128
  if variant > 0 then
    self:set_caption("inventory.caption.item." .. item_name .. "." .. variant)
    self.game:set_custom_command_effect("action", "info")
    if item:is_assignable() then
      item_icon_opacity = 255
    end
  else
    self:set_caption(nil)
    self.game:set_custom_command_effect("action", nil)
  end
  self.game:get_hud():set_item_icon_opacity(1, item_icon_opacity)
  self.game:get_hud():set_item_icon_opacity(2, item_icon_opacity)
end

function inventory_submenu:get_selected_index()

  return self.cursor_row * 7 + self.cursor_column
end

function inventory_submenu:is_item_selected()

  local item_name = item_names[self:get_selected_index() + 1]
  return self.game:get_item(item_name):get_variant() > 0
end

function inventory_submenu:on_command_pressed(command)

  local handled = submenu.on_command_pressed(self, command)

  if not handled then

    if command == "action" then
      if self.game:get_command_effect("action") == nil
            and self.game:get_custom_command_effect("action") == "info" then
        self:show_info_message()
        handled = true
      end

    elseif command == "item_1" then
      if self:is_item_selected() then
        self:assign_item(1)
        handled = true
      end

    elseif command == "item_2" then
      if self:is_item_selected() then
        self:assign_item(2)
        handled = true
      end

    elseif command == "left" then
      if self.cursor_column == 0 then
        self:previous_submenu()
      else
        sol.audio.play_sound("cursor")
        self:set_cursor_position(self.cursor_row, self.cursor_column - 1)
      end
      handled = true

    elseif command == "right" then
      if self.cursor_column == 6 then
        self:next_submenu()
      else
        sol.audio.play_sound("cursor")
        self:set_cursor_position(self.cursor_row, self.cursor_column + 1)
      end
      handled = true

    elseif command == "up" then
      sol.audio.play_sound("cursor")
      self:set_cursor_position((self.cursor_row + 3) % 4, self.cursor_column)
      handled = true

    elseif command == "down" then
      sol.audio.play_sound("cursor")
      self:set_cursor_position((self.cursor_row + 1) % 4, self.cursor_column)
      handled = true

    end
  end

  return handled
end

function inventory_submenu:on_draw(dst_surface)

  self:draw_background(dst_surface)
  self:draw_caption(dst_surface)

-- Draw the cursor.
  self.cursor_sprite:draw(dst_surface, 64 + 32 * self.cursor_column, 77 + 32 * self.cursor_row)

  -- Draw each inventory item.
  local y = 82
  local k = 0

  for i = 0, 3 do
    local x = 64

    for j = 0, 6 do
      k = k + 1
      if item_names[k] ~= nil and item_names[k] ~= "" then
        local item = self.game:get_item(item_names[k])
        if item:get_variant() > 0 then
          -- The player has this item: draw it.
          self.sprites[k]:draw(dst_surface, x, y)
          if self.counters[k] ~= nil then
            self.counters[k]:draw(dst_surface, x + 8, y)
          end
        end
      end
      x = x + 32
    end
    y = y + 32
  end

  -- Draw the item being assigned if any.
  if self:is_assigning_item() then
    self.item_assigned_sprite:draw(dst_surface)
  end

  self:draw_save_dialog_if_any(dst_surface)
end

-- Shows a message describing the item currently selected.
-- The player is supposed to have this item.
function inventory_submenu:show_info_message()

  local item_name = item_names[self:get_selected_index() + 1]
  local variant = self.game:get_item(item_name):get_variant()
  local map = self.game:get_map()

  -- Position of the dialog (top or bottom).
  if self.cursor_row >= 2 then
    self.game:get_dialog_box():set_position("top")  -- Top of the screen.
  else
    self.game:get_dialog_box():set_position("bottom")  -- Bottom of the screen.
  end

  self.game:set_custom_command_effect("action", nil)
  self.game:set_custom_command_effect("attack", nil)
  self.game:start_dialog("_item_description." .. item_name .. "." .. variant, function()
    self.game:set_custom_command_effect("action", "info")
    self.game:set_custom_command_effect("attack", "save")
    self.game:get_dialog_box():set_position("auto")  -- Back to automatic position.
  end)

end

-- Assigns the selected item to a slot (1 or 2).
-- The operation does not take effect immediately: the item picture is thrown to
-- its destination icon, then the assignment is done.
-- Nothing is done if the item is not assignable.
function inventory_submenu:assign_item(slot)

  local index = self:get_selected_index() + 1
  local item_name = item_names[index]
  local item = self.game:get_item(item_name)

  -- If this item is not assignable, do nothing.
  if not item:is_assignable() then
    return
  end

  -- If another item is being assigned, finish it immediately.
  if self:is_assigning_item() then
    self:finish_assigning_item()
  end

  -- Memorize this item.
  self.item_assigned = item
  self.item_assigned_sprite = sol.sprite.create("entities/items")
  self.item_assigned_sprite:set_animation(item_name)
  self.item_assigned_sprite:set_direction(item:get_variant() - 1)
  self.item_assigned_destination = slot

  -- Play the sound.
  sol.audio.play_sound("throw")

  -- Compute the movement.
  local x1 = 60 + 32 * self.cursor_column
  local y1 = 75 + 32 * self.cursor_row
  local x2 = (slot == 1) and 20 or 72
  local y2 = 46

  self.item_assigned_sprite:set_xy(x1, y1)
  local movement = sol.movement.create("target")
  movement:set_target(x2, y2)
  movement:set_speed(500)
  movement:start(self.item_assigned_sprite, function()
    self:finish_assigning_item()
  end)
end

-- Returns whether an item is currently being thrown to an icon.
function inventory_submenu:is_assigning_item()
  return self.item_assigned_sprite ~= nil
end

-- Stops assigning the item right now.
-- This function is called when we want to assign the item without
-- waiting for its throwing movement to end, for example when the inventory submenu
-- is being closed.
function inventory_submenu:finish_assigning_item()

  -- If the item to assign is already assigned to the other icon, switch both items.
  local slot = self.item_assigned_destination
  local current_item = self.game:get_item_assigned(slot)
  local other_item = self.game:get_item_assigned(3 - slot)

  if other_item == self.item_assigned then
    self.game:set_item_assigned(3 - slot, current_item)
  end
  self.game:set_item_assigned(slot, self.item_assigned)

  self.item_assigned_sprite:stop_movement()
  self.item_assigned_sprite = nil
  self.item_assigned = nil
end

return inventory_submenu



et l'erreur : Error: In on_draw: scripts/menus/pause_inventory.lua:195: attempt to perform arithmetic on field 'cursor_column' (a nil value)
Title: Re: Menu de game-over + inventaire en 1.6
Post by: Christopho on January 26, 2018, 09:54:14 PM
Alors vérifie que cursor_column a bien été initialisé (ligne 94).
Title: Re: Menu de game-over + inventaire en 1.6
Post by: Lucifer on January 27, 2018, 08:23:24 AM
Code ( lua) Select
function inventory_submenu:set_cursor_position(row, column)

  self.cursor_row = row
  self.cursor_column = column

mais, il y a la même erreur
Title: Re: Menu de game-over + inventaire en 1.6
Post by: Christopho on January 27, 2018, 10:54:02 AM
Et donc cursor_column vaut combien ?
Comme expliqué dans le premier tuto, il faut un minimum de bases de programmation pour pouvoir débugguer. Commence par un tuto Lua.
Title: Re: Menu de game-over + inventaire en 1.6
Post by: MetalZelda on January 27, 2018, 01:28:28 PM
De ce que je vois soit un item n'existe pas (et donc ne peut pas être placé) soit il y'a une erreur d'initialisation. Je pencherais plus pour la 1ere hypothèse.
Title: Re: Menu de game-over + inventaire en 1.6
Post by: Lucifer on January 29, 2018, 01:04:23 PM
J'ai regardé, il s'agit d'une erreur d'initialisation...
Title: Re: Menu de game-over + inventaire en 1.6
Post by: Christopho on January 29, 2018, 02:02:37 PM
D'où ce que suggère : vérifier la valeur de cursor_column.
Title: Re: Menu de game-over + inventaire en 1.6
Post by: Lucifer on January 29, 2018, 09:27:49 PM
 Est-ce bien ceci ?
Code ( lua) Select
  -- Initialize the cursor
  local index = self.game:get_value("pause_inventory_last_item_index") or 0
  local row = math.floor(index / 7)
  local column = index % 7
  self:set_cursor_position(row, column)
end
Title: Re: Résolu : Menu de game-over + inventaire en 1.6
Post by: Lucifer on March 14, 2018, 05:09:04 PM
Merci beaucoup, j'ai trouvé en prenant les ressources de alttd.