Just a neat bit of coding I thought I would share

Hello my fellow CoGgers. I am currently enjoying a holiday in Wales with my wife and kids. Because of the holiday I haven’t wrote at all, well at least until last night. I couldn’t sleep so was working on an opening to a new project. (I intend to have fully written opening chapters for 3/4 games and then let people decide which one I finish first).

Now back to the post’s title. Well during the writing of this opening chapter I came up with a code that allows the writer to show a choice is available while hiding the actual choice and showing what is required to unlock it but shows the actual choice if the conditions are met.

*title test code
*author Sam Kabell
*comment your code goes here
*create swordplay 50
*create hidden ""
*create condition ""
The enemy soldier draws his sword. 
*label swordfight
*if (swordplay >50)
  *set hidden "Disarm him"
  *set condition "."
  *goto fight
*else
  *set hidden "Hidden Choice"
  *set condition "- [Swordplay >50]"
  *goto fight

*label fight
With a snarl, he raises his sword.
*choice
  #Try and block his attack.
    *if (swordplay >50)
      You easily parry his attack knocking him off balance.
      *goto endfight
    *else
      You barely manage to block his attack, knocking you off balance.
      *set swordplay %+5
      *goto swordfight
  #Try and attack him.
    *if (swordplay >50)
      Your attack catches him off guard and your strike knocks him off balance.
      *goto endfight
    *else
      Your sword cuts nothing but air and he parries your blade, knocking you off balance.
      *set swordplay %+5
      *goto swordfight
  *selectable_if (swordplay >50) #${hidden}${condition}
    The soldier lunges for you, sword poised to pierce your chest, but you step to the side and divert the thrust knocking him of balance and disarming him.
    *goto endfight
  
*label endfight
While the enemy soldier was off balance, he can't stop your sword piercing his chest.
*ending
36 Likes

I think I shall use this code – thank you for sharing it.

3 Likes

Super clever!

2 Likes

No problem. This is what I meant before the more you use choicescript the more neat tricks you can learn how to do. :slight_smile:

1 Like

Don’t try to go too deep the rabbit hole and have multireplace in your choices.
No, I’m not regretting whatever the past me did.

2 Likes

Its doesnt use multireplace I can’t understand that so I don’t use it.

It just gets set prior to the choice hits usually just before a page_break before said choice.

4 Likes

I use multireplace + *selectable_if for the same thing quite a lot

*choice
    *selectable_if (sword_obtained = 1) #@{(sword_obtained = 1) Attack with your sword|You need a sword to do this}
5 Likes

I think that would work better with multireplace. And it’s easier than it looks. But if it works, it works! :yum:

2 Likes

Interesting design choice. It never would have occurred to me. Now I need to think about where and whether it might be appropriate in my WIPs.

I think its useful for choices that require an item or maybe a training choice. I.e [Needs Magic]