Solarus-Games English Forum

Solarus => Development => Topic started by: hood_rad on September 08, 2019, 11:26:23 PM

Title: Text box appearing when getting an item
Post by: hood_rad on September 08, 2019, 11:26:23 PM
Im probably missing something really simple but I'm following the tutorials and I'm trying to get dialog's to work right now when getting an item when opening a chest for example. In the tutorial it says to add sol.language.set_language("en") to main.lua but that didn't help at all and when I looked at a sample quest it didn't have that line of code in it either but still had text pop up when opening a chest and getting a sword. I also know I have the text setup in dialogs.dat the exact same as in the tutorial. Has something changed since the tutorial and I need to do something different to get dialog's working?
Title: Re: Text box appearing when getting an item
Post by: ponderitus on September 09, 2019, 11:51:37 AM
do you get an error when you open the chest?

what does your main.lua look like? paste it after clicking the hashtag icon "insert code" button. (12th button 2nd row)

in the quest editor when you click on languages there will be an "en"...right click that and "open dialogs" to get to the dialog editor and if you havent got a dialog for that item..the rest are under _treasure.sword.1, _treasure.shield.1, ect...
Title: Re: Text box appearing when getting an item
Post by: hood_rad on September 09, 2019, 09:42:15 PM
Thanks for the reply! No I dont get any errors and my dialog editor has dialog for my items under _treasure.sword.1, _treasure.shield.1 etc...

Here is the main.lua code:
-- Main Lua script of the quest.

require("scripts/features")
local initial_menus_config = require("scripts/menus/initial_menus_config")
local initial_menus = {}

-- This function is called when Solarus starts.
function sol.main:on_started()

  sol.language.set_language("en")

  sol.main.load_settings()
  math.randomseed(os.time())

  -- Show the initial menus.
  if #initial_menus_config == 0 then
    return
  end

  for _, menu_script in ipairs(initial_menus_config) do
    initial_menus[#initial_menus + 1] = require(menu_script)
  end

  local on_top = false  -- To keep the debug menu on top.
  sol.menu.start(sol.main, initial_menus[1], on_top)
  for i, menu in ipairs(initial_menus) do
    function menu:on_finished()
      if sol.main.game ~= nil then
        -- A game is already running (probably quick start with a debug key).
        return
      end
      local next_menu = initial_menus[i + 1]
      if next_menu ~= nil then
        sol.menu.start(sol.main, next_menu)
      end
    end
  end

end

-- Event called when the program stops.
function sol.main:on_finished()

  sol.main.save_settings()
end

-- Event called when the player pressed a keyboard key.
function sol.main:on_key_pressed(key, modifiers)

  local handled = false
  if key == "f11" or
    (key == "return" and (modifiers.alt or modifiers.control)) then
    -- F11 or Ctrl + return or Alt + Return: switch fullscreen.
    sol.video.set_fullscreen(not sol.video.is_fullscreen())
    handled = true
  elseif key == "f4" and modifiers.alt then
    -- Alt + F4: stop the program.
    sol.main.exit()
    handled = true
  elseif key == "escape" and sol.main.game == nil then
    -- Escape in title screens: stop the program.
    sol.main.exit()
    handled = true
  end

  return handled
end

-- Starts a game.
function sol.main:start_savegame(game)

  -- Skip initial menus if any.
  for _, menu in ipairs(initial_menus) do
    sol.menu.stop(menu)
  end

  sol.main.game = game
  game:start()
end


Also as a side note I do get the save and quit text so it shouldn't be because I don't have a language set

Thanks again for the suggestions and help
Title: Re: Text box appearing when getting an item
Post by: Max on September 11, 2019, 02:09:23 PM
Hmm, it's probably just a small mistake, but it's hard to say where if you aren't getting error messages.

If you set the item as a pickable, instead of in a chest, do you still not get the dialogue? If there's no dialogue for an item you pick up as a pickable, there will just be a 1-2 second pause where the hero is holding the item and nothing is happening. If that pause is happening, it's definitely the item not finding the dialog. Does the item's script have item:set_brandish()? The item might be not displaying the dialog because of some code in the item.
Title: Re: Text box appearing when getting an item
Post by: hood_rad on September 11, 2019, 09:22:45 PM
When its set as a pickupable I still dont get the text but it plays the animation. I think your right about the item just not having the script that calls for the text because I dont see any code for it in the items script. This is the script for the sword:
local item = ...
local game = item:get_game()

function item:on_created()
  item:set_savegame_variable("possession_sword")
end

function item:on_variant_changed(variant)
  game:set_ability("sword", variant)
end


Thanks again for the help!
Title: Re: Text box appearing when getting an item
Post by: ponderitus on September 12, 2019, 12:53:47 AM
have you tried with an npc? the text for the save and quit is most probably a menu not a dialog so thats why that would still show.

make an npc and set it to speak...see if that brings an error
Title: Re: Text box appearing when getting an item
Post by: hood_rad on September 12, 2019, 03:00:41 AM
Just tried with an npc using _treasure.sword.1 and I got the text with no errors. Is there an easy way to change what dialog is used when getting an item? I feel like I'm just really dumb and missing something super simple.

thanks!
Title: Re: Text box appearing when getting an item
Post by: hood_rad on September 12, 2019, 03:13:28 AM
so I found the code sol.language.get_dialog() in the solarus documentation pdf and I think that might be what I'm missing but cant get it to work either. Is there a certain function in my sword.lua that it should be used in or something like that maybe?
Title: Re: Text box appearing when getting an item
Post by: ponderitus on September 12, 2019, 04:11:58 AM
i dont know what you're doing but you shouldn't have to do anything like this, where have you started from? id suggest redownloading solarus and the resource pack if thats what you are using
Title: Re: Text box appearing when getting an item
Post by: Max on September 12, 2019, 04:19:54 AM
I dropped your item's code into my sword item, and it displayed the dialog when I picked it up, so it's not your code there, and if you're getting any dialogs at all, it's not setting the language in main.lua.

Your item is called "sword", right? Since the engine uses the item's name to search for a matching dialog in the _treasures dialogs. That's the only other thing I can think of at the moment :^0
Title: Re: Text box appearing when getting an item
Post by: llamazing on September 12, 2019, 05:29:49 AM
You don't need any code in your sword.lua for the dialog to be shown, it's all automatic. The dialog for an item is always shown when you get an item from a chest (unless you didn't define its dialog).

The dialog displayed corresponds to the item name. So the "_treasure.sword.1" dialog is shown when you pick up the first variant of the sword, "_treasure.sword.2" when you pick up the second variant. The dialog "_treasure.boomerang.1" is shown when you pick up the first variant of the boomerang, etc.
Title: Re: Text box appearing when getting an item
Post by: hood_rad on September 12, 2019, 09:47:53 PM
ok so I tried using a freshly extracted solarus quest editor, made a new quest and all I did was add the resource pack called "solarus-alttp-pack-master", added dialogue for _treasure.sword.1 and changed my starting location to "test_map/test_map" and still didn't get text. Maybe its the resource pack? Or I'm just really dumb which is more likely.
Title: Re: Text box appearing when getting an item
Post by: hood_rad on September 12, 2019, 09:52:33 PM
ok so I think it has to do with the resource pack because I tried making a quest and only adding the sword.lua file and the sword sprite and I was able to get the text
Title: Re: Text box appearing when getting an item
Post by: llamazing on September 13, 2019, 12:53:45 AM
I think it's because the alttp resource pack does not set a language by default. On cursory examination it looks like there's some language selection menu you have to open to set it first.

add the line: sol.language.set_language("en")

You can also try starting a dialog manually with game:start_dialog(dialog_id) to test whether a language has been set. If it hasn't then you'll get an error saying the language is not set.
Title: Re: Text box appearing when getting an item
Post by: Max on September 13, 2019, 02:54:37 AM
Could the sword item in that pack being in a subdirectory also be a factor? Also just gave a cursory glance.
Title: Re: Text box appearing when getting an item
Post by: hood_rad on September 13, 2019, 09:38:42 PM
sol.language.set_language("en") was already in my main.lua. Should it be added somewhere else? I tried adding game:start_dialog(_treasure.sword.1) to the item script and main.lua and I just get the error "Error: Failed to load script 'main': main.lua:11: ')' expected near '.1'" I also tried adding to main.lua and got the same error but no error about the language not being set. 

And I was thinking it might be something to do with the file directory that the item is in. I tried messing around by changing the dialog to "_treasure.equipment.sword.1" but haven't had any luck yet. Ill mess around a bit tonight to see if I can figure it out.

Thanks again for all the suggestions guys!
Title: Re: Text box appearing when getting an item
Post by: llamazing on September 13, 2019, 11:20:57 PM
You need quotes on the dialog:
game:start_dialog("_treasure.sword.1")
Title: Re: Text box appearing when getting an item
Post by: hood_rad on September 14, 2019, 12:08:50 AM
ok Im dumb sorry. I tried adding game:start_dialog("_treasure.sword.1") to sword.lua under function item:on_created() and under no function and I get this error for both: Error: In on_created: items/equipment/sword.lua:7: Cannot start dialog: this game is not running

should I be adding game:start_dialog("_treasure.sword.1") somewhere else maybe?
Title: Re: Text box appearing when getting an item
Post by: hood_rad on September 14, 2019, 12:13:09 AM
ok got it working by putting game:start_dialog("_treasure.sword.1") in function item:on_variant_changed(variant)
Title: Re: Text box appearing when getting an item
Post by: Max on September 14, 2019, 03:28:51 AM
Yeah, the on_created event is called before the game starts. It creates all the items, it's better than not creating the item in memory until you get it for a lot of reasons.

On variant changed would be the right place, but I still can't figure out why it wouldn't be playing automatically. If you game is on gitlab or GitHub I can pull it down and take a look if you want. Have you made other items and the dialogues display automatically?
Title: Re: Text box appearing when getting an item
Post by: Graw on April 17, 2020, 03:16:38 AM
Sorry to resurrect this topic but I ran into this problem and tried OP's solution but it led to a small delay after brandishing. I figured out that any items in subfolders need to have their dialog named as _treasure.subdirectory/item.

ie. For the sword with the alttp resource pack: _teasure.equipment/sword.1