Counter partially working

I’m having trouble with a counter I am using. I have set a temp of
*temp counter 6 at the top of the page and then the following code

*label roll_dice_loop3
*temp thugdiceresult
*set counter -1
*if (counter < 1)
	*goto counterdeath
*rand diceresult 1 dicesides

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)
	*line_break
	You punch the thugs and send them reeling.
	*set thughp -2
*if (diceresult < thugdiceresult)
	*line_break
	The thugs hit you savagely.
	*set stamina -2
*if (diceresult = thugdiceresult)
	*line_break
	You dodge each other
	*goto roll_dice_loop3
*line_break
You have ${stamina} stamina left
*line_break
The thugs have ${thughp} stamina left
*if (stamina < 1)
	*goto_scene youdied
*if (thughp < 1)
	*goto win

"The water is rising Jack! We can only fight another ${counter} @{(counter = 1) round|rounds}"
*else
	*goto roll_dice_loop3

The error I’m getting is: instead of the loop going for 6 times and then moving to counterdeath, it is going to counterdeath after one round?

*rand commands can be a real pain and are prone to messing up. One thing I’d suggest is to move the rand command somewhere else and definitely behind a page_break at least as it’ll be prone to rerolling if the player checks their stats page or similar. (Roll it before everything starts, and then maybe at the end before a pagebreak for the loop.) Anyway, just check that by leaving the page and coming back to it to see if you’re getting re-roll problems.

I’m not 100% sure, but I think you might be setting up a loop as there’s no page_break in there and it’s running through until it runs out of counters. (I would have thought that it would have shown up 6 times before doing that, but I’ve found rand commands sometimes make things go strange.) Is the counter stat definitely set for 6 before the fight begins?

Edit- Also not sure if you need that *else in there at the end. You want anything that’s made it past the above checks to go back through the loop.

5 Likes

Hiya!
Many thanks, what I have done is take a working fight loop and tried to add a counter into it
What normally happens is the whole page fills up as the system rolls until either the enemy or the player wins
Initially the counter did actually work but then I had a line of text that said “We can only fight another 0 rounds”
In trying to fix this I moved things about and now it is broken
This is the only situation with a counter in it, I am thinking to rewrite it as it is Far easier for me to do this than getting coding to work

I always wonder how long other people spend on coding, for example I have now spent nearly 3 hours on this and it frazzles my nerves! :crazy_face:

Messed up coding is the worst. One of the games I’m working on has a tonne of things like this in it and sometimes I think I spend as much time hunting for bugs and reorganising code as I do writing it in the first place!

Oh yeah I do remember now your code runs in a stream (rather than page_breaks between rolls) which should prevent the reroll bug from happening with rand.

Is the count definitely reset to 6 before this code routine starts running? (Sounds like it should be, but just check all the spelling etc. as I can’t see why it’d only run once)

Edit: Not sure if this is causing any problems but your *temp thugdiceresult doesn’t seem to have a value set. (I could be wrong but I thought temp values had to be initially defined even if they’re changed later?)

1 Like

It actually really helps me to hear you say this!

I try to divide my time doing choicescript between coding and writing. If my brain is focused on coding I lose all creativity in my writing and vice versa.

Very occasionaly I am able to work out how to do something, provided I have many examples to draw on, but actually what is really happening is like I am watching a magic trick that I can’t understand, then having it explained to me and I am “oh yeah thats simple” until right away the next trick leaves me bewildered again!

The only rule I have set myself is that I must only ask for technical help when I have exhausted all of my ideas. If the forum ever stops helping me it is game over my end!

2 Likes

This should produce error, but

You can’t separate a set of checks with unindented content without CS chopping the set. It’s always a good idea to keep the habit of using *elseif if your checks are used to test a single goal.

i.e.

The thugs have ${thughp} stamina left
*if (stamina < 1)
	*goto_scene youdied
*elseif (thughp < 1)
	*goto win
*else
	"The water is rising Jack! We can only fight another ${counter} @{(counter = 1) round|rounds}"
	*goto roll_dice_loop3
1 Like

Hi and thank you very much indeed for your help!
This is now working - largely! but I would appreciate ideas on the following.
IF the battle is a draw for a round then I get the following problem, which is that a draw isn’t being counted. In the followig example the character should have been washed away, but they aren’t until the next round

You rolled 2
The crab rolled 8
Your total: 10 Crab total: 14
The crab pinches you with its claws
You have 9 stamina left
The crab has 4 stamina left
“The water is rising Jack! We can only fight another 1 round”

You rolled 2
The crab rolled 4
Your total: 10 Crab total: 10
The crab scampers sideways
“The water is rising Jack! We can only fight another 0 rounds”

You rolled 5
The crab rolled 10
Your total: 13 Crab total: 16
The crab pinches you with its claws

The water rises higher and higher as you fight the giant crab and several times you find your feet are being lifted off the river bed by the strong current. It is well above your knees when a large wave washes over you and you are washed away by the current. You bob helplessly as the unstoppable force propels you onwards.

There is obviously a problem with the code I have written , which is as follows:

*label roll_dice_loop3
*temp crabdiceresult
*set counter -1
*rand diceresult 1 dicesides
You rolled ${diceresult}
*rand crabdiceresult 1 dicesides
*line_break
The crab rolled ${crabdiceresult}
*set diceresult +skill
*set crabdiceresult +crabskill
*line_break
Your total: ${diceresult} Crab total: ${crabdiceresult}
*if (diceresult > crabdiceresult)
	*line_break
	You hack at the crab with your machetes.
	*set crabhp -2
*if (diceresult < crabdiceresult)
	*line_break
	The crab pinches you with its claws
	*set stamina -2
*if (diceresult = crabdiceresult)
	*line_break
	The crab scampers sideways
	*line_break
	"The water is rising Jack! We can only fight another ${counter} @{(counter = 1) round|rounds}"
	
	*goto roll_dice_loop3
*elseif (counter < 1)
	*goto counterdeath
*line_break
You have ${stamina} stamina left
*line_break
The crab has ${crabhp} stamina left
*if (stamina < 1)
	*goto_scene youdied
*elseif (crabhp < 1)
	*goto win3
*elseif (counter < 1)
	*goto counterdeath
*else
	*line_break
	"The water is rising Jack! We can only fight another ${counter} @{(counter = 1) round|rounds}"
	
	*goto roll_dice_loop3

Maybe it would work if you did the *if, *elseif, *else combo on the first part?

1 Like
*if (diceresult = crabdiceresult)
	*line_break
	The crab scampers sideways
	*line_break
	"The water is rising Jack! We can only fight another ${counter} @{(counter = 1) round|rounds}"
	
	*goto roll_dice_loop3

It’s because your [equal dieroll check] loops back to the rolling phase instead of continuing.

1 Like

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