intfiction.org

The Interactive Fiction Community Forum
It is currently Fri Feb 22, 2019 10:38 am

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Thu Aug 02, 2012 10:52 pm 
Offline

Joined: Thu Aug 02, 2012 10:40 pm
Posts: 11
Howdy, all. My first post.

I was inspired by my friend Aaron Reed's lovely book about Inform 7 to write a modest IF game. Now I'm having trouble that I've been unable to solve alone.

I am trying to append "And" to an arbitrary sentence, changing the first letter of the string to lower case before I do.

I tried this, which didn't work:

Code:
let new text be the description of this event;
replace character number 1 in new text with character number 1 in new text in lower case;
say "And [description of this event]  [run paragraph on]";


It didn't error, it just didn't have any effect. Result:

Quote:
And On a crackly far-off radio, a new song begins: "Rhinestone Cowboy" by Glen Campbell, a good one.


The first word is still in its original sentence case.
So then I tried this more complex version:

Code:
let new text be the description of this event;
let firstword be word number 1 in new text in lower case;
replace word number 1 in new text with "";
say "And [firstword][new text]  [run paragraph on]";


But this one revealed something funny. Each time I did something with "new text," it ran all the text substitutions in the original "description of this event" some of which created random variations. The result was:

Quote:
And onThe song "Lucy In the Sky With Diamonds", begins playing on a far-away radio.


Which suffers from two problems: It changed the text since the first word was extracted and the replacement didn't work at all.

So I'm back to the drawing board.

Any suggestions for how to lower case the first word of text?

Wes

_________________
Wes Modes
Artist, technologist, and organizer.
portfolio.thespoon.com


Top
 Profile Send private message  
Reply with quote  
PostPosted: Fri Aug 03, 2012 1:12 am 
Offline

Joined: Wed Oct 27, 2010 6:15 pm
Posts: 344
Two things.

First, you'll want the line
Code:
let new text be indexed text;
before assigning to new text. Ordinary text cannot be modified, and it leaves substitutions unevaluated, whereas indexed text is mutable, and, because it can store only characters, evaluates substitutions when assigned to from ordinary text.

Second, modifications to new text won't be reflected in the description of the event; they are separate copies. So the say line should read
Code:
say "And [new text] [run paragraph on]";

The compiler should have complained on the line
Code:
replace character number 1 in new text with character number 1 in new text in lower case;
because the story can't actually change new text. But instead, it implicitly converted new text from ordinary to indexed text, made the substitution, and then had the resulting value thrown away. That's a bug, and not one we have in the database, so if you could report it at http://inform7.com/mantis/, it would be much appreciated.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Fri Aug 03, 2012 8:20 am 
Offline

Joined: Wed Feb 29, 2012 2:00 pm
Posts: 833
Why don't you just use something like this? You can use similar concepts for upper case, title case and sentence case, like so.

Code:
"Test"

To say stuff:
say "My name is Guybrush Threepwood! Prepare to die![line break]" in title case;
say "My name is Guybrush Threepwood! Prepare to die![line break]" in lower case;
say "My name is Guybrush Threepwood! Prepare to die![line break]" in upper case;
say "My name is Guybrush Threepwood! Prepare to die![line break]" in sentence case.

The Testing Room is A Room. The description of the testing room is "[stuff]".


Hope this helps.

_________________
"Will you stop breaking the fourth wall? It's costing me an absolute fortune to replace it!"


Last edited by climbingstars on Fri Aug 03, 2012 1:20 pm, edited 1 time in total.

Top
 Profile Send private message  
Reply with quote  
PostPosted: Fri Aug 03, 2012 11:08 am 
Offline

Joined: Thu Aug 02, 2012 10:40 pm
Posts: 11
I understood from the documentation that when you asked inform to do replacements or extract a word or a character that it casts the text variable as indexed text. But I didn't know about the uncomfortable side effects. And though I read about starting its life as indexed text I had not tried it yet.

Code:
let new text be indexed text;
let new text be the description of this event;
replace character number 1 in new text with character number 1 in new text in lower case;
say "And [new text]  [run paragraph on]";


Here's the result:

Quote:
A dog barking can be plainly heard from across the river. And the song "When Will I Be Loved", begins playing on a distant radio.


Perfect. Thanks.

_________________
Wes Modes
Artist, technologist, and organizer.
portfolio.thespoon.com


Top
 Profile Send private message  
Reply with quote  
PostPosted: Fri Aug 03, 2012 11:13 am 
Offline

Joined: Thu Aug 02, 2012 10:40 pm
Posts: 11
In these two examples:

Code:
say "My name is Guybrush Threepwood! Prepare to die![line break]" in lower case;
say "My name is Guybrush Threepwood! Prepare to die![line break]" in sentence case.


The results are unsatisfactory:

Quote:
my name is guybrush threepwood! prepare to die!
My name is guybrush threepwood! Prepare to die!


It was precisely that, the capitalization of proper nouns, why I didn't cast the whole sentence in lowercase and add a conjunction.

Quote:
After a DJ break, a far-away radio's playing "You're the First, the Last, My Everything" by Barry White, one of your favorites.

_________________
Wes Modes
Artist, technologist, and organizer.
portfolio.thespoon.com


Top
 Profile Send private message  
Reply with quote  
PostPosted: Fri Aug 03, 2012 1:27 pm 
Offline

Joined: Wed Feb 29, 2012 2:00 pm
Posts: 833
In that case, you want something like this.

Code:
"Test"

To say stuff:
say "My name is " in title case;
say "Guybrush Threepwood";
say "! Prepare to die![line break]" in title case;
say "My name is " in lower case;
say "Guybrush Threepwood";
say "! Prepare to die![line break]" in lower case;
say "My name is " in upper case;
say "Guybrush Threepwood";
say "! Prepare to die![line break]" in upper case;
say "My name is " in sentence case;
say "Guybrush Threepwood";
say "! Prepare to die![line break]" in sentence case.

The Testing Room is A Room. The description of the testing room is "[stuff]".


Hope this helps.

_________________
"Will you stop breaking the fourth wall? It's costing me an absolute fortune to replace it!"


Top
 Profile Send private message  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group