Need some help doing a basic RPG system

Hey there. A friend of mine has asked me if it would be possible to try to recreate a combat system from a certain tabletop RPG, and while I think I might be able to do it with some time, I might need a little bit of help.

Right now, what I’d like to know is, is there an easy way to handle dice? I either thought it’d involve a lot of ‘roll a random number from 1 to 6’ or having a value called ‘dice’, and specifying ‘D1’, ‘D2’, ‘D3’, ‘D4’, ‘D5’, and ‘D6’ as dice. The problem is that in both of those ways, I’m not really sure how to have Inform compare the roll of the player and the AI opponent.

Here’s my code so far, although it’s incorrect:

[code]“Jadeclaw Combat Simulator” by Robert Naytor

Include Simple Chat by Mark Tilford.

A person is either attackfirst or attacksecond. A person is usually attacksecond.

A dice is a kind of value. The dices are D1, D2, D3, D4, D5, D6, D7, and D8. A person has a dice. The dice of a person is usually D8.

The Combat Room is a room. The player is in The Combat Room.

The mook is a person. The mook is in The Combat Room.

When play begins:
run a conversation from roll-init;

Roll-init is a chat node.
Report giving link to roll-init: say “Roll initiative.” instead.
Report giving text for roll-init:
let D be a random dice;
if the D of the player is greater than the D of the mook:
say “You go first.”;
if the D of the mook is greater than the D of the player:
say “You go second.”’[/code]

When I say ‘D1’ and such in the code, it’s not meant to be an actual dice, it’s just to seperate it from a regular number.

Basically, how initiative in this game works is that two characters roll their Body die, which is a 1D6 for the player, and a 1d8 for the enemy, and their Mind die, which is 1d6 for both. Instead of adding them together, you just compare what you got on the dice. Whoever gets a higher number goes first. I just need to figure out how to code that.

All right, I’ve changed around the code a little bit, now that I’ve figured some things out, but I’m still stuck.

[code]“Jadeclaw Combat Simulator” by RiptorRaptor

A person has a number called wounds. The wounds of a person is usually 0.

A person is either attackfirst or attacksecond. A person is usually attacksecond. A person is either hostile or unhostile. A person is usually unhostile.

A BodyDice is a kind of value. The BodyDices are B1, B2, B3, B4, B5, B6, B7, B8, B9, B10, B11, and B12. A person has a BodyDice. The BodyDice of a person is usually B8.
A MindDice is a kind of value. The MindDices are M1, M2, M3, M4, M5, M6, M7, M8, M9, M10, M11, and M12. A person has a MindDice. The MindDice of a person is usually M8.

The Combat Room is a room. The player is in The Combat Room.

The mook is a person. The mook is in The Combat Room.

When play begins:
now the mook is hostile;

Roll Init is a scene. Roll Init begins when the mook is hostile for two turns.

When Roll Init begins:
now the BodyDice of the player is a random BodyDice from B1 to B8;
now the MindDice of the player is a random MindDice from M1 to M8;
say “You got a [Bodydice of the player] for your Body and a [MindDice of the player] for your Mind.”;
now the BodyDice of the mook is a random BodyDice from B1 to B8;
now the MindDice of the mook is a random MindDice from M1 to M8;
say “The enemy got a [Bodydice of the mook] for his Body and a [MindDice of the mook] for his Mind.”;[/code]

What I need to know, though, is how to make Inform ‘compare’ the dice to know if one roll is better than another. If anybody has any idea, let me know, because I think I’m stumped.

So, I’m not sure why you really need to make Body into a special kind of value rather than a number (A person has a number called body.) I’m also not quite sure how the initiative system you’re describing is intended to work; if the player always rolls a d6 for body, why do you need to preserve that number rather than rolling it every time it comes up?

For how to compare two numbers, you want to take a look at 14.2., Numbers.

Since I’m not really sure what exact mechanic you’re after here, I’m going to take a wild guess and just show you how to compare numbers:

let X be a random number from 1 to 8;
let Y be a random number from 1 to 6;

(So right now X is going to stand for the mook’s Body roll, and Y for the player’s.)

if X = Y begin;
[the two numbers are the same: the rolls are tied]
otherwise if X > Y;
[the mook's score is higher than the player's]
otherwise;
[the player's score is higher than the mook's]
end if;

OK, I tried something a little closer to what you were suggesting, although with colons and indentations instead.

When Roll Init begins: let Body be a random number fom 1 to 8; let MBody be a random number from 1 to 6; If Body > MBody: say "Your Body of [Body] beat his Body of [MBody]. Trying your Mind..."; now beat-his-body is true; If Body < MBody: say "His Body of [MBody] beat your Body of [Body]. Trying your Mind..."; now beat-your-body is true; If Body = MBody: say "Tie. Flipping coin..."; if a random number from 1 to 2 is 1: say "You win the tie."; now beat-his-body is true; if a random number from 1 to 2 is 2: say "He wins the tie."; now beat-your-body is true;

Here’s what supposed to happen. Initiative is figured by two stats, Body and Mind. Body and Mind belong to the player, MBody and MMind belong to the opponent. When the scene ‘Roll Init’ happens, the game is supposed to compare the roll of the two Body stats, with the highest roll winning. If somebody fails the Body roll, however, they can still win initiative if they get a higher Mind roll. If there’s a tie, then it’s supposed to see who has the bigger dice size in either Body or Mind. However, the two characters SHARE the same die size in both, so instead it’s supposed to flip a coin, which is what the ‘if a random number from 1 to to 2’ is for. The problem is Inform will not recognize ‘If Body = MBody’ at all, and I’m not sure why.

My bad; I always forget that this doesn’t work. Try ‘Body is MBody’ instead.

This bit won’t work as expected since a new number is generated for each “random number from 1 to 2”, which means that both if statements will fail a quarter of the time. Try this.

if a random chance of 1 in 2 succeeds begin; say "You win the tie."; now beat-his-body is true; otherwise; say "He wins the tie."; now beat-your-body is true; end if;

Hope this helps.

I decided to do something different, but that doesn’t seem to be working out.

A person has a number called Body. The Body of a person is usually 8.
A person has a number called Mind. The Mind of a person is usually 8.
A person has a number called MBody. The MBody of a person is usually 8.
A person has a number called MMind. The MMind of a person is usually 8.

A person is either hostile or unhostile. A person is usually unhostile.
The Combat Room is a room. The player is in The Combat Room.
The mook is a person. The mook is in The Combat Room.
Roll Init is a scene. Roll Init begins when the mook is hostile for two turns.

To decide whether you go first:
	let Mind be a random number from 1 to 6;
	let MBody be a random number from 1 to 8;
	let MMind be a random number from 1 to 6;
	if the Body of the player > the MBody of the mook, decide yes;
	if the Body of the player < the MBody of the mook, decide no;
	if the Mind of the player > the MMind of the mook, decide yes;
	if the Mind of the player < the MMind of the mook, decide no;
	if the Body of the player is the MBody of the mook:
		if a random chance of 1 in 2 succeeds:
			say "Flipping coin... you go first.";
			decide yes;
		else:
			say "Flipping coin... he goes first.";
			decide no;
To decide whether he goes first:
	if the Body of the player < the MBody of the mook, decide yes;
	if the Body of the player > the MBody of the mook, decide no;
	if the Mind of the player < the MMind of the mook, decide yes;
	if the Mind of the player > the MMind of the mook, decide no;
		
When Roll Init begins:
	if you go first:
		say "You got a [Body] and [Mind]. He got a [MBody] and [MMind]. You win.";
	If he goes first:
		say "He got a [MBody] and [MMind]. You got a [Body] and [Mind]. He wins.";

The problem is that when I try to have Roll Init happen, I get this message from Inform:

And this as the explanation:

What am I doing wrong? Was my old way better?

First, the mook is not hostile.

Second, you can’t just set Mind and MBody and MMind; those are properties of each person, not temporary values. Use “Mind of the player/the mook/etc”, for instance.

Third, you can’t reference a temporary named value defined in a different rule: see WI 11.15. Again, though, in this case you’ll want to refer to "The of " within the brackets in the say statement.

Fourth, it’s a bad idea to define two functions, each of which is intended to return yes when the other returns no, because that requires you to write equal and opposite code; any difference between them will introduce very difficult-to-trace bugs. And in fact, your “To decide whether he goes first:” rule does not decide properly in the case of a tie (or at least, that would be the case if the above property-of-a-person issues were corrected). Much better to change the “When Roll Init begins:” block to When Roll Init begins: if you go first: say "You got a [Body of the player] and [Mind of the player]. He got a [MBody of the mook] and [MMind of the mook]. You win."; otherwise: say "He got a [MBody of the mook] and [MMind of the mook]. You got a [Body of the player] and [Mind of the player]. He wins.";and not define “whether he wins” explicitly at all.

Alternately, to prevent bugs while still providing opposite-named functions in the interest of literate code, call the original function explicitly: To decide whether he goes first: if you go first, decide no; decide yes.

I think you really need to explain more carefully, to us and to yourself, precisely what you want the system here to do.

You’re making a lot of choices that are just confusing: what is the point of separate Body and MBody (and Mind and MMind) stats for everyone? I’m serious: what is that intended to accomplish? In fact, since you seem to want to make the same roll every time, why do you need to give characters permanent stats at all?

I’m bringing this up because writing code is, to a large extent, explaining to the program precisely what you want to do. I7 is fairly smart as programs go, but it’s not anywhere near as smart as an actual person. So if you can’t explain precisely what you want to a person, you’re unlikely to be able to explain it to I7.

Just check out the source text for Graham Nelson’s “The Reliques of Tolti-Aph”. Right here: http://inform7.com/learn/eg/rota/source_2.html

It’s simple, it works, and I’ll be damned if using it is any sort of copyright infringement.