Dice rolls in COG/HG

I’m considering adding skill checks (via the use of “dice”) to one of my WIPs.

Is there a way that this can be done? I believe the rand command had an issue related to this with avoiding numbers that it had chosen previously but it’s been so long I cannot remember the command in its entirety.

Also…

If it IS possible to make something like this, how would the code be written? In a way that is elegant and doesn’t rely on dozens of lines of code for a single command, that is. I understand the basics of CScript but making elegant code is not my forte.

I hadn’t heard that?

The main issue is the game re-rolls if you go to the stats page and back, so you need a *page_break between when the roll is made and when you actually tell the player what the dice says. If you’re rerolling dice one after the other, you might even need two dice stats to get around this problem. ie dice_a and dice_b

Otherwise it’s simple to use.

*rand dice 1 6

text here

*page_break

You roll the dice and get ${dice}.

Here is the chociescript wiki page on *rand which explains how to use it pretty well. It doesn’t mention the issue you talked about with avoid numbers.

I’m not sure how complicated the code would be? I’m pretty sure it would just be

*rand dice 1 20
*if (dice >= DC)
   SUCCESS TEXT HERE
*else
   FAIL TEXT HERE

where DC refers to the minimum number you need to roll to succeed the skill check.

If you want an example of d20 rolls in a choicescript game, Breach: the Archangel Job uses them to hilarious results.

1 Like

I may be misremembering then. So something like…

*rand dice 1 20 + Combat
*page_break

Would add the stat to the dice roll?

Gotcha. I’ve read the page on the wiki but it doesn’t explain how to add stats to the equation which is my biggest issue with it… at least for now.

I’d do the stat add on a separate line
so like

*rand dice 1 20
*set dice + Combat
*page_break

since pretty sure your way creates errors. Pretty sure choicescript is strict on “one command per line”.

2 Likes

I don’t think I could use a gosub for it could I?

Like maybe

*gosub CombatCheck

*rand dice 1 20
*temp CombatCheck
*temp CombatCheck (dice + Combat)

*if (CombatSkillCheck >= X)
*goto Blah
*else
*goto Die

I derped the code already and I see the error (the gosub one) but IDK how to fix it.

I’m not sure what you’re trying to do here? gosub needs to go to another place, so if you’re going to use gosub to roll, it needs to point to a *label and that section of text needs to end with a return. Also as I said, don’t use it right before a goto, or if the player checks the stat menu and comes back, the text they see with flick from one to the other causing them to think it is bugged.

Example

*gosub CombatSkillCheck

Text here talking about whatever.

*page_break

More text about the combat and then the result kicks in with…

*if (CombatCheck >= X)
*goto Blah
*else
*goto Die

*label CombatSkillCheck
*rand dice 1 20
*temp CombatCheck
*set CombatCheck (dice + Combat)
*return

Edit- Also you have to check the variable, not the label. So check CombatCheck, not CombatskillCheck

1 Like

I was just trying to see if I could use a gosub to reduce the overall amount of code necessary for it is all. I didn’t realize that a gosub would also cause this issue.

*rand dice 1 20
*if (dice >= (CombatCheck - Combat))
   SUCCESS
*else
   FAILURE

a little more compressed but thats prob about as short as you’ll get it

1 Like

You can use it to reduce code, I updated the comment above, but gosub doesn’t avoid the reroll thing. There needs to be a page break. It’s no big deal, just set the roll before you need it.

Edit- Also I think you’re getting errors because you’re mixing up your variables in the checks and need to set not temp some of the variables. TBH I’d make you’re life easier and just create them as variables in the start file so you don’t need to temp them unless it’s something you’re only going to use once to reduce confusion like this.

1 Like

Thank you both. You’ve been very informative. :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. If you want to reopen your WiP, contact the moderators.