A small showcase how to work with variables / conditions and loop a story

Discussion in 'Authors' Hangout' started by dingsdongs, Sep 19, 2016.

  1. dingsdongs

    dingsdongs Really Really Experienced

    I created a small showcase to explain how to work with the current variable / condition system at choya: https://chyoa.com/story/Character-Creation-Showcase.9920

    I just saw that there is a similar example already available as well: http://forum.chyoa.com/threads/story-loop-example.605/

    And of course there are the guides from gene.sis "Conditional Branches - If-Statements" and "Immersion Variables" at https://chyoa.com/story/CHYOA-GUIDE.6006

    For excellent examples of how this can work in a real story, you can check out the work from Javalar https://chyoa.com/user/Javalar with the stories "The invitation" and "Happy Maid".

    I hope this helps to get more of these kind of stories started :)

    If you have any questions, post away!
     
    porneia and Javalar like this.
  2. dingsdongs

    dingsdongs Really Really Experienced

    The "source of the chapters" as copyable text:

    • Note: It is written in markdown format, to make the formatting copy-able. To use it, you would need to disable the Rich Text Editor in your account settings.

    Introduction:

    Code:
    ____Showcase____
    
    Note: The "source of the chapters" as copyable text can be viewed [on the forum](http://forum.chyoa.com/threads/a-small-showcase-how-to-work-with-variables-conditions-and-loop-a-story.658/)
    
    **For this to work, it is mandatory to start the Game Mode on the right tab under "Score".**
    
    In the Intro Chapter, the player is awarded 5 character creation points, which he can spent freely at the character creation screen.
    * This is achieved by ticking "Changes to the score" at the bottom of the chapter edit screen,
    * and choosing "Add a new score change: 00", then entering Variable: "Character Creation Points" and Value: "= 5"
    
    Furthermore i will add the starting values by adding these as variable each as well.
    Your starting values are:
    **Strength**: 1
    **Intelligence**: 1
    **Charisma**: 1
    
    ![](http://i63.tinypic.com/158badi.jpg)
    
    
    Note: If you have any questions regarding this, feel free to ask on the [on the forum](http://forum.chyoa.com/threads/a-small-showcase-how-to-work-with-variables-conditions-and-loop-a-story.658/).
    Note: And as always, if you found something helpful, the author won't mind if you hit the like button ;-)
    
    
    Chapter2: Begin Character Creation:
    Code:
    ____Character Creation Screen____
    
    You can spent 5 character creation points freely in the attributes Strength, Intelligence and Charisma.
    
    You have {if Character Creation Points = 5}5{elseif Character Creation Points = 4}4{elseif Character Creation Points = 3}3{elseif Character Creation Points = 2}2{elseif Character Creation Points = 1}1{elseif Character Creation Points = 0}0{else}**For this to work, it is mandatory to start the Game Mode on the right tab under "Score".**{endif} points remaining to spent as you wish.
    
    ____Your current values are:____
    Strength: {if Strength = 6}6{elseif Strength = 5}5{elseif Strength = 4}4{elseif Strength = 3}3{elseif Strength = 2}2{elseif Strength = 1}1{else}**For this to work, it is mandatory to start the Game Mode on the right tab under "Score".**{endif}
    Intelligence: {if Intelligence = 6}6{elseif Intelligence = 5}5{elseif Intelligence = 4}4{elseif Intelligence = 3}3{elseif Intelligence = 2}2{elseif Intelligence = 1}1{else}**For this to work, it is mandatory to start the Game Mode on the right tab under "Score".**{endif}
    Charisma: {if Charisma = 6}6{elseif Charisma = 5}5{elseif Charisma = 4}4{elseif Charisma = 3}3{elseif Charisma = 2}2{elseif Charisma = 1}1{else}**For this to work, it is mandatory to start the Game Mode on the right tab under "Score".**}{endif}
    
    {if Character Creation Points = 0}**You can now start the story!**{endif}
    
    - - - - -
    Explanation
    
    * Note: For more instructions check the chapter "Add +1 Strength"
    * Note: I am not setting any variables or conditions in this chapter "Begin Character Creation" itself. All the work is done before or after.
    * Note: You can use if-clauses to display some text according to the value of a variable. Sadly you cannot simply display the value itself at this time. A small workaround like seen in the source below is always needed.
    * Note: More info on the if clauses, check this guide from gene.sis https://chyoa.com/chapter/Conditional-Branches---If-Statements.256046
    
    * Note: The "source of the chapters" as copyable text can be viewed [on the forum](http://forum.chyoa.com/threads/a-small-showcase-how-to-work-with-variables-conditions-and-loop-a-story.658/)
    * Note: It is written in markdown format. To use it, you would need to disable the Rich Text Editor in your account settings.
    * The "source code" for this chapter as image:
    
    ![](http://i66.tinypic.com/nf17h1.jpg)
    

    Chapter 3: Finish Character creation and begin story
    Code:
    Once upon a time ...
    
    ... there was a hero named {first_name} {last_name} with the following stats:
    {if Strength >= 4}He was very strong. {endif}{if Intelligence >= 4}He was very intelligent. {endif}{if Charisma >= 4}He was very charismatic.{endif}
    
    - - - - -
    
    ____Your current values are:____
    Strength: {if Strength = 6}6{elseif Strength = 5}5{elseif Strength = 4}4{elseif Strength = 3}3{elseif Strength = 2}2{elseif Strength = 1}1{else}**For this to work, it is mandatory to start the Game Mode on the right tab under "Score".**{endif}
    Intelligence: {if Intelligence = 6}6{elseif Intelligence = 5}5{elseif Intelligence = 4}4{elseif Intelligence = 3}3{elseif Intelligence = 2}2{elseif Intelligence = 1}1{else}**For this to work, it is mandatory to start the Game Mode on the right tab under "Score".**{endif}
    Charisma: {if Charisma = 6}6{elseif Charisma = 5}5{elseif Charisma = 4}4{elseif Charisma = 3}3{elseif Charisma = 2}2{elseif Charisma = 1}1{else}**For this to work, it is mandatory to start the Game Mode on the right tab under "Score".**{endif}
    
    
    * Note: Check for the remaining Character Creation Points to make sure the reader only enters this chapter after he has spent all his points:
    
    ![](http://i63.tinypic.com/flahbn.jpg)
    
    * Note: The "source of the chapters" as copyable text can be viewed [on the forum](http://forum.chyoa.com/threads/a-small-showcase-how-to-work-with-variables-conditions-and-loop-a-story.658/)
    * Note: It is written in markdown format. To use it, you would need to disable the Rich Text Editor in your account settings.
    * The "source code" for this chapter as image:
    
    ![](http://i68.tinypic.com/1zf328k.jpg)
    
     
    Last edited: Sep 21, 2016
  3. porneia

    porneia Really Experienced

    Thank you for all the assistance. Simply, amazing work.
     
  4. Faustus

    Faustus Virgin

    Is there anyway to delete variables once they're used? Say my character finds a key, then under score it says KEY with a check mark by it. Then after the chapter when the key is used I can get it so the character doesn't have it anymore and it says KEY X, but is that going to be under the score for the rest of the story?

    I guess I'm trying to have temporary variables but now my story is going to have the ones used still listed. Not a big deal but could get pretty cluttered as the story progresses.
     
  5. gene.sis

    gene.sis CHYOA Guru

    currently, it will.
     
    porneia likes this.
  6. Faustus

    Faustus Virgin

    Good to know going forward. Thanks for the reply.
     
  7. dingsdongs

    dingsdongs Really Really Experienced

    porneia likes this.
  8. gene.sis

    gene.sis CHYOA Guru

    Currently, there are two different approaches for this feature.
    One of them would force the visibility from beginning to end.
    The other would allow changing visibility each chapter.
     
    porneia likes this.
  9. Faustus

    Faustus Virgin

    Hidden variables seem to be up and working now. Not sure who to thank, but they are an awesome person indeed.
     
    Javalar and porneia like this.
  10. porneia

    porneia Really Experienced

    Huzzah!
     
    Javalar likes this.
  11. Toadsith

    Toadsith Virgin

    Thanks for the super helpful guide!

    Quick question:
    Is there a way to conditionally change one variable based on another variable? Essentially: Can I use If/Then statements to change variable values?

    For example, I'm currently working on a story that I'd like to build a pregnancy system into. So first I'm tracking the number of times the Player cums inside other characters, when the NPC's cream pie value reaches 5 by the start of a new week, I want to set a value indicating that the NPC is pregnant. Then each following week I want to increase their pregnancy rating by 1 until they reach 36, at which point a birth scene is triggered.

    Currently the only way I see doing this is by setting up multiple condition dependent chapters for each start of the week. It would be nice to be able to put all the code in one chapter.

    Thanks!
     
  12. gene.sis

    gene.sis CHYOA Guru

    This is currently not possible.
    I am working on a feature to do that, though it isn't sure if we can release it.

    no, If-Statements can only be used to manipulate the chapter text.

    I think, that this is currently the only way to do that, though it can be cumbersome.
    Imagine, that two NPCs get pregnant the same week. Then you would have to ensure, that the reader chooses both answers. You probably also need more variables for that (pregnancy rating (1-36) and pregnancy (yes/no)) because you probably want to add 1 to each pregnancy rating each week. (So if pregnancy happens, you have to set the rating to 0 and pregnancy to true)
     
    Toadsith likes this.
  13. Toadsith

    Toadsith Virgin

    I hope you succeed!

    I was thinking the same thing — fortunately with the current story layout I only have two characters I'm planning on allowing to be pregnant, but it is entirely possible both could become pregnant simultaneously. I'm not planning on informing the readers of how or when the characters can become pregnant so that the story text simply dynamically changes as they go along. I'll have to do some messing about on paper to figure out how the mechanics of it will work. Hopefully I'll be able to hide the necessary chapters with descriptive text so the chapters can do their work and the reader will be none the wiser. In the effort of making my first story more manageable I'm making the overall story linear while allowing the readers to change behaviors in the immediate (as in what sex acts happen during a scene, not if the scene happens at all) so that all tangents lead back to the main storyline eventually. I didn't realize tracking the variables was going to lead to these sort of complications when I began though, lol

    Thanks for the help!!
     
    Javalar likes this.
  14. Zekar

    Zekar Really Experienced

    Currently my time is very limited to write. How much longer does this typically add to writing do you(or anyone) find?
     
  15. gene.sis

    gene.sis CHYOA Guru

    It depends on, how much you want to use it, how complex it should be and so on.
    It will probably cost you some time to familiarize with the features to use them.
    Good logical understanding/ basic programming experience should reduce the needed time.
    Testing the right behavior can need some time. (some kind of a debug mode to test the chapter text with certain variable values would be useful but isn't available at the moment)

    In some (maybe rare) cases it could save you some time because you could "use" one chapter for more answers.

    I think that it is more important to ask yourself if the features would add additional value to your story.


    btw the planned syntax for this is described here.