Solarus-Games English Forum

Solarus => Development => Topic started by: Starlock on February 09, 2016, 06:18:52 PM

Title: Scrolling dialog selections?
Post by: Starlock on February 09, 2016, 06:18:52 PM
Hey, I'm planning to implement a crafting system that involves talking to NPCs and they will show a selection of craftables and the regents required to make them. I figured it would be easier to make this as a dialog that displays craftables and checks if you have the regents when you select it. Is it possible to have more than 4 selection in a dialog that you can scroll through or would I have to create a menu for a crafting system to be possible
Title: Re: Scrolling dialog selections?
Post by: Christopho on February 09, 2016, 06:39:24 PM
Dialogs are already menus in most games.
Title: Re: Scrolling dialog selections?
Post by: Starlock on February 09, 2016, 10:15:24 PM
So would a crafting system be something viable just using the dialog box?
Title: Re: Scrolling dialog selections?
Post by: Christopho on February 09, 2016, 11:04:43 PM
Sure, I don't see why not :)
Title: Re: Scrolling dialog selections?
Post by: Starlock on February 12, 2016, 03:09:43 AM
Would a new dialog box have to be coded or are zsdx or roth usable. Right now using a dialog box similar to the zsdx one I am only able to make 2 choice questions rather than a bunch of choices that you can scroll through.
Title: Re: Scrolling dialog selections?
Post by: Christopho on February 12, 2016, 08:39:17 AM
Well it has to be a modified version of the one of another game since you want to add new things.
Title: Re: Scrolling dialog selections?
Post by: Starlock on March 17, 2016, 03:30:43 AM
Forgot about this for a while, coming back to it now. I'm using Diarandor's current dialog box as a point of reference, but I kinda need a push in the right direction, I'm not too sure where to begin with this atm  ???
Title: Re: Scrolling dialog selections?
Post by: Diarandor on March 17, 2016, 09:01:56 AM
My dialog box is a modified version of Christopho's one, so all credit goes for him. It allows to use certain syntax to write color words, and the last version also adds commands to draw animated sprites.

Edit: @Starlock, you should start by studying the code, as I did, until you fully understand it. I remember it was not easy since the script is long, so be patient.
Title: Re: Scrolling dialog selections?
Post by: Starlock on March 20, 2016, 08:09:28 PM
I've started to work on it by making a hybrid between the zelda roth and zsdx dialog boxes. I can get the box to appear, but it's giving me an error about the text_surface on this chunk of code...
Code ( lua) Select
    if not special then
   
    text_surface:set_text(text_surface:get_text() .. current_char)
   

    -- If this is a multibyte character, also add the next byte.
    local byte = current_char:byte()
    if byte >= 192 and byte < 224 then
      -- The first byte is 110xxxxx: the character is stored with
      -- two bytes (utf-8).
      current_char = line:sub(self.char_index, self.char_index)
      self.char_index = self.char_index + 1
      text_surface:set_text(text_surface:get_text() .. current_char)
    end


I'm a bit confused as to why it doesn't work when text_surface is used earlier in the code with no problem

EDIT: I would've posted the full code, but it was over the limit  :-\
Title: Re: Scrolling dialog selections?
Post by: MetalZelda on March 20, 2016, 10:00:43 PM
What is the exact error ? Attempt to call a nil value ?
Title: Re: Scrolling dialog selections?
Post by: Starlock on March 20, 2016, 10:18:11 PM
Yes

Error: In timer callback: [string "scripts/dialog_box.lua"]:492: attempt to index local 'text_surface' (a nil value)

Sorry I forgot to write that in originally

EDIT: github link to full code     https://github.com/Star-Lock/LongSteel/blob/master/dialog_box
Title: Re: Scrolling dialog selections?
Post by: Starlock on April 02, 2016, 12:25:43 AM
I was able to get the dialog box to function properly. It has Diarandor's animations and colors as well as the ability the make more than 2 answers to questions from the Return of the Hylian

https://github.com/Star-Lock/LongSteel/blob/master/dialog_box

Title: Re: Scrolling dialog selections?
Post by: Starlock on April 04, 2016, 04:31:26 AM
I'm continuing to make a few changes to the dialog box code to make a crafting system smoother. I tried to make it so you can close the dialog box at any time when it is being used for crafting.

Code ( lua) Select
function game:on_key_pressed(key)
  if key == "escape" and
  self.dialog.id == "_crafting" then
sol.menu.stop(dialog_box)
end
game.dialog_box = nil
end


I'm getting the error Error: In on_key_pressed: [string "scripts/dialog_box.lua"]:149: attempt to inde
x field 'dialog' (a nil value)

I was trying to test the code using a dialog called "give_crafting" so I'm unsure why dialog would be a nil value
Title: Re: Scrolling dialog selections?
Post by: Diarandor on April 04, 2016, 01:46:44 PM
You have to learn how to debug by yourself.

The error speaks by itself: your variable "self.dialog" is nil, so you cannot index it with something like "self.dialog.id" (which makes no sense). You can only index lists, and a nil variable is not a list, obviously.