Receive Player Input, Random Number, Repeat

Hello everyone, I am really struggling with another aspect of Inform that I need some help with and it’s been difficult for me to find exactly what I need.

Basically, I want a simple duel type scenario at one part of my game in which it essentially goes like this:

  • Player is given the option to Press 1 to Attack, 2 to Defend.
  • Meanwhile a timer is set to 3 seconds.
  • At the 3 second mark, a message will appear such as, “The man readies his sword to strike!”
  • A timer is set to 3 seconds again.
  • If the player did not input 2 to defend before this (second) 3 second mark, a variable called PlayerHP is deducted 10 points with a message, “The man strikes you for 10 points!”
  • If the player DID press 2 to defend, there is a 50/50 chance of it working, otherwise, PlayerHP is deducted 10 points with a message, “The man strikes you for 10 points!”
  • During all of this, if the player presses 1 to attack, the player has a 50/50 chance of successfully reducing EnemyHP by 10 points
  • This returns to the top repeatedly until Enemy HP is up.

I don’t know how to do much of this, but I know in other scripting languages, this would be a relatively simple program to write. All you’d have to do is ask for player input, if 1, then subtract 10 from a numerical variable and display a message etc… However, I suspect this isn’t that easy in Inform (although many other things are much easier).

Can I get some help please? I plan on to use this as my basic foundation and build on it further overtime as I learn more, but I just want to get past this one part in my story.

Thank you!

First problem: Inform 7 doesn’t keep track of real time out of the box.

Check out this extension: … doc_0.html

The solution I use for numbered choice menus is Hybrid Choices: … index.html

The variable manipulation and randomness is doable with standard Inform rules. You are correct that this would be easier with Twine or ASM which both have timers and choice-menus built into their standard functionality.

Thank you, I think I can make that work for what I want! It actually gave me a few other ideas.

To a separate, but bigger issue:

I have tried like 10 different ways to say something like:

CustomVariable = 100 or The CustomVariable is 100.

Yet Inform, no matter how I write this, will always state “thing called ‘CustomVariable’ is a value, but this makes no sense to me - it would be like saying ‘the chair is 10’.”

Are we not capable of creating our own custom variables, give them a numerical value, then add and subtract from them at will?

Eventually, I’d like to create IF statements when the player enters a room based off these variables, but I am not even sure how to initiate a script I wrote when a player enters a room.

I apologize if this seems like a lot, but I am spending several hours researching prior to posting again.

Thank you!

You need to define what the variable is before you give it a value. So you can write:

CustomVariable is a number that varies. CustomVariable is 100.


CustomVariable is a number variable. CustomVariable is 100.

or even

CustomVariable is initially 100.

where the word “initially” is enough for Inform to deduce that you’re trying to create a variable. See Writing with Inform §4.12.

Manual chapter 8, by the way.

Thank you all.

I’ve read both Chapter 4 and 8 and I did read Chapter 8.12 about Increasing and Decreasing variables, however I’ve spent the last two hours trying to decrease a variable by 5. Even when I copy and paste the example from the help document, I still get an error.

I don’t feel like it should be this difficult, as all I had to do in another language was do: “CustomVariable! - 5” and it was done.

Which gives me the error: “I can’t find a verb that I know how to deal with.”

I don’t know why it says that, I declared the variable at the beginning of the script with no errors.

My best guess is that you’re not putting the phrase in a rule. Something like this should work:

[code]Lab is a room.

var is a number that varies. var is 100.

Every turn:
decrease var by 5;
say “Current value: [var].”;[/code]

If I were to liken it to programming, then I guess I’d say it’s like how you have to put executable code within a function in languages like C or Java.

I’m not sure exactly how to map it to other programming languages, but the basic idea is that almost everything in an Inform game happens turn by turn, and most of what happens in a turn is usually processing an action that the player performed. So, except for the initial declarations like “CustomVariable is a number that varies. CustomVariable is 10”–which get taken care of when the game is compiled–almost everything Inform does, you have to tell it exactly when to do it. (In particular, it doesn’t execute in the order of the source code. Source code order isn’t at all the main thing that determines when stuff happens.)

So you could wrap your phrase in “Every turn” as Brian did, which would run the code at the end of every turn. Or you could say “Before jumping: decrease CustomVariable by 5,” which would decrease var by 5 at the beginning of processing a jumping action (when the player types JUMP). Or… in your case there might be something wrapped up in one of the rules for the Real Time Events, I don’t know how those work. But it’s got to be wrapped up in some sort of rule, otherwise it’s like a “CustomVariable! - 5” line floating in space with no indication of when to do this. (That’s what the “can’t find a verb” error usually means, that you have something that isn’t a valid initial declaration and isn’t wrapped in a rule.)