intfiction.org

The Interactive Fiction Community Forum
It is currently Fri Sep 22, 2017 7:05 pm

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Fri Sep 01, 2017 10:01 am 
Offline

Joined: Sat Aug 25, 2012 4:17 am
Posts: 257
Hey, I'm just wondering if there is a shortcut to printing suffixes for numbers like 1st and 2nd? What I mean is that if the number ends in 1 it would add a 'st' to make it 1st, so a number 2 changes to to 2nd and so on? If not, is there a syntax to say:

Code:
if X ends in the number 1: Say "st";


Top
 Profile Send private message  
 
PostPosted: Fri Sep 01, 2017 11:31 am 
Offline

Joined: Sun Oct 11, 2015 5:09 pm
Posts: 263
It's not built in, but you can write a function for it:

Code:
Test chamber is a room. 

To say ordinalize (N - a number):
	let the last digit be the remainder after dividing N by 10;
	if the last digit is:
		-- 1: say "[N]st";
		-- 2: say "[N]nd";
		-- 3: say "[N]rd";
		-- otherwise: say "[N]th";
		
Every turn:
	say "This is the [ordinalize the turn count] turn."



Top
 Profile Send private message  
 
PostPosted: Fri Sep 01, 2017 12:16 pm 
Offline

Joined: Sat Aug 25, 2012 4:17 am
Posts: 257
Thanks a lot. :D


Top
 Profile Send private message  
 
PostPosted: Fri Sep 01, 2017 1:05 pm 
Offline

Joined: Sun Oct 11, 2015 5:09 pm
Posts: 263
Just occurred to me, you'll want to write in exceptions for 11, 12, and 13, all of which end with "th".

Code:
To say ordinalize (N - a number):
	let last-2-digits be the remainder after dividing N by 100;
	if last-2-digits is at least 11 and last-2-digits is at most 13:
		say "[N]th";
	otherwise:
		let the last digit be the remainder after dividing N by 10;
		if the last digit is:
			-- 1: say "[N]st";
			-- 2: say "[N]nd";
			-- 3: say "[N]rd";
			-- otherwise: say "[N]th";


Top
 Profile Send private message  
 
PostPosted: Sat Sep 02, 2017 4:38 pm 
Offline

Joined: Sat Aug 25, 2012 4:17 am
Posts: 257
Ah, thanks again! That's even better! :D


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

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: Bing [Bot] and 8 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