Adding random to this

Carry out shooting something with a gun:
decrement the bullets of the second noun;
say “Nice shot! You fire right into the center of [the noun].”;

I would like it to miss once in awhile?

1 Like

Maybe something like:

Carry out shooting something with a gun:
	Decrement the bullets of the second noun;
	If a random chance of 3 in 4 succeeds:
		Say "Nice shot!  You fire right into the center of [the noun].";
		[Whatever code you need to indicate that a person place or thing just got shot]
	Otherwise:
		Say "Bad luck, that was a miss."

By the way, you can use the preformatted text option – either the button that looks like < / > in the toolbar, or writing three backticks (`) above and below your code – to preserve whitespace like tabs, which will make your code excerpts easier to read (and copy-and-paste into the IDE to troubleshoot, too).

4 Likes

Thank you, I been trying all evening to figure that out. As you can tell I’m new. One last thing if you don’t mind. reload, it to is kicking my tail?

The pistol is a gun. The bullets of the pistol is 2.

1 Like

Sure, I can take a crack at that – how are you implementing bullets/ammo? It seems from your first excerpt that guns have a number property called “bullets” that tracks how many shots they have left, but are bullets implemented as objects in their own right, or is it assumed that the player is carrying as many as they need and they just need to reload once the gun is empty?

that is my problem. i just want to have pistol with six bullets and player must collect clips to reload. anyway thats my goal. Early stage of game still working things out.

1 Like

Would this work?

Reloading is an action applying to one thing.  Understand "reload [something]" as reloading.

Check reloading:
	If the noun is not a gun, say "You can't reload that!" instead;
	If the player does not carry a clip, say "You don't have any ammo to hand." instead.
	
Carry out reloading:
	Say "You clear out the gun's chamber and slam in a fresh clip, topping it up.";
	Now a random clip carried by the player is nowhere;
	Now the bullets of the noun is six. [Or whatever the capacity is meant to be]

2 Likes

Thank you kindly

1 Like

lol how to stop it from loading when pistol is not empty.

1 Like

Just add:

If the bullets of the noun is not zero, say “You don’t need to reload yet.” instead.

that worked but for some reason when i reload clip does not move to nowhere. I do thank you for putting up with my lack of knowledge.

1 Like

Hmm, do you have an example that demonstrates the behavior? It worked when I did a quick test but it was a very hasty test :slight_smile:

i am bad at this but this is my code. I had to add a second check line for some reason to get the reload to work. sadly this is my code.

Check reloading:
	If the noun is not a gun, say "You can't reload that!" instead;
	If the player does not carry a clip, say "You don't have any ammo to hand." instead.

Check reloading:
	If the bullets of the noun is not zero, say “You don’t need to reload yet.” instead.
	
Carry out reloading:
	Say "You clear out the gun's chamber and slam in a fresh clip, topping it up.";
	Now the bullets of the noun is six. [Or whatever the capacity is meant to be]
 	Now a random clip carried by the player is nowhere;

The crash test dummy is in the Firing Range .
The first clip is in the Firing Range.

everything works but except clip stays in inventory after I reload.

Hmm, looks like you’ve got a period after the second line of the carry out rule, instead of a semi-colon, which might be prematurely terminating the rule – perhaps that’s the culprit?

will not compile with semi colon, anyway thank you so much going to call it a night and try again to mor

To format monospace code in your message:

You can also do it inline like this by surrounding individual words or a line with single backticks.

You can also do it `inline` like this...
1 Like

Thank you

got it to remove clip, had to remove carried by player. I don’t think I am smart enough for this lol

One other neat trick some may not be aware of, if you format your text as code, hovering your mouse will let you copy the entire selection, or click the other button to widen it out so you can see the whole thing.

4 Likes

now a random clip carried by player is nowhere;

inform tells me carried by player is a description

Carry out reloading:
	Say "You clear out the gun's chamber and slam in a fresh clip, topping it up.";
	Now the bullets of the noun is six;
	Now a random clip carried by the player is nowhere;