# Ambiguous Equations

Hello,

So, I wanted to get the game to work out “Lockpick Skill” on all people at game start (so most values can also be changed from “Everything” to “Every person”).

[code]Maltese Falcon is a room. The description of the Maltese Falcon is “The sign outside says ‘We have blackjack and hookers!’ Which was enough to convince you to come in. It also reminds you of a book you once had.”
The Roulette Dealer is a male person in the Maltese Falcon. The description of the Roulette Dealer is “A large, intimidating black man in armour. You really wouldn’t want to mess with him. Unless you want to be beaten (or shot) to a nice red paste.”
Kane is a male person in the Maltese Falcon. The description of Kane is “A large, tough and shady-looking man with armour and a holstered gun. You think he might be part of the management.”
Kane’s Safe is a locked container in the Maltese Falcon. The description of Kane’s Safe is “A safe, built into the wall. It’s probably owned by Kane, provided he is part of the management. Probably also has lots of caps. And guns. And blackjack cards. Mmm, blackjack…”
The Roulette Dealer’s Safe is a locked container in the Maltese Falcon. The Lockpick Chance Number of The Roulette Dealer’s Safe is 50.

Everything has a number called Perception. Perception is usually 5.
Everything has a number called Agility. Agility is usually 5.

When play begins:
Let L be given by Initial Lockpick;
Now the Lockpick Skill of the player is L.

Equation - Initial Lockpick
L = 20+C
Where L is a number, and C is the AveragePA of the player.

Every turn:
Let C be given by APA;
Now the AveragePA of the player is C.

Everything has a number called AveragePA. AveragePA is usually 5.

Equation - APA
C = (P+A)/2
Where C is a number, P is the Perception of the player, and A is the Agility of the player.

Everything has a number called RAPA. The RAPA is usually 1.

Every turn:
Now the RAPA of the player is a random number from 0 to AveragePA of the player;
Say “[RAPA of the player] [Lockpick Skill of the player].”

Everything has a number called Lockpick Skill. The Lockpick Skill is usually 20.

Everything has a number called Lockpick Chance Number. The Lockpick Chance Number is usually 25.
The Lockpick Chance Number of Kane’s Safe is 25.

Equation - Successful Lockpick Equation
S = (L+C)/C+R
Where S is a number, L is the Lockpick Skill of the player, C is the Lockpick Chance number of a noun, and R is the RAPA of the player.

Understand “lockpick [something]” as lockpicking. Lockpicking is an action applying to one thing.

Check lockpicking:
If the noun is not something lockable, say “[The noun][s] is hardly something you can lockpick.” instead;
If the noun is unlocked, say “[The noun][s] is already unlocked. Idiot.” instead.

Carry out lockpicking:
Let S be given by the Successful Lockpick Equation;
If S is greater than 7, say “[The noun] unlocks.”;
If S is less than 7, say “You fail to unlock [the noun].”[/code]

So, I tried replacing “the player” with “the noun” in all instances, that doesn’t work. Is there any easy way, without 1,000 lines of code, to get it to work out the lockpick skill of every person at game start?

Thanks,
Blaze5565

What error are you getting exactly?

Equations are probably not the right tool for the job. (They rarely are in practice.) Instead you should just use “To decide what number is the lockpick skill of (P - a person): …” phrases. Then use P as the person rather than player or noun (which are both global variables and inappropriate for use in such circumstances.)

Right… So, do I put the “To decide”-s in a “When play begins” phrase, or something like that? And will that then run through all people and the player?

And the error is a runtime one, it’s saying I can’t make something nothing, something like that. Can’t use the nothing object. Though, it doesn’t appear with this code, it does only when I replace “player” with “the noun”.

A “To Decide” is a phrase. You write it at the top level - not inside anything else. See §11.17. Phrases to decide other things in Writing with Inform.

A phrase does not run by itself. A phrase will only run if it is part of a rule that is activated.

To set the Lockpick Skill of every character you could use a repeat loop:

``````When play begins:
repeat with subject running through persons:
Let L be given by Initial Lockpick;
now the Lockpick Skill of subject is L;``````

Do you want the equation (Initial Lockpick) to give a different value for different characters?

Here the equation is specialised for the player’s character (the player). It won’t give the relevant value for other characters.

Right, so if I want it to give the relevant value for each player, what do I say?
“and C is the AveragePA of the subject”? or something else?

You really should not be using equations. You are calculating values and then assigning them to properties - they are liable to get out of sync this way, and it’s so convoluted! Instead do this:

[code]To decide what number is the Lockpick Skill of (P - a person):
decide on 20 + the AveragePA of P.

To decide what number is the AveragePA of (P - a person):
decide on (the Perception of P + the Agility of P) / 2.

To decide what number is the lockpick test of (P - a person) against (T - a thing):
let RAPA be a random number from 0 to AveragePA of the player;
decide on (Lockpick Skill of P + Lockpick Chance number of T) / Lockpick Chance number of T + RAPA.

Carry out lockpicking:
Let S be given by the lockpick test of the actor against the noun;
If S is greater than 7, say “[The noun] unlocks.”;
If S is less than 7, say “You fail to unlock [the noun].”[/code]

Here is how you would use a generic equation rather than one hard coded to the player, but don’t do it! It’s not the right tool.

[code]Equation - Initial Lockpick
L = 20 + C
Where L is a number, and C is a number.

When play begins:
Let L be given by Initial Lockpick where C is the AveragePA of the player;[/code]

I’ll go with the phrase, I think, and this’ll come in really handy for the rest of the extension, so, thanks for being so helpful!

I just updated my post, to give you a full example.

Thanks!

Uh, I just tried that code and I’m getting a compile error. It could be my code conflicting, but it tells me the error is with “the lockpick test of the actor against the noun”. Do you know how to fix that? I’m assuming it’s just a small thing, like the specific wording of the phrase.

``let S be the lockpick test of the actor against the noun;``

Thanks, that works!

EDIT: Maybe not quite so much…

Well, it’s working, for the most part: no errors, that is, however…

Every time, it says the lockpick fails, and if I turn on actions listing, it is telling me it succeeded. I think, for some reason, it might be only outputting 5 as the number for “A number between 0 and the AveragePA of P”. Also, yeah, it does the same with it being as “of the player”. But, if it is outputting 5, and saying it failed while the actions listing says success, then there would be another problem in there, which I would assume would only happen with S coming out as 7.

Any idea how to fix that?

The rules for action success/failure are pretty obscure. There are cases where everything happens the way you want but the action is marked “failed” anyway. You don’t have to worry about this if you’re not explicitly checking the action result.

No, it’s just that every time now, the lockpick attempts fail. Sorry to keep bothering everyone, by the way…

Ok, I did a little bit of editing:

[code]Maltese Falcon is a room. The description of the Maltese Falcon is “The sign outside says ‘We have blackjack and hookers!’ Which was enough to convince you to come in. It also reminds you of a book you once had.”
The Roulette Dealer is a male person in the Maltese Falcon. The description of the Roulette Dealer is “A large, intimidating black man in armour. You really wouldn’t want to mess with him. Unless you want to be beaten (or shot) to a nice red paste.”
Kane is a male person in the Maltese Falcon. The description of Kane is “A large, tough and shady-looking man with armour and a holstered gun. You think he might be part of the management.”
Kane’s Safe is a locked container in the Maltese Falcon. The description of Kane’s Safe is “A safe, built into the wall. It’s probably owned by Kane, provided he is part of the management. Probably also has lots of caps. And guns. And blackjack cards. Mmm, blackjack…”
The Roulette Dealer’s Safe is a locked container in the Maltese Falcon. The Lockpick Chance Number of The Roulette Dealer’s Safe is 50.

Everything has a number called Perception. Perception is usually 6.
Everything has a number called Agility. Agility is usually 6.

Everything has a number called Lockpick Skill. The Lockpick Skill is usually 20.

Everything has a number called Lockpick Chance Number. The Lockpick Chance Number is usually 25.
The Lockpick Chance Number of Kane’s Safe is 25.

To decide what number is the Lockpick Skill of (P - a person):
decide on 20 + the AveragePA of P.

To decide what number is the AveragePA of (P - a person):
decide on (the Perception of P + the Agility of P) / 2.

To decide what number is the lockpick test of (P - a person) against (T - a thing):
let RAPA be a random number from 0 to AveragePA of the player;
decide on (Lockpick Skill of P + Lockpick Chance number of T) / Lockpick Chance number of T + RAPA.

Carry out lockpicking:
let S be the lockpick test of the actor against the noun;
If S is greater than 7, say “[The noun] unlocks.”;
Now the noun is unlocked;
If S is less than 6, say “You fail to unlock [the noun].”

Understand “lockpick [something]” as lockpicking. Lockpicking is an action applying to one thing.

Check lockpicking:
If the noun is not something lockable, say “[The noun] is hardly something you can lockpick.” instead;
If the noun is unlocked, say “[The noun] is already unlocked.” instead.[/code]

And it works… Better. But it will always unlock first turn, and when it does, it still says “You fail to unlock [the noun].”

So, how do I get it to work, and actually be random?

I messed around with this code and found a couple of issues with the carry out lockpicking rule:

``````Carry out lockpicking:
let S be the lockpick test of the actor against the noun;
If S is greater than 7, say "[The noun] unlocks.";
Now the noun is unlocked;
If S is less than 6, say "You fail to unlock [the noun]."``````
1. The “now the noun is unlocked” line isn’t protected by any conditional, so it happens every time regardless of the value of S. Hence the box being unlocked even when lockpicking should fail.

2. The failure test (S < 6) and the success test (S > 7) create a gap where nothing happens when S == 6 or 7.

``````Carry out lockpicking:
let S be the lockpick test of the actor against the noun;
If S is less than 6:
say "You fail to unlock [the noun].";
else:
Now the noun is unlocked;
say "[The noun] unlocks."``````

Edit: Or this:

``````Carry out lockpicking:
let S be the lockpick test of the actor against the noun;
if S is less than 6:
say "You fail to unlock [the noun].";
stop the action;
Now the noun is unlocked;
say "[The noun] unlocks."``````

Ok, thanks! That seems to have it fixed!