*if = not working as expected

I’m having trouble with the following code,

The error I’m getting is that *if (diceresult = thugdiceresult) should result in no damage and returning to the top, but actually this isn’t happening

My code looks like this:

*line_break
[b]Skill 6, Stamina 6[/b]
*label roll_dice_loop
*temp thugdiceresult
*rand diceresult 1 dicesides

You rolled ${diceresult}
*rand thugdiceresult 1 dicesides
*line_break
The thugs rolled ${thugdiceresult}
*set diceresult +skill
*set thugdiceresult +thugskill
*if (diceresult > thugdiceresult)
	*line_break
	Test of thug being hit
	*set thughp -2
*line_break
The thugs have ${thughp} stamina left
*if (diceresult < thugdiceresult)
	*set stamina -2
*line_break
You have ${stamina} stamina left
*if (diceresult = thugdiceresult)
	*goto roll_dice_loop
*if (stamina < 1)
	*goto_scene youdied
*if (thughp < 1)
	*goto win
*else
	*goto roll_dice_loop

Here is the output showing that twice both parties rolled the same but the thugs took damage:

You rolled 11
The thugs rolled 11
Test of thug being hit
The thugs have 4 stamina left
You have 17 stamina left

You rolled 4
The thugs rolled 7
The thugs have 4 stamina left
You have 15 stamina left

You rolled 5
The thugs rolled 5
Test of thug being hit
The thugs have 2 stamina left
You have 15 stamina left

You rolled 4
The thugs rolled 2
Test of thug being hit
The thugs have 0 stamina left
You have 15 stamina left

What about their skill?

3 Likes

Is there any reason you aren’t using *elseif and *else for the checks as opposed to three *ifs?

1 Like

Off the top of my head:

*temp thugdiceresult

should be either *temp thugdiceresult 0 or *temp thugdiceresult “none” for example. You have to tell ChoiceScript if you are creating a number variable or a string variable.

Also, I don’t see where you’ve *created (or *temped) the “diceresult” variable.

Also, as a seperate style thing, you can simply hit enter to go down a line. You will almost never need *line_break unless you are writing verse or some other corner case.

1 Like

This is it.

Display the two results again after modifying them based on skills, before *if (diceresult > thugdiceresult), and you’ll see what’s going on:

	You rolled ${diceresult}
	*rand thugdiceresult 1 dicesides
	*line_break
	The thugs rolled ${thugdiceresult}
	*set diceresult +skill
	*set thugdiceresult +thugskill
	*line_break
	Your total: ${diceresult}. 
	Thugs total: ${thugdiceresult}
	*if (diceresult > thugdiceresult)

A sample playthrough after I did that, including a tie:

output

You rolled 10
The thugs rolled 8
Your total: 16. Thugs total: 13
Test of thug being hit
The thugs have 4 stamina left.
You have 6 stamina left.

You rolled 6
The thugs rolled 7
Your total: 12. Thugs total: 12
The thugs have 4 stamina left.
You have 6 stamina left.

You rolled 4
The thugs rolled 3
Your total: 10. Thugs total: 8
Test of thug being hit
The thugs have 2 stamina left.
You have 6 stamina left.

You rolled 11
The thugs rolled 3
Your total: 17. Thugs total: 8
Test of thug being hit
The thugs have 0 stamina left.
You have 6 stamina left.

win

1 Like

Thank you all, a bit of a doh! moment on my part here
All fixed and I will update the code as suggested so the totals are clearer

Cheers all

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.