Referencing to Tables in an IF Condition

Hello

I was curious – I managed to get a table ‘set up’ in my Inform 7 project that references Days and “Blurbs” – to simulate a poster listing Days and Events.

At this point, I also figured out how to ‘simulate’ a random day that you come to this place (a Bar, for this project.)

My question is – how do I reference the table in an if-then condition inside a player’s/NPC’s description or a room description? I was toying with the idea that descriptions of people and (probably rooms - I haven’t decided for sure.) would change according to the day ‘picked’ at the beginning of the game.

For example, if Thursday is a Mardi Gras event, a NPC might have a different description as to how they look, other than a regular Bar night.

If you have any questions, please ask, I’ll do my best to answer.

Try this.

A weekday is a kind of value. The weekdays are Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday.
The current weekday is initially Sunday.

Instead of waiting:
    say "You wait for a whole day.";
    if the current weekday is Saturday:
        now the current weekday is Sunday;
    otherwise:
        now the current weekday is the weekday after the current weekday.

The player carries a calendar. The description of the calendar is "Today is [current weekday], the [if the current weekday is Sunday]seventh[else if the current weekday is Monday]first[else if the current weekday is Tuesday]second[else if the current weekday is Wednesday]third[else if the current weekday is Thursday]fourth[else if the current weekday is Friday]fifth[else]sixth[end if] of November, 2014."

(This gets a bit long, but it sounds like you won’t usually have different text for every day. For a simpler case, you can just use [if the current weekday is Monday]…[else]…[end if].)

If you’ve got a table, you might say something like “select the row with weekday of the current weekday”. Then you could refer to the other entries in that row.

Ah, thanks for the examples.

But in my IF – I have it set up so nearly at the beginning:

Table of Weekdays
Day Blurb
Monday “Casual Night.”
Tuesday “Mardi Gras Bash”



Sunday “Closed?”

(Or something to that degree.)

Then I set it up near the beginning of the game to pick the ‘day’ for that game’s ‘run through’ -

choose a random row in Table of Weekdays;

Then I set it up so the “Command prompt” has the “Day entry” and Time>

My question is – how do I set it up so if it “is” Monday, then descriptions of NPCs, or rooms change based on the day itself?

like this type of code - The description of the bouncer is “He stands tall, looking bored.[if Monday …etc] He looks more relaxed, and wears a leather jacket.[otherwise if Tuesday…]…etc”

I wanted to make sure that the description of objects, be it, NPCs, or rooms, or even items, reflect the day’s ‘theme’, for lack of a better word.

I hope this is clearer?

That’s what Draconis’s example demonstrated, in the calendar description.

After you choose a random row, set the “current weekday” global variable to the day entry.

Thanks for the tip – but I’m stumped on how to do that.

I keep doing something like:

Now the current weekday is the Day from the Table of Weekdays. (And IF keeps thinking I’m talking about two different things.)

or

The current weekday is the Day from the Table of Weekdays. I’m not sure what the exact formatting of setting one ‘variable’ to the Table entry’s header.

When play begins:
        choose a random row in Table of Weekdays;
	now the command prompt is "([Day entry]) [time of day]>";
	now the left hand status line is "You: [the player's surroundings]".

The time of day is 5:00 pm.

 Table of Weekdays
 Day	Blurb
 "Monday" 	"Casual Monday"
 "Tuesday"	"Mardi Gras Night"
 "Wednesday"	"Exotic Beer Gala"
 "Thursday"	"T-shirt Contest"
 "Friday"	"Bring a Buddy" 
 "Saturday" 	"Bands Night" 
 "Sunday"	"Karaoke Evening"

A weekday is a kind of value. The weekdays are Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday.
The current weekday is initially Sunday.

Instead of waiting:
	say "You wait for a whole day.";
	if the current weekday is Saturday:
		now the current weekday is Sunday;
	otherwise:
		now the current weekday is the weekday after the current weekday;
		
The player carries a calendar. The description of the calendar is "Today is [current weekday], the [if the current weekday is Sunday]seventh[else if the current weekday is Monday]first[else if the current weekday is Tuesday]second[else if the current weekday is Wednesday]third[else if the current weekday is Thursday]fourth[else if the current weekday is Friday]fifth[else]sixth[end if] of November, 2014."

I tried to add the code for trying to make ‘current weekday’ equate to ‘Day’ in the Table of Weekdays, in various places, even after the ‘choose random row… in the Table…’

I’d appreciate it if you could point out the exact or approximate ‘formatting’ I should be using. I would be thankful for a hint. The documentation on the I7 program isn’t always clear for me, and I do prefer seeing actual examples.

-Thanks :slight_smile:

You’ve already got it elsewhere in the code – after you’ve chosen a row, you get the Day from it with “day entry.” And to do this you’ll want to fill the column with weekday values instead of text strings, which you can just do by stripping the quotes – if Inform sees that the table is full of weekdays it’ll know how to parse it. So:

[code]
A weekday is a kind of value. The weekdays are Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday.
The current weekday is initially Sunday.

Table of Weekdays
Day Blurb
Monday “Casual Monday”
Tuesday “Mardi Gras Night”
Wednesday “Exotic Beer Gala”
Thursday “T-shirt Contest”
Friday “Bring a Buddy”
Saturday “Bands Night”
Sunday “Karaoke Evening”

When play begins:
choose a random row in Table of Weekdays;
now the current weekday is the Day entry;
now the command prompt is “([current weekday]) [time of day]>”;
now the left hand status line is “You: [the player’s surroundings]”.[/code]

It’s OK to have “current weekday” in the command prompt because weekdays are a sayable value–Inform can just print the name of the current weekday. I changed “day entry” to “current weekday” because I wasn’t absolutely positive whether with the latest version of text substitutions Inform would try to print whatever the day entry of the chosen row was every turn, and get upset once no row was chosen. I’m also not sure whether what I’ve got will update automatically when the current weekday is updated; it’d be nice if it did.

(This code may not be copy-pastable; you may have to fix the tab stops by hand.)

Hm, maybe we could go with example 271/“Dubai?” It’s in 15.3 in the old Inform IDE, 16.3 in the new. This compiles and seems to work, but it may have faults I’m unaware of.

[code]“The Bar” by Andrew Schultz

Big Bob’s Bar is a room.

A weekday is a kind of value. The weekdays are Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday.

cur-day is a weekday that varies. cur-day is Sunday.

Instead of waiting:
say “You wait for a whole day.”;
if cur-day is Saturday:
now cur-day is Sunday;
otherwise:
now cur-day is the weekday after cur-day.

The player carries a calendar. The description of the calendar is “Today is [cur-day], the [placing corresponding to a weekday of cur-day in table of weekdays]. The special promotion is [promotion corresponding to a weekday of cur-day in table of weekdays].”

table of weekdays
weekday placing promotion
Monday “first” “Casual Monday”
Tuesday “second” “Mardi Gras Night”
Wednesday “third” “Exotic Beer Gala”
Thursday “fourth” “T-shirt Contest”
Friday “fifth” “Bring a Buddy”
Saturday “sixth” “Bands Night”
Sunday “seventh” “Karaoke Evening”
[/code]

@Matt W - Thank you so much. It took me a few tries, then I looked closer at my Table – and realized you meant take out the quotes. lol.

Thanks for everyone’s help :slight_smile:

Now, I can reference this ‘variable’ - current weekday to alter descriptions if needed.

Thanks a lot :slight_smile: