Parsing coordinates

[code]A coordinate location is a kind of value. 9 9 9 specifies a coordinate location. 9/9/9 specifies a coordinate location.

Walking to is an action applying to one coordinate location. Understand “walk to [coordinate location]” as walking to.[/code]
Walking to isn’t the actual verb, but will serve as a simplification. My problem is that I want to permit the player to walk to a location with one or more negative coordinates. The code as written doesn’t make such things understood. I had noticed that Inform translates the numbers I specify as maximum values (that is, using 5 5 5 makes the digits 6-9 invalid), so I tried creating alternative specifications using negative values. Unfortunately, adding a negative sign to the second or third number results in an error complaining that a negative sign can not be entered in the middle of a constant.

Does anyone have an example, insight or an idea on how I can make this work?

It’s not possible to implement negative coordinates using a kind of value. The easiest way to implement coordinates is to use a list of numbers:

A thing has a list of numbers called the coordinate location. The coordinate location of the player is {9, 9, 9}.

You’d need to write a special reg-ex based method of parsing the player’s command to use lists in game input, though, as Inform can’t parse lists in the straightforward way that it can kinds of value. This could be entered in any way you like, e.g.

WALK TO 9, 9, -9
WALK TO 9/9/-9
WALK TO 9 9 -9
WALK TO (9, 9, -9)

You’d just have to grab the numerical values as indexed text, convert them to numbers, and slot them into your list for processing.

–Erik

here’s a way i developped in order to parse numbers:
it works well, but as it strongly relies on regular expression, it shouldn’t work well with large numbers.

When play begins:
	say "go";
	let X be "999999999" parsed as a number;
	increment X;
	showme X;

Part - Matchers

A matcher is a kind of thing.
It has some indexed text called the regex.
It has some indexed text called the original string.
It has some indexed text called the current string.
It has some indexed text called the current match.

The matcher prototype  is a matcher.
[After cloning a new object from a matcher:
	fix the cloned regex property;
	fix the cloned original string property;
	fix the cloned current string property;
	fix the cloned current match property;]

To feed (S - indexed text) to (M - matcher):
	change the original string of M to S;
	reset M;

To reset (M - matcher):
	change the current string of M to the original string of M;

To decide what indexed text is the next match/bite of/in/from (M - matcher):
	let window be some indexed text;
	[R = rigth cursor ; L = left cursor]
	repeat with R running from 1 to the number of characters in the original string of M:
		[say the character number R in the current string of M, "[line break]";]
		add the character number R in the current string of M to window;
		if window matches the regular expression (regex of M):
			while not (window exactly matches the regular expression (regex of M)):
				delete the first character of window;
			change the current match of M to window;
			delete the R first characters in the current string of M;
			break;
	decide on the current match of M;

To decide whether (M - matcher) matches:
	if the current string of M matches the regular expression (regex of M):
		decide yes;
	else:
		decide no;

Section - Parsing Numbers

The number parsing matcher is a matcher.
The regex of the number parsing matcher is "\d";

To decide what number is (T - indexed text) parsed as a/-- number:
	if T exactly matches the regular expression "(<-+>?)(\d+)":
		let S be the text matching subexpression 1;
		if S is "" or S is "+":
			let SC be 1;[Sign Coefficient]
		else if S is "-":
			let SC be -1;
		else:
			say "THERE IS SOME KIND OF PROBLEM IN SECTION - PARSING NUMBER OF ADVANCED TEXT MANIPULATION FOR 6E72";
		let RV be 0;
		let M be the number parsing matcher;
		feed the text matching subexpression 2 to M;
		while M matches:
			change RV to RV multiplied by 10;
			let N be the next match of M;
			let X be the digit corresponding to a textual digit of N in the Table of Parsed Digits;
			change RV to RV plus X;
		let RV be RV * SC;
		decide on RV;
	else:
		deliver parse error with T;

Table of Parsed Digits
textual digit (indexed text)	digit
"0"	0
"1"	1
"2"	2
"3"	3
"4"	4
"5"	5
"6"	6
"7"	7
"8"	8
"9"	9



To deliver parse error with (T - indexed text):
	say "[paragraph break][bold type]";
	say "ERROR: Parsing[line break][fixed letter spacing][T][bold type] does not seem to represent a number.";
	say "[roman type][paragraph break]";


Part - Deleting text from indexed texts TODO

Chapter - At the beginning

Section - Characters

To delete/remove/suppress the (N - number) first characters in/from/of (T - indexed text):
	(- {-allocate-storage:iterator}if( {N} > IT_BlobAccess({-pointer-to:T}, CHR_BLOB)) {-open-brace} print "error when deleting characters"; {-close-brace} else {-open-brace} for ((I7_ST_iterator-->{-counter:iterator})=1 : (I7_ST_iterator-->{-counter:iterator})<={N} : (I7_ST_iterator-->{-counter:iterator})++) {-open-brace:} IT_ReplaceBlob(CHR_BLOB, {-pointer-to:T}, 1, ""); {-close-brace} {-close-brace} -).

To delete/suppress/remove the first character in/from/of (T - indexed text):
	(- IT_ReplaceBlob(CHR_BLOB, {-pointer-to:T}, 1, ""); -).
	

Chapter - Adding indexed text to indexed text

Section - Default - appending after

To append/add (T - indexed text) after/to (target - indexed text):	
	(- BlkValueCast({-pointer-to:target}, INDEXED_TEXT_TY, TEXT_TY, ((+ concatenation +)-->1)({target}, {T}));  -).




Concatenation_A is some indexed text that varies.
Concatenation_B is some indexed text that varies.
To decide what text is the concatenation of (A - indexed text) and/with (B - indexed text) (this is concatenation):
	change concatenation_a to A;
	change concatenation_b to B;
	decide on "[concatenation_a][concatenation_b]";

Also, if you add one more “9” to the indexed text i’m parsing in my When play begins phrase, it just goes banana and print some bizarre word without displaying any error.
And the matcher object is just an half-assed matcher in the style java. I created it because i wasn’t able to see a way to match an unknown number of groups with inform’s regex (but maybe, as i’m java-minded, i was just unable to see the obvious).

Another way for parsing numbers: use if/else statements for each digit.

There’s a considerably simpler number parsing routine in Vaporware’s Guncho Mocup extension:

To decide which number is numeric value of (T - indexed text): let S be 1; let L be the number of characters in T; if L is 0, decide on 0; let negated be false; if character number 1 in T is "-" begin; let negated be true; let S be 2; end if; let result be 0; repeat with N running from S to L begin; let C be character number N in T; let D be 0; if C is "1" begin; let D be 1; otherwise if C is "2"; let D be 2; otherwise if C is "3"; let D be 3; otherwise if C is "4"; let D be 4; otherwise if C is "5"; let D be 5; otherwise if C is "6"; let D be 6; otherwise if C is "7"; let D be 7; otherwise if C is "8"; let D be 8; otherwise if C is "9"; let D be 9; otherwise if C is "0"; let D be 0; otherwise; decide on 0; end if; let result be (result * 10) + D; end repeat; if negated is true, let result be 0 - result; decide on result.