Open paranthesis error and random damage

I’m having trouble with indenting the following code. I knwo I am missing text at the moment that would relate to how many bullets are left etc

The error I’m getting is open parenthesis

The idea is, If the character has a gun and bullets they can shoot rather than have a fist fight
If they roll a 6, it is an instant win
A 1-5 roll causes damage and this damage is a random number between 1-6

My code looks like this:

*label gun_loop
*temp bullet_roll
*temp bullet_damage
*if (bullets > 0)
	*rand (bullet_roll) 1 6
		*if bullet_roll = 6
			*goto win
*if bullet_roll < 6
		*rand (bullet_damage) 1 6
			*set thughp - (bullet_damage)
			*if (thughp <1)
				*goto win
*else 
	*goto thug_fight

I’m not sure what error you’re getting; always post the whole error message whenever available. However, any text below *rand doesn’t need to be indented.

Many thanks, the error os in CSIDE and is:
invalid expression. expected name, found OPEN_PARENTHESIS at char 1
It refers to line 52 which in the above cut and paste is :
*rand (bullet_roll) 1 6

That explains it. Variable bullet_roll (and other randomized vars) doesn’t need to be parenthesized.

4 Likes

Thanks for the help, I still have the error so will try something else tomorrow
Too tired to think straight on this anymore so will have a beer instead!

i.e. replace:

with:

*rand bullet_roll 1 6
1 Like

I changed the code to the following much simpler version. Its complicated because IF the character uses a gun it needs to have bullets. A “roll” of 6 is an instant win.
Rather than getting too clever I will use *selectable if and then a check of bullets.

For this bit, ie did they roll a 6 or not, I rewrote as follows. I still get the same error though?

*label gun_loop
*temp guntest
*rand guntest 1 6
*if guntest = 6
	*goto win
*if guntest < 6
	*goto damage

What does the error now says?

1 Like

Try adding parenthesis to your if checks and when you have excluding conditions like this, use an *else.

*if (guntest = 6)
	*goto win
*else
	*goto damage

Even then this was just some code improvement, the way it was before shouldn’t cause an error. What is the error and the rest of the code?

1 Like

Many thanks, I will add all the code for this including the text. FYI there is no scene or label for “damage”. I intended to first make it possible to roll a 6 or not when using the gun (this is broken right now and the bit we are discusssing)
Then for a roll of less than 6 I was going to see how to write a randomly generateted amount of damage between 1 and 6
When I had done this I was going to subtract bullets used and when they reach zero use selectable_if to direct the reader to text advising the gun is empty
I am sure there are better ways to do this but as is obvious I am very poor at coding

What follows if the full scene, the error is the same

The gloomy narrow alley is a depressing contrast to the warm and bustling club. No sooner have you walked a few steps towards the main street than three figures emerge in front of you from the shadows. They advance towards you with caps pulled low. One is patting a sap into his palm. As you raise your arms to fight a deep man’s voice from behind says
*line_break
“We should even the odds a little”.
*line_break
Glancing over your shoulder you see Lady Jane Joseph and Sir Malcolm Penrose.

[i]From now on, when you are with Lady Jane and Sir Malcolm you will fight as a group. Your stats will stay the same when you fight in a group with Sir Malcolm and Lady Jane and any stamina losses carry over. If you reach zero stamina either in a group or on your own, you are dead.[/i]

You fight the [b]thugs[/b] together.
*label thug_fight
*choice
	#Fight
		*goto roll_dice_loop
	*selectable_if (gun = true) #Use gun
		*goto gun_loop
		
*line_break
[b]Skill 6, Stamina 6[/b]
*label roll_dice_loop
*temp thugdiceresult
*rand diceresult 1 dicesides
*rand thugdiceresult 1 dicesides
*set diceresult +skill
*set thugdiceresult +thugskill
Diceresult ${diceresult}
*line_break
Thugdiceresult ${thugdiceresult}
*line_break
Stamina ${stamina}
*line_break
ThugHP ${thughp}
*line_break
*if (thugdiceresult < diceresult)
	*set thughp -2
*if (thugdiceresult > diceresult)
	*set stamina -2
*if (thugdiceresult = diceresult)
	*goto roll_dice_loop
*if (stamina < 1)
	*goto_scene you_died
*if (thughp < 1)
	*goto win
*else
	*goto roll_dice_loop
*label win
[b]You win[/b]

*label gun_loop
*temp guntest
*rand guntest 1 6
*if guntest = 6
	*goto win
*else
	*goto damage


You almost had it in the original code. The issue appears to be the way you’ve structured the checks. Try this:

*temp bullet_roll 0
*temp bullet_damage 0

...

*label gun_loop
*if (bullets > 0)
        *rand bullet_roll 1 6
        *goto set_bullet_damage
*else
        *goto thug_fight

*label set_bullet_damage
*if (bullet_roll = 6)
        *goto win
*elseif (bullet_roll < 6)
        *rand bullet_damage 1 6
        *set thughp - bullet_damage
        *if (thughp < 1)
                *goto win
        *else
                *goto gun_loop
*else
        *bug *rand rolled outside 1-6, please report to forum topic

I’m not 100% sure how this fits into the code on your last post because I can’t really figure out what it’s accomplishing. But this check should work on its own.

A tip: it’s always helpful to establish your *temp variables at the very top of the .txt file instead of under the label where they’re needed. This way, they’re easier to find and they don’t get recreated on looping scenes, which could cause issues.

1 Like

It’s Saturday, glorious sunny weather and I am in a darkened room puzzling over this code again I’m afraid
Thanks to all the help I no longer get a parenthesis error but the code fails a randomtest by going in a loop
I have tried to prevent this as follows. NB I have set bullets at 10 in the startup and added a line to reduce bullets by 1 each time the gun is fired
Here is the code, it still goes in an infinite loop:

*temp bullet_roll 0
*temp bullet_damage 0
The gloomy narrow alley is a depressing contrast to the warm and bustling club. No sooner have you walked a few steps towards the main street than three figures emerge in front of you from the shadows. They advance towards you with caps pulled low. One is patting a sap into his palm. As you raise your arms to fight a deep man’s voice from behind says
*line_break
“We should even the odds a little”.
*line_break
Glancing over your shoulder you see Lady Jane Joseph and Sir Malcolm Penrose.

[i]From now on, when you are with Lady Jane and Sir Malcolm you will fight as a group. Your stats will stay the same when you fight in a group with Sir Malcolm and Lady Jane and any stamina losses carry over. If you reach zero stamina either in a group or on your own, you are dead.[/i]

You fight the [b]thugs[/b] together.
*label thug_fight
*choice
	#Fight
		*goto roll_dice_loop
	*selectable_if (gun = true) #Use gun
		*set bullets - 1
		*if (bullets > 0) 
			*goto set_bullet_damage
		*if (bullets = 0)
			*goto label click
			
*label click
You have no bullets and must fight by hand
	*goto roll_dice_loop

		
*line_break
[b]Skill 6, Stamina 6[/b]
*label roll_dice_loop
*temp thugdiceresult
*rand diceresult 1 dicesides
*rand thugdiceresult 1 dicesides
*set diceresult +skill
*set thugdiceresult +thugskill
Diceresult ${diceresult}
*line_break
Thugdiceresult ${thugdiceresult}
*line_break
Stamina ${stamina}
*line_break
ThugHP ${thughp}
*line_break
*if (thugdiceresult < diceresult)
	*set thughp -2
*if (thugdiceresult > diceresult)
	*set stamina -2
*if (thugdiceresult = diceresult)
	*goto roll_dice_loop
*if (stamina < 1)
	*goto_scene you_died
*if (thughp < 1)
	*goto win
*else
	*goto roll_dice_loop
*label win
[b]You win[/b]

*label gun_loop
*if (bullets > 0)
	*rand bullet_roll 1 6
	*goto set_bullet_damage
*else
	*goto thug_fight

*label set_bullet_damage
*if (bullet_roll = 6)
	*goto win
*elseif (bullet_roll < 6)
	*rand bullet_damage 1 6
	*set thughp - bullet_damage
	*if (thughp < 1)
		*goto win
	*else
		*goto thug_fight
*else
	*bug *rand rolled outside 1-6, please report to forum topic

Where is the loop occurring?

1 Like

*label roll_dice_loop looks very loop-prone because of how the *if statements are set up.
If the thug and main character get same dice rolls, it goes back to the same label without reducing any stamina. Then there is that *else statement. If thug’s and MC staminas are more than one, you are sent to the same loop again.

*if (thugdiceresult = diceresult)
    *goto roll_dice_loop
*if (stamina < 1)
    *goto_scene you_died
*if (thughp < 1)
    *goto win
*else
    *goto roll_dice_loop

Even if you get this code to work, it probably wouldn’t be very engaging for the reader, because it would be several dice rolls one after one, without farther reader’s input and with random result.
The code with the gun is also strange:
If you choose to use the gun and have bullets, it sends you to set_bullet_damage, the label which checks for bullet_roll. But the variable bullet_roll is set at random under *label gun_loop. But nothing goes to *label gun_loop, as far as I can see.

2 Likes

Thanks both indeed, with some jiggling around it is now working!
Going to quit while I’m ahead and have a BBQ! :stuck_out_tongue:

2 Likes

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