Search Unity

KINGS - Card Swiping Decision Game Asset

Discussion in 'Assets and Asset Store' started by Maulwurfmann, Nov 26, 2017.

  1. tieum67

    tieum67

    Joined:
    Mar 7, 2017
    Posts:
    61
    Hello ! I was building on Windows 10 and using Unity 2019.2.19.
    i'll clean the limits of the value. Thanks for your help!
     
  2. tieum67

    tieum67

    Joined:
    Mar 7, 2017
    Posts:
    61
    Hello , unfortunately the error strikes back... After a sucessfull build i had to change a few things in some cards ( typo errors). And since then i get the same error as before : the build and the unity game dont behave in the same way, in relation to values that have the "keep value" checked. As i had to finish the project, i unchecked the "keep value" stuff, and it works as expected. Can you let me know if one day this issue shows up for someone else and if there's a workaround ?
     
  3. KMDeclius

    KMDeclius

    Joined:
    Aug 12, 2019
    Posts:
    213
    Hi tieum67,
    I started a direct conversation.
    Greetings
     
  4. PavelLangweil

    PavelLangweil

    Joined:
    Mar 4, 2014
    Posts:
    28
    I actually managed to hack in support for importing simple value changes (like religion, health, money etc.) directly into the CSV column, per each card. It supports all the values, when you do just simple changes. Also added support for follow up cards to the csv import/export. I won't certainly do all possible settings this supports, but the most frequent ones are possible to add. It's not production quality code but ping me in case you want that functionality, might share the modified sources. I've got the recent version, I think 1.55.
     
  5. Tropobor

    Tropobor

    Joined:
    Mar 24, 2014
    Posts:
    73
    Hi,
    Is it ok to use Kings with Unity 2020 ?
     
  6. KMDeclius

    KMDeclius

    Joined:
    Aug 12, 2019
    Posts:
    213
    Hi Tropobor,
    I'm also curious, because 2020.1 become available but Unity itself recomends 2019 LTS for Projects in production.
    If your question is, if is allowed to use Kings with Unity 2020, then yes, this is allowed. But I'm not sure if everything works seamless with the new Version. One thing that sometimes changes on the side of Unity is the implementation for their Packages like the Advertisement, I had to adjust it several times.

    Did you test it with Unity 2020?
    If you see an issue or something is marked as deprecated, let me know.
    Perhaps I can also try it next week.
     
  7. Tropobor

    Tropobor

    Joined:
    Mar 24, 2014
    Posts:
    73
    So far so good :) It is just way better if on import you choose : "Skip" to Unity warning : "This Unity Package has Package Manager dependencies"
     
    KMDeclius likes this.
  8. Tropobor

    Tropobor

    Joined:
    Mar 24, 2014
    Posts:
    73
    Hi KMDeclius,
    Although I have bought your asset some time ago, I didn’t start using Kings yet, I have just been through the documentation and dedicated forum, so please bear with me if I ask stupid questions, however here are just a few :

    Dictionary system
    On page 40 of the documentation it’s written :
    “To keep an overview of all Dictionary entries we highly recommend to create a spreadsheet”
    Is it possible to do it with Imex?

    Card style
    Post #884 suggest that it could be possible to introduce UI text element (font, size, alignment…) in CardStyle, am I misinterpreting?

    Text Mesh Pro
    How far is the support for TMP? e.g. Typewriter text effect…

    Upgrade
    Following posts in your forum seem to bring valuable changes, do you think it would be possible to get an upgrade containing these ?
    #542 KingsImEx
    #608 QuestFromCards
    #656 ValueDependantText
    #708 Inventory
    #726 PopupUpdate
    #763 ConditionalFollowUpCardPool

    I guess that's all for now ;)
     
  9. KMDeclius

    KMDeclius

    Joined:
    Aug 12, 2019
    Posts:
    213
    The dictionary entries are generated by the game itself. The intention for a separat spreadsheet is for you to be aware which key value pair you set, e.g. if you use it for a condition.
    This is not included in the Import/Export (ImEx) script. We wanted to keep the functionality simple to catch the most changes and keep the resulting csv-file tidy. @falcan pointed out that he extended the import and export feature, but the definition of the "most frequent" settings varies from use case to use case.

    Should be possible with a little bit of coding. I made an example for setting the font from the card styles, other behaviour is also possible and depends on your requirements.
    ModifiedCardStyle_.gif

    Step 0: Make a backup of your project.

    Step 1: Extend the card style (file "KingsCardStyle.cs") so there's a field for your configuration
    Code (CSharp):
    1. [CreateAssetMenu]
    2. public class KingsCardStyle : ScriptableObject {
    3.  
    4.     public GameObject prefab;
    5.     public Color cardColor = Color.white;
    6.     public Sprite cardFront;
    7.     public Sprite cardBack;
    8.     public Sprite icon;
    9.     public Font titleTextFont; //<- Extension
    10. }
    Your card styles should now have a field for linking a font:
    upload_2020-9-4_23-28-21.png


    Step2: Code the actualization (file "CardStyle.cs" starting around line 35) so a text can be linked and it's font is actualized
    Code (CSharp):
    1.  
    2.     //Refresh style dependant images, colors etc.
    3.     public Text titleText;  //Extension: show a public text field
    4.     public void Refresh() {
    5.         if (style != null)
    6.         {
    7.             actualizeColoring();
    8.             actualizeImages();
    9.  
    10.             if(style.titleTextFont != null && titleText != null) //Extension: if theres a title text linked AND the cardstyle has a font configured then ...
    11.             {
    12.                 titleText.font = style.titleTextFont;   // ... actualize the font
    13.             }
    14.         }
    15.     }
    16.  
    Step 3: Link the title text to the the public text field for all prefabs which shall use this:
    upload_2020-9-4_23-32-18.png

    I hope this helps for the moment, more to folow.
     
  10. KMDeclius

    KMDeclius

    Joined:
    Aug 12, 2019
    Posts:
    213
    Typewriter uses "EventScript.C_Texts" in the background. I don't know if more things changed in Unity 2020, but enabling TMP (Documentation page 27) changes the input fields of the type writer from:
    upload_2020-9-4_23-50-51.png
    to
    upload_2020-9-4_23-49-47.png

    Please be aware, enabling TMP doesn't change every target text field. The simplest example is the the previous post where I only used "Text" instead of "TMPro.TextMeshProUGUI".
     
  11. KMDeclius

    KMDeclius

    Joined:
    Aug 12, 2019
    Posts:
    213
    Sorry, some of the Updates are mutual exclusive to previous behaviour. Unfortunately, I have not had much time at my disposal for some time now, because I work on some other projects. There are no updates planned at the moment.
     
  12. PavelLangweil

    PavelLangweil

    Joined:
    Mar 4, 2014
    Posts:
    28
    @Tropobor nice list of updates :) I've got some of them, wasn't aware of some of the others.

    @KMDeclius well I'd argue the "most frequent" is pretty clear for this case. You have the core values system as the basis of those decision games (people, wealth etc.), so you would expect them to be changed in most game cards(ie. a pretty frequent need). I'm defining all of that in Excel now and it's a much more coherent user experience than defining like 300 cards in Excel and then trying to do the rest of the work in Unity. In this case a little more rows in the csv doesn't make anything messy, but greatly improves your efficiency. I can see at first glance which core values each card changes.

    Great work with this asset otherwise, my game is about 90% complete now. There are some smaller issues, like with the "manual" achievements GameObjects (wish it was made like quests). A shame you stopped supporting it, otherwise I'd rate it 5 stars. I made couple more improvements, if anyone was interested:

    • You can also define "followup left" and "followup right" and import / export them from / to the CSV - works only for "Simple" mode. It was the 2nd most frequent thing I needed to do, but this might depend on the card game type you're doing (I have more talking, so more follow ups).
    • Added new type of card result: "Conditional tree" (next to Simple, Random etc.). Sometimes it seemed useful for my case to have a selection from multiple branches, where only one executes based on some condition(s). So let's say if someProgress==0, go to card 0, if someProgress==1, go to card 1, if someProgress==2, go to card 3 etc. It executes the first branch where all conditions are true, so you can have multiple conditions for each branch, all of them need to be true. It's kind of a waterfall system which didn't seem possible with the default conditional which supports true/false.
     
  13. KMDeclius

    KMDeclius

    Joined:
    Aug 12, 2019
    Posts:
    213
    Hi falcan,

    maybe you are right. I'm supporting this asset since some years and saw some requests and different opinions on what are the important parts. I remember one, where it was mainly a calculator... ;)
    But for it's intention, the value system is one the core features.

    Your "Conditional tree" sounds a little bit similar to my "ConditionalFollowUpCardPool" - script.
    from post #756 where I added it as an extra script. Great if you implemented it within the dropdown.

    Sorry, but this is not true. I'm still supporting it. By no updades I meant I have no time at the moment to make a full release. Nevertheless I'm at least once per day in the forum to support, write extensions etc. which I will realease here.

    Also thanks to @Tropobor, the list is great.
     
  14. Tropobor

    Tropobor

    Joined:
    Mar 24, 2014
    Posts:
    73
    Hi Falcan,
    I'm very interested with your Imex extension, but... /!\ Caution: just a graphic designer in prep stage here, w/ almost no skill in C#, apart basic understanding.
    Thanks for your feedbacks on this forum and and in the asset store reviews: It helps.
     
  15. Tropobor

    Tropobor

    Joined:
    Mar 24, 2014
    Posts:
    73
    Hi KMDeclius,
    Another question, In post #656 you said : "valueDependentTexts.cs" can also be used to do some other neat things. It supports ranges to generate texts, the left numbers are used as minimal values when the text will be shown.
    Would it be possible to store these “generated texts” and “left numbers” in a csv ?
     
  16. KMDeclius

    KMDeclius

    Joined:
    Aug 12, 2019
    Posts:
    213
    Something like this?

    ExtendedValueDependentTexts.gif

    I wrote a little parser into the file which can load text assets.
    Unescaping is not supported (please ensure theres no '"' in your texts).
    Empty lines in the csv should be ok.

    It will overwrite the original content, if theres a valid file. If an error in the csv is detected, it will throw an error and leave the original content as it is.

    I did put the csv file into a "Resources" Folder, because this name has a special meaning in Unity. I don't know if this is neccessary for this case.
    Please be aware, I didn't test this in a real build.

    If you want this functionality, please overwrite the attached file (make a backup of your project first). Or just add it, if it doesn't exist in your version.

    I also attached my test csv file as zip, because csv files are not allowed as attachement in the forum.

    I hope this helps.
     

    Attached Files:

  17. Tropobor

    Tropobor

    Joined:
    Mar 24, 2014
    Posts:
    73
    Yes! Not sure if you can imagine how much this helps :) This means that it is feasible to control display of quotes with some value, therefore can significantly reduce the number of possible cards to be used. Hope you don’t mind, if i’m not testing this just right now because I'm still in a stage where I'm trying to design a general project workflow… now, I have to dig into localization process. Great, great support by the way. Many thanks!
     
  18. PavelLangweil

    PavelLangweil

    Joined:
    Mar 4, 2014
    Posts:
    28
    @KMDeclius Yeah about the important parts ideas, I can imagine - I'm a software developer as well. This system is so universal it seduces you trying to make it something completely different. I guess one has to keep in mind it's called card decision system, not a calculator system - for a reason :)

    About the pool yes, it seems that's what I did, only better in giving more options in addition to the 'first fitting' case. I overlooked that before I saw the summary of the updates. If I knew I'd have updated to that, shame it's not in a new release! It seemed like I could implement it pretty fast by cloning and adjusting the Random code.

    Hmm, I wrote 2 emails to your email(support@km-games.com) after purchasing(weeks ago), but got no replies. Maybe check that your inbox is working fine? At that time there wasn't activity on the forums as well and no reply to my review, where I thought I'd get a reply more likely than here...so my conclusion was, support not working. I was in hurry so I just coded what I needed myself.

    And @Tropobor, well my updates are to several files and might be contradicting some of the other updates here, so you'd have to use it at your own risk (making backups and all that). Let me know which parts you're interested in the most, as I see KMDeclius already took care of the card pool thing, so the only significant thing for you might be the expanded CSV import/export support.
     
  19. PavelLangweil

    PavelLangweil

    Joined:
    Mar 4, 2014
    Posts:
    28
    @KMDeclius By the way, I encountered an issue, not sure if this is a result of my changes but I think it's more likely an underlying bug. When starting a fresh game, I noticed my xp bar was full at level 0, and in the inspector XpActual and XpAll both "NaN", instead of 0. When I looked into the code a bit, I tracked this down to PlayerSecurePrefs. The GetFloat(and friends) is trying to parse empty space "" and returning success (but in reality it doesn't seem to work). So when the game is initialized and there's no Xp saved yet, the issue occurs. I changed the code for GetFloat in PlayerSecurePrefs into:

    Code (CSharp):
    1.     public static float GetFloat(string key){
    2.         float value;
    3.         string s = GetString (key);
    4.         if (s != "" && float.TryParse (s, out value)) {
    5.             return value;
    6.         } else {
    7.             return 0f;
    8.         }
    9.     }
    10.  
    Just making sure parsing gets ignored when GetString is empty. This is potentially happening in other GetXXX, so I chaned them too...seemed to have fixed the xp bar problem.
     
  20. Tropobor

    Tropobor

    Joined:
    Mar 24, 2014
    Posts:
    73
    Hi Falcan, since I’ve discovered there is a way to decouple question text from answers in a card, I will stay with imex “universal” version. However I still have to test it and then will let you know if I need your extension. Thanks again.
     
  21. PavelLangweil

    PavelLangweil

    Joined:
    Mar 4, 2014
    Posts:
    28
    Tropobor, sure no problem !

    @KMDeclius , actually, since you're around I've got a question - I've been trying to implement a "crisis", where your value decreases constantly. That works, but what would be the easiest way to constantly show the downward icon under the affected value when the crisis is active? Like a red down arrow or something. Or would it be easiest to put something in a different place, as I'd prefer if the value preview still worked on left / right unfinished swipe.
     
  22. KMDeclius

    KMDeclius

    Joined:
    Aug 12, 2019
    Posts:
    213
    @falcan You were right, my inbox filtered your mails (23.08). Because the mail adress is public, it get's a lot of spam and i missed your mails. Sorry.

    Thanks for the Bug-report regarding the player prefs, I will post a new version of this file after I checked it further.

    Regarding your "crisis", this depends on how you implemented it. E.g. if it is a value wich is set to 1, as long as the crisis is active, you could use "valueDependantImages". This should be in the original version.
    At Post #661 I released the more advanced "valueDependentConditionalImages" - where an Image to show is depending on conditions and values. This could match your case.

    I hope this helps.
     
  23. KMDeclius

    KMDeclius

    Joined:
    Aug 12, 2019
    Posts:
    213
    This is getting a little bit strange, may I ask which Unity version do you use?

    For my testing Version 2019.2.17f1 it seems ok and returns (a solid o_O) 0.0 for an empty PlayerPref.
    Second thing is, the TryParse should catch empty strings. It's not parsable then and shall execute the alternative path.
    I think the is one of the main reasons to use TryParse ( ... talking about "important parts" :p ).
     
  24. PavelLangweil

    PavelLangweil

    Joined:
    Mar 4, 2014
    Posts:
    28
    I'm using older Unity- 2019.2.3f1. The reason was, I tried Kings with the latest Unity first and it was showing errors. So I tried the older Unity version I still had installed, it works there. It's not a big deal, maybe that function is broken in that Unity version or something. I tried to reproduce it many times, just erased all playerPrefs and got NaN always. I tracked it down by logging to console deeper and deeper until I got there, I logged empty string (as expected for the xp stuff) and the branch got through trying to parse it (it logged success), and the result was seeing NaN in Play mode.

    Regarding the crisis stuff, ok I thought so, just was making sure there isn't something already invented which I'm missing like with the pools :)
     
  25. PavelLangweil

    PavelLangweil

    Joined:
    Mar 4, 2014
    Posts:
    28
    I can provide screenshot / video or something. If interested, just ping me through private msg / email, I feel already bad by spamming this forum so much :D About the email in the spam, that's fine, it can happen! Just explaining why I thought support was no longer provided (coupled with my quick reading of your earlier remarks of not having enough time etc.). Good to know it's working still on this forum!
     
  26. KMDeclius

    KMDeclius

    Joined:
    Aug 12, 2019
    Posts:
    213
    Thanks for the informations. I will not track this issue further at the moment. It doesn't seem to occure for other users and is perhaps related to switching Unity Versions (which, by the way, can lead to the strangest errors i've seen...). If this occures again I'm warned, thank you.
     
  27. Tropobor

    Tropobor

    Joined:
    Mar 24, 2014
    Posts:
    73
    Hi KMDeclius,
    Actually it doesn't seem possible to use Text Mesh Pro with :
    • Inventory_UIItem
    • Quest_UIItem
    • Timeline_UIItem
    Can not link the TMP texts to public text fields... Am I missing something ?
     
  28. KMDeclius

    KMDeclius

    Joined:
    Aug 12, 2019
    Posts:
    213
    I nearly forgot this. Yup, this is not supported in the actual Kings Version, but can be fixed for the texts.
    I'm shure, @falcan would say to update the whole asset, and he would be right.

    I see several possibilities here. The easiest way would be:

    Open the script and change the definition for "Text" into "TMPro.TextMeshProUGUI".

    Example for the item text, original snippet:
    Code (CSharp):
    1. public class Inventory_UIItem : MonoBehaviour
    2. {
    3.     //...
    4.     [Tooltip("Please specify a text element to show the item name.")]
    5.     public Text itemText;
    6.     //...
    7. }
    changed to TMPro :
    Code (CSharp):
    1. public class Inventory_UIItem : MonoBehaviour
    2. {
    3.     //...
    4.     [Tooltip("Please specify a text element to show the item name.")]
    5.     public TMPro.TextMeshProUGUI itemText;
    6.     //...
    7. }
    You can now link the textmesh pro field:
    upload_2020-9-13_20-34-0.png

    I also wrote a gateway class which selects if the target is a UI text or TMPro text. But this would also require changing the text definition in the script. Because it doesn't make things easier, I skip attaching it (except someone wants it).

    I hope this helps.
     
  29. Tropobor

    Tropobor

    Joined:
    Mar 24, 2014
    Posts:
    73
    Could you please tell me precisely wich scripts should have modification to“Text” public declaration ?
    For now I'm staying with your Game version, just converting Text to TMP and so far I can see there are a lot of potential candidate ...

    Quest_UIList
    Quest_UIItem
    Inventory_UIItem
    Timeline_UIEventList
    Timeline_UIItem
    CountryNameDisplay
    InfoDisplay
    ValueDisplay
    LevelUpDisplay
    DelayedEvent

    … (maybe more ?)
     
  30. KMDeclius

    KMDeclius

    Joined:
    Aug 12, 2019
    Posts:
    213
    Hi Tropobor,
    most of the scripts have the Unity UI Text output. The complete list would be:

    Inventory_UIItem - PopupPrefabConfiguration - Quest_UIItem - Quest_UIList - Timeline_UIEventList - Timeline_UIItem - AchievementsScript - CardStyle - CountryNameDisplay - CountryNameGenerator - DelayedEvent - EventScript - GameLogger - GenderGenerator - HighScoreNameLinker - HighScoreNameLinker - InfoDisplay - LevelUpDisplay - Mobile_Leaderboard - scoreCounter - saveSlider - UniToggle - ShowGameLog - ValueDisplay

    And some which only use text fields for debug outputs.

    Searching for the fields which use "Text" can be done by Visual Studio.
    Right Click on "Text"-class in the editor -> "Find All References".

    I don't have a good solution switching between Unity texts and TMPro texts. Main issue here is, changing the link to the textfield will not change the Textfield itself. Adding both is also not working, because TMPro has to be imported for the Unity 2018 Version and therefore can't be anabled by default. Even then, every text field would have a duplicate... . Maybe I'm missing something.
     
  31. Tropobor

    Tropobor

    Joined:
    Mar 24, 2014
    Posts:
    73
    Ok , so if I switch "Text" as you say in all the scripts listed above it should be ok ? I can do it. Actually I have a big bad recurent red console warning when the gamescore card is spawned.

    >>>>>GameOver__Score card (sorry)
     
  32. Tropobor

    Tropobor

    Joined:
    Mar 24, 2014
    Posts:
    73
    So I’ ve made all changes in the scripts you adviced (apart EventScript.cs)
    It is working ok and clean until GameOver_(Army, Money, Religion, People) but when these are despawned, i’ve these console error :
    NullReferenceException: Object reference not set to an instance of an object
    InfoDisplay.fillDisplayElements () (at Assets/Kings/scripts/InfoDisplay.cs:78)
    InfoDisplay.addDisplay (UnityEngine.Sprite s, System.Single number) (at Assets/Kings/scripts/InfoDisplay.cs:66)
    valueManager.changeValue (valueDefinitions+values type, System.Single valueAdd) (at Assets/Kings/scripts/valueManager.cs:247)
    EventScript.executeValueChange (EventScript+resultModifier rm) (at Assets/Kings/scripts/EventScript.cs:1044)
    EventScript.computeResult (EventScript+result res) (at Assets/Kings/scripts/EventScript.cs:679)
    EventScript.onRightSwipe () (at Assets/Kings/scripts/EventScript.cs:455)
    CardStack.rightSwipe () (at Assets/Kings/scripts/CardStack.cs:953)
    UnityEngine.Events.InvokableCall.Invoke () (at <49f4e7e791cc4fffacd88f729e2b1e4c>:0)
    UnityEngine.Events.UnityEvent.Invoke () (at <49f4e7e791cc4fffacd88f729e2b1e4c>:0)
    Swipe.processSwipe () (at Assets/Kings/scripts/Swipe.cs:452)
    Swipe.onRelease () (at Assets/Kings/scripts/Swipe.cs:367)
    Swipe.Update () (at Assets/Kings/scripts/Swipe.cs:287)
     
  33. KMDeclius

    KMDeclius

    Joined:
    Aug 12, 2019
    Posts:
    213
    Thanks for the callstack. It seems you deleted one of the textfields of "InfoDisplay". Could you post a screenshot of it? Here's the original with a text-target for each slot, I'm assuming one or more are not linked or say something like "missing":
    upload_2020-9-15_20-33-48.png

    I hope this helps.
     
  34. Tropobor

    Tropobor

    Joined:
    Mar 24, 2014
    Posts:
    73
    Thanks for pointing me the direction. All texts are now displayed with Text Mesh Pro. Works great :) The very last thing I’m not really sure how to deal with is adapting GameDictionary_InputField for TMP... Any clue?
     
  35. KMDeclius

    KMDeclius

    Joined:
    Aug 12, 2019
    Posts:
    213
    I believe replacing the three "InputField"-classes from Unity with "TMPro.TMP_InputField" should to the trick (untested).

    Original:
    Code (CSharp):
    1. [RequireComponent(typeof(InputField))]
    2. public class GameDictionary_InputField : MonoBehaviour
    3. {
    4.     [Tooltip("Please provide an key for acessing the data from the dictionary.")]
    5.     public string DictionaryKey = "NewKey";
    6.     public bool allowEmptyString = false;
    7.     private InputField inputField;
    8.  
    9.     private void Start()
    10.     {
    11.         inputField = gameObject.GetComponent<InputField>();
    12.         if(CardStack.instance != null)
    13.         {
    14.             CardStack.instance.OnCardDestroy += OnCardDestroy;
    15.         }
    16.     }
    17. //... more code
    Modified:
    Code (CSharp):
    1. [RequireComponent(typeof(TMPro.TMP_InputField))]
    2. public class GameDictionary_InputField : MonoBehaviour
    3. {
    4.     [Tooltip("Please provide an key for acessing the data from the dictionary.")]
    5.     public string DictionaryKey = "NewKey";
    6.     public bool allowEmptyString = false;
    7.     private TMPro.TMP_InputField inputField;
    8.  
    9.     private void Start()
    10.     {
    11.         inputField = gameObject.GetComponent<TMPro.TMP_InputField>();
    12.         if(CardStack.instance != null)
    13.         {
    14.             CardStack.instance.OnCardDestroy += OnCardDestroy;
    15.         }
    16.     }
    17. //... more code
    The script requires to be attached to an GameObject which has the TMP_InputField attached.
     
  36. PavelLangweil

    PavelLangweil

    Joined:
    Mar 4, 2014
    Posts:
    28
    @KMDeclius Hello again, could you please explain what is the thinking behind your "RandomElementWithPropability" class? I don't understand from the code how it would correctly keep picking cards with the lowest probability.

    I mean this code:

    Code (CSharp):
    1.     public GameObject getRandomElement(){
    2.         calculateOverallPropability ();
    3.  
    4.         float rndResult = Random.Range (0f, overallPropability);
    5.  
    6.         foreach (propElement e in elements) {
    7.             rndResult -= e.propability;
    8.             if (rndResult > 0f) {
    9.                 //no our gameobject
    10.             }else{
    11.                 //this is the random gameobject
    12.                 return e.go;
    13.                 //break;
    14.             }
    15.         }
    16.  
    17.         //something went wrong. return the first
    18.         return elements[0].go;
    19.  
    20.     }
    21.  
    Seems this just counts down from a random range capped with overall probability, substracting each cards probability, until it hits 0 (which is your pick). I feel this would cause cards with low probability to be overlooked constantly if they are placed at the front of the list, making them almost impossible to pick. On the other hand, if you have lots of high probability cards and then some mid-probability afterwards, I guess in lots of cases you'd have harder time getting to the mid-probability ones as this code would "eat" to rndResult 0 faster.

    And worse, if you have the exact same low probability in the beginning and low at the end of the list, then in reality the one in the beginning has much lower probability to be picked (as its the first one to be substracted, more likely to still be > 0f). So the probabilities are not equal as positioning in the list messes with the outcome...

    Maybe I'm overlooking something though! I just had a hunch something was weird with the probabilities couple times (like one card with 10% chance never appears while another one appears quite a bit etc.), that's why I checked the code. Again, not 100% sure...it was just a hunch so far.

    My thinking would be, that for this to work reliably I'd create a list of the size like overall probability * 10.

    So cards with probability 1.0 occupy 10 elements, cards with 0.5 occupy 5 elements etc. and then simply pick one from that. Maybe could shuffle the array as well before picking a random index. In such an array you then naturally pick the individual cards based solely on their probabilities(represented by how many places they occupy in an array), and the positioning in the elements list never messes with the cards probability to be picked, it only depends on the random number generator.

    -----

    Edit: I tried my modification and *I think* it seems to have improved, unless I'm imagining things. I also allowed probability to go beyond 1.0f, as sometimes you want to "bump" a card, don't want it high priority but also don't want to lower 99 other standard cards probability to do it.
     
    Last edited: Sep 18, 2020
  37. KMDeclius

    KMDeclius

    Joined:
    Aug 12, 2019
    Posts:
    213
    @falcan : Aah, I remember this function. This function was a little bit tricky to develop. Your suggestion with the array also was in my mind, when I wrote this. But this has a drawback: How do you make a card which only has 0.001 propability? One thousand array elements per card?
    In the end, this function is the same as occupy some array elements, but the range it occupies is the propability of the card itself. And this works with float precision. I draw a visualisation of this:

    KingsPropability.jpg

    Regarding you concern, I will write a test for this function. Until later.
     
  38. KMDeclius

    KMDeclius

    Joined:
    Aug 12, 2019
    Posts:
    213
    And finished. I wrote the Unit test attached, it is executed in the Start, therefore it has to be attached somewhere in the scene. For 1.000.000 test I get following result (it then is shown in the console of Unity):

    UnitTest_RandomElementWithPropability - Result:
    Propability : Number of selections
    0 :0
    0,1 :22138
    0,2 :44779
    0,3 :66813
    0,4 :89339
    0,5 :110941
    0,6 :133057
    0,7 :155402
    0,8 :177733
    0,9 :199798

    which seems correct for me. An element with 0.2 propability has approx. half selections as the element with 0.4 propability.

    Please be aware of two things:
    1. Random means you can the element with 90% 100 times in a row and the element with 10% never, or even vice versa.
    [EDIT] Of course this is very unlikely to happen, specially the random generators in software only emulate real randomnes. [/EDIT]
    2. Only cards which can be drawn (e.g. because of conditions) that are added to the pool for the next random selection. If it is blocked otherwise, it will not appear. Also active "High Priority" cards make the random selection obsolete.

    I hope this helps.
     

    Attached Files:

    Last edited: Sep 18, 2020
  39. KMDeclius

    KMDeclius

    Joined:
    Aug 12, 2019
    Posts:
    213
    Sorry, I missed your edit. You are right on bumping cards. If someone wants to use bigger numbers, this is also possible with the old system. The limit to 1.0 as maximum is just something from the Inspector. The original can be extended for bigger numbers in the script "EventScript.cs", e.g. for a maximum of 100.0.
    Original:
    Code (CSharp):
    1.     [Tooltip("The propability applies to all cards, which met the conditions. Cards with a higher propability are more likely to be drawn.")]
    2.     [Range(0f, 1f)] public float cardPropability = 1f;
    to
    Code (CSharp):
    1.     [Tooltip("The propability applies to all cards, which met the conditions. Cards with a higher propability are more likely to be drawn.")]
    2.     [Range(0f, 100f)] public float cardPropability = 1f;
     
  40. PavelLangweil

    PavelLangweil

    Joined:
    Mar 4, 2014
    Posts:
    28
    @KMDeclius Hey, thanks for the reply! Yes you're right, it works perfectly.

    That's what happens when I try to think at night :D I was overfocusing on the substraction thinking it plays a role in selecting the card (as if it could influence the result) but in reality the result is determined solely by the rand you perform before that.

    The substraction of the numbers is only a clever way to get to the correct card "index" (like you're showing on the image).
     
  41. nikrost

    nikrost

    Joined:
    Mar 25, 2019
    Posts:
    5
    Hi, guys!
    Big thanks for your asset, it reall helped us.
    We made this demo for steam - unforgotten
    And know i want to ask, do you have some tips, how i can add steam achivmients in my build? I saw i can do it for google, but what about steam?
     
    Lady_Lai likes this.
  42. KMDeclius

    KMDeclius

    Joined:
    Aug 12, 2019
    Posts:
    213
    Hello nikrost,
    welcome to the forum. Nice to see the demo on steam, seems like an interesting approach for this genre. It looks like you put in a huge amount of work for your art.

    Steam achievements are not yet implemented in the Kings asset.
    I did a shallow reasearche of how this achievements are handled. From the look of one fast video from Dapper Dino it seems easy to achieve this. He also links the needed packages in his description.
    The only thing I dislike in his video is him returning from his loop and not rewarding if the Initialization (which he says needs connection) is not done.

    For your achievements, do you know how you would like to handle them?

    One possibility would be to write a little script where you can input the achievement key in the inspector and trigger the
    Code (CSharp):
    1. SteamUserStats.SetAchievement(...);
    2. SteamUserStats.StoreStats();
    by one of the events from a card. In my opinion, don't use the Update loop like in the video.

    Perhaps I can make an example later.
     
    nikrost likes this.
  43. KMDeclius

    KMDeclius

    Joined:
    Aug 12, 2019
    Posts:
    213
    I wrote some code for this based on the video from Dapper Dino. I did this blind folded (no package installed and no steam account):

    Create a script "SteamworksGiveAchievement.cs" with this content:
    Code (CSharp):
    1. using Steamworks;
    2. using UnityEngine;
    3. public class SteamworksGiveAchievement : MonoBehaviour
    4. {
    5.     public void GiveAchievement(string achievement_ID)
    6.     {
    7.         if (!SteamManager.Initialized) { return; } //I'm not shure, if this works if user is offline
    8.  
    9.         SteamUserStats.SetAchievement(achievement_ID);
    10.         SteamUserStats.StoreStats();
    11.     }
    12. }
    13.  
    From the despawn event of a card it could be possible to call the function like this (Achievement for Cild Born in the example cards):
    upload_2020-10-14_22-26-29.png

    I would NOT suggest to do it in the spawn event, this is called every time the card is spawned -> If the user leaves the game it would trigger again.

    I don't know if this matches your cases or if this works like intended but this is one way it seems possible to me.
    I hope this helps.
     
  44. blahzorl

    blahzorl

    Joined:
    Oct 16, 2020
    Posts:
    2
    Hi, I´m new to Unity so sorry for a newbie question,
    How can I keep a card title fixed, yet preserve the "Answersback"? I read here about the "nomovingtext" animation controller, and used the nomovingtextcard prefab, but in doing this I find myself without the background to the card answers (the "answersback" game object in the card prefabs, right?).
    I can´t find a way to add the "answersback" to the nomovingtext card prefab and animation controller :(
    I also tried to separate the image from regular card prefabs (adding it to a new game object as child in the card in hierarchy), to see if I could prevent it from moving with the title, but also to no avail. I´d like to use the regular card prefab but just keep the card title still, not animated with the card. I´m also not using cardstyles, don´t know if this could influence this...
    thanks
     
  45. KMDeclius

    KMDeclius

    Joined:
    Aug 12, 2019
    Posts:
    213
    Hi blahzorl,
    welcome to the forum.

    You are right, this seems a little bit tricky. More than I expected myself.

    First step: make a backup of your project.

    Am I assuming correctly you want to do this for all your cards?
    I'm checking how to rearrange the game objects of an default prefab in a way, so only a portion of them is affected:
    upload_2020-10-18_0-49-35.png
    The title Text have to be lower, so it will be rendered on top.

    The Animator has to stay on the root game object in the kings prefabs, which will break the single animations so they are not moved anymore, because they have new parenting:
    AnimationMissingObject.gif

    Theres a post, how to fix this manually. I adjusted each animation file in my project to have correct links. Also I added new transform positions and rotations for "Move" and removed the root objects. Then it will look like this:
    AnimationChanges.gif
    (The Prefab has to be selected to add animtion parts)

    Next step is moving the Image and the mask to the "Move" game object:
    upload_2020-10-18_1-1-30.png
    Also increase the size, so the scaling of the Mask will be correct.

    Result:
    DecoupledText.gif

    I hope I didn't miss a step for this tutorial.

    Please be aware: For this example, every card with a different (previous) hierarchy using this animator will not animate anymore.

    I hope this helps.
     
  46. KMDeclius

    KMDeclius

    Joined:
    Aug 12, 2019
    Posts:
    213
    Theres also a second method to achive this:

    Instead of manipulating the hierarchy, you could also add the title text to each animation and set it's position to a hard value. I didn't test this, but perhaps this could also work.
    Pros:
    + No change in the hierarchy of the prefab.
    Cons:
    - The Title position will be Animation controlled and is NOT decoupled.
    - Depending on the Animation Update Order (is there something like this? ) it could fail.
    Does anybody know, for an animation, if parenting is calculated before or after setting transforms by the animator?
     
  47. blahzorl

    blahzorl

    Joined:
    Oct 16, 2020
    Posts:
    2
    Yes, it worked! Thanks for the fast and excellent reply, great support!
    It´s for all the cards, as you assumed.
    I used the first method since it came with helpful graphics, and I was worried by the "cons" you listed for the second (although I don´t understand their implications).
    Hope I don´t have to bother you too much in the future, I´m doing my best to study the documentation and forum
     
  48. Destiny51

    Destiny51

    Joined:
    Jun 8, 2020
    Posts:
    1
    I have a doubt, when I finish the game, I want to go back to the selection screen and not to the introduction. Do you know how I can solve it?
     
  49. KMDeclius

    KMDeclius

    Joined:
    Aug 12, 2019
    Posts:
    213
    Hi dropp3r,
    welcome to the forum.

    Your request depends on what you want to achieve. There are some things wich are not clear to me. Let me draw the default game flow:
    DefaultGameflowKings.jpg
    When the game starts the first time, the first start panel is shown. After this the main menu card is shown, which acts as real entry point to the game. The selection panel itself is a card prefab (even if it doesn't look like this) which is loaded because of the configuration of the entry point card.

    The first card could be changed to be the selection card, but it's not clear to me if this is what you want to achieve.
    • Are you reffering to the main menu card or the first start panel if you say "indroduction"?
      A: The first start panel is only shown once and is no card. If you want to show it again, the easy way would be to delete the player prefs with the supplied script.
    • Or do you have altered the game flow by conditions so the selection card is shown later and you want to omit the cards in between?
      A: This could be done by conditions for cards , which are using persistent Kings-values.
    • By "go back", do you mean you want to go from some gameplay back to the selection OR do you want to skip the main menu card after an game over?
      A: If you want to go from some game play back to the selection, you could try to load the selection card again. I've never tried this, but it could work.
      If you want to skip the main menu card, this could be tricky because the game relies on a main entry point...
    So far my answer. Make backups of your project before you make changes in the hierarchy, e.g. when replacing the main menu card.

    I hope this helps. If you have further questions, feel free to ask.
     
  50. KMDeclius

    KMDeclius

    Joined:
    Aug 12, 2019
    Posts:
    213
    Hello folks,
    unfortunately I have to make an important announcement regarding the availability of the KINGS-Asset.

    IMPORTANT

    Because of various reasons we will set the KINGS-Asset as deprecated.
    If you bought the KINGS-Asset already, you can still use it. Also you will be able to download it and I will continue the support as long as neccessary. Nothing will change here.

    But no more new sales will be possible for an unknown time.

    We decided against making the asset completely free, so user wich already bought it don't have a disatvantage.

    In order to allow for some lead time, the asset will probably not be classified as deprecated until a week from now (around 14.12.2020).

    So, sorry folks. I hope we can resolve some issues and make the KINGS-Asset available for new downloads again in the future.

    Greetings.