Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Making a quest log; active quest strings always at top? [solved]

Discussion in 'Scripting' started by lemonrays, Aug 22, 2016.

  1. lemonrays

    lemonrays

    Joined:
    May 7, 2015
    Posts:
    48
    I feel like I'm thinking about this too hard, but I'm trying to make a quest log. With the quest system that I'm using, when a quest is active, its name and description (from an array of strings, an element for each quest) go into a Text object, and when it's inactive, it goes back to empty, i.e. " ". However, I'm not sure how to go about making the active quest strings always be at the top, or how to check for and omit the empty ones from the array. I hope the solution is easier than I'm making it out to be lol.
     
  2. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    If only the active quest has text just compare the string from the text component to the strings in your array.
     
  3. lemonrays

    lemonrays

    Joined:
    May 7, 2015
    Posts:
    48
    Multiple quests can be active at a time!
    Basically, right now, they just kinda appear in order; if you complete quest 1 before quest 2, there's just a giant space where quest 1 used to be. Would like to make it so that quest 2 moves up, if that makes sense.
     
  4. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,146
    I'd have to know more about your setup, but if you're using text objects within a scrollview content, you can just set up a layout group(grid or whatever you prefer) on the content object. All your text goes underneath. If quest aren't active, just turn off the text and the boxes will adjust. I'd also add a content size fitter to the content object.
    As far as ordering the quest, all children have an index assigned to them. So changing that index will change the order, or you can just use the setAsFirstSibling to move something to the top of the list
    https://docs.unity3d.com/ScriptReference/Transform.SetAsFirstSibling.html
     
  5. raycosantana

    raycosantana

    Joined:
    Dec 23, 2012
    Posts:
    319
    Use a "List<>" instead of an array, Lists can be rearranged, just have a List with the active quest and remove them when not active or completed, if you remove the first quest the next quest will move up by it self.

    To use Lists you need to add

    Code (CSharp):
    1. using System.Collections.Generic;
    To your script, to create a string list you do as follow:

    Code (CSharp):
    1.  List<string> MyQuestLog = new List<string>();
    and to add or remove you do this:

    Code (CSharp):
    1. MyQuestLog.Add( "you quest string goes here" );
    2.  
    3. MyQuestLog.Remove(0); // 0 its just an example.
    More info:
    https://msdn.microsoft.com/es-es/library/6sh2ey19(v=vs.110).aspx
     
  6. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    please tell me a quest is being stored as it's own class/struct... and you're not synchronizing two string arrays to hold the quest data.

    You can then either go with a pair of list for active/inactive quests (not string lists) or have a bool in that class/struct and a single list sorted by that bool(might be interested in "linq" for that).
     
  7. lemonrays

    lemonrays

    Joined:
    May 7, 2015
    Posts:
    48
    Thank you so much. I actually didn't know about lists before lol. I figured it out!
    I'm still using the array, too, but the specific elements of the array are "added" or "removed" to the list, depending on activation, etc. :p