Problems with "If X greater than, say "

I suppose somewhere there is a topic about this same issue, or maybe nobody have the same newbie problems as me.

I am trying to make some rules to show the changing status of the player. I tried this:

But the text doesn´t show when the variable turns 10 and upwards. I don´t know what I am doing wrong. Thanks in advance. ^^

The syntax looks fine, so the issue is probably about when the rule is actually firing. Do you have an every turn rule or an action rule that invokes this one? Apologies if that’s a basic question but I can’t think of what else the issue could be.

By the way, you can paste code directly into the forum using the preformatted text option - the one that looks like </>, which makes it easier for folks to troubleshoot.

1 Like

My first guess is that there is something going wrong with the logic to invoke your Reason rule. You have written it as a standalone rule that is not part of any rulebook. Unless you are writing a separate statement that places it inside of a rulebook, or you are manually requesting that the rule be followed somewhere else, then the rule will never be run. See WWI 19.7 The preamble of a rule for more details (online at 19.7. The preamble of a rule or WI 19. Rulebooks).

My second guess would be that there is a name conflict with the word logic that is causing the compiler to misunderstand your intent.

It will probably be helpful for you to post a more complete example of your code that demonstrates the problem in action.

1 Like

Thank you for your reply, and for the tip about posting code.

I don´t want to tie the message to a particular action. When you choose some lines of thought from a menu you get or lost Logic points, so I would like the message to appear when the variable is fulfilled. Like a one time notice. “Every turn” would be tiresome because if the player is always on 9 the message would keep up showing, isn´t?

Thank you, otistdog. Yes, I didn´t write any preamble, so maybe that is the problem. Although, the variables seem to be ok, because they are working to limit the scope of the actions. The only thing that doesn´t work is the “say”. I will study the preambles in case I can solve the issue contextualizing the code.

When do you want it to appear, then - any time the Logic variable goes above by 9? If so you could embed a say command in the rules that are changing the variable, or do an every turn rule that tracks what logic was last turn and fires when the current value goes above 9, maybe?

1 Like

Thanks. Yes, I would like it to appear anytime the Logic variable goes above 9. That sounds promising, though I don´t know how to do it.

Do you mean something like that? This “P2” is Hybrid Text extension.

A page-toggle rule for P2:
	if Logic is greater than 9:
		say "Mi fe en la razón se ve reafirmada[paragraph break]".

That might work, but I have a huge tree of choices, though If there isn´t any other way I could do it.

About the every turn rule. What´s the exact syntax I could use? Again, thank you very much! ^^

Yeah, if you already have code that changes logic scattered through a bunch of different rules and menus, I think the every turn approach is going to be easiest. I’m not in front of my computer right now so haven’t tested this, but something like this could work:

Previous_logic is a number that varies.  Previous_logic is (whatever Logic starts out at).

Every turn:
     If previous_logic is less than 10 and Logic is greater than 9, say “I feel more confident…”;
     Now previous_logic is logic.

There are probably more elegant ways to do it too!

2 Likes

Well, not only works like charm, it looks elegant to me. ^^ I feel like a monkey hitting keys at random, though bit by bit I am finishing the first part of my story.

So grateful for this! I was falling into despair. +_`

1 Like

Here are some other approaches to this problem:

logic is initially 0. [or instead of '0', whatever start value you like]
Every turn:
	if logic was not greater than 9 and logic is greater than 9:
		say "[one of]Glad I worked that out![or]Worked it out again![stopping]";

Here logic is initially 0 is a shorter way of writing logic is a number that varies. logic is 0.- the initially tells inform that logic may vary (always here instead would signify a constant, unchanging value) and Inform deduces from the 0 that logic is a number, as well as setting its starting value.

‘if logic was not greater than 9…’ means ‘if, at the start of this turn, the condition ‘logic is greater than 9’ was not true…’ (see Inform documentation §9.13. The past and perfect tenses). So the full phrase if logic was not greater than 9 and logic is greater than 9 will trigger only if logic has changed during the course of this turn from 9 or less to greater than 9.

say "[one of]Glad I worked that out![or]Worked it out again![stopping]" will cause the 1st text (before the [or]) to display the first occasion the say phrase is triggered, and the 2nd text (after the [or]) on all subsequent occasions (see Inform documentation §5.7. Text with random alternatives- which also describes options for displaying text only the first occasion the say phrase is triggered, and numerous other variations).

You could also take a look at §9.14. How many times? and §9.15. How many turns?: for example

if logic is greater than 9 for 1 turn

has exactly the same effect as

if logic was not greater than 9 and logic is greater than 9

meaning ‘if logic is greater than 9 now but wasn’t last turn’.

small print Note that the first example chosen in §9.15. How many turns? can initially lead to confusion as to how if ... for (x) turns works, because of the use of the present perfect tense of the condition ‘if the floppy hat is worn’, i.e. ‘if the floppy hat has been worn’.

‘if the floppy hat is worn for 3 turns’ is equivalent to ‘if the floppy hat is worn for exactly three turns’ or '‘if the floppy hat is worn for the third turn’ and simply implies the floppy hat is worn now (1 turn) and last turn (2 turns) and the turn before (3 turns), but not the turn before that (4 turns).

‘if the floppy hat has been worn for 3 turns’ implies ‘if the floppy hat is worn now and was also worn for all of the previous 3 turns (and possibly more before that)’ and is equivalent to the (more intuitive) ‘if the floppy hat is worn for at least 4 turns’. (4 turns here being this turn and all of the previous 3 turns).

EDIT: more small print

The documentation is incorrect when it says that the following are equivalent:

if the floppy hat is worn for the third turn ...
if the floppy hat has been worn for only 3 turns ...
if the floppy hat has been worn for exactly three turns ...

‘if the floppy hat is worn for the third turn’ is equivalent to ‘if the floppy hat is worn for three turns’ but, as might be expected from the description above of ‘if the floppy hat has been worn for three turns’, the other two equivalent phrases should read as below:

if the floppy hat is worn for the third turn ...
if the floppy hat has been worn for only 2 turns ...
if the floppy hat has been worn for exactly two turns ...
2 Likes

This is an excellent solution. In my case, I think it´s the best and easiest method to manage this complex tree of variables. Thank you very much for all your help and for taking your time to explain to me the code so clearly. I´m trying to fork the story as the player´s character evolves in different ways and thanks to this I can simplify the code enormously.

Thanks again to everyone who replied to my post. Very grateful.