Punyinform compass replacement

new to punyinform.

is there an easy way to replace:

objectloop (direction in compass) 
{
     ...do something here with the direction like NPC wandering or whatever.
}

using the punyinform Directions object?

or is it just easier to go ahead and create my own compass object that will work with my inform6 code?

2 Likes

It’s not too hard, but it’s a bit different from how it works in the standard library of course, since each direction isn’t an object in PunyInform.

You probably want to read the section on Directions in the manual: Manual · johanberntsson/PunyInform Wiki · GitHub

Also, you could look at the code in Library of Horror, which is used to make a robot follow the player around. It checks which direction it has to go, so it can print something like “The robot enters from the east.”

(PunyInform/library_of_horror.inf at 3fa5cda718e9ad4f43bbbfdf67df0ba59c9e70a9 · johanberntsson/PunyInform · GitHub)

1 Like

Here’s a magic sweater which tells you about the possible exits from the current location every turn (yes, it does get tedious…)

Object -> Sweater "sweater"
	with
		name 'sweater' 'red',
	each_turn [ _i _dir_prop _dir_name _any _value;
		print "^The sweater says the possible exits are: ";
		for(_i=1 : _i <= DIRECTION_COUNT : _i++) {
			_dir_prop = direction_properties_array->_i;
			if(location provides _dir_prop) {
				_value = location._dir_prop;
				if(_value ~= 0 && ~~(_value ofclass String)) {
					_dir_name = direction_name_array-->_i;
					if(_any) print ", ";
					print (string) _dir_name;
					_any = true;
				}
			}
		}
		if(_any == 0) print "None";
		".";
	],
	has clothing;

Note: I’m in the habit of prefixing all local variable names with “_” so it’s always obvious in the code when a name is a local variable.

2 Likes

got it, thx. that’s not too much more convoluted than the i6 compass. i just wasn’t sure of the most efficient way to iterate through and test the directions.

1 Like

Since you mention efficiency, and since efficiency is a major point of PunyInform, I just updated the solution to make it slightly more efficient. (Put the value of location._dir_prop into a local variable).