Teleporting code

Hello, all:

I worked on this for four hours before posting here, I tried every permutation and combination I could think of.
The action is to teleport to places on the map (my map is very large with nearly 300 rooms) to save the player some time. The code below compiles but doesn’t run the way it should:

porting is an action applying to nothing.  understand "ports" as porting.

report porting:
	say "These are the locations you can teleport to:[paragraph break][if crossroads is visited]1:  Crossroads[line break][end if][if At_the_Top_of_the_Staircase is visited]2:  Library[line break][end if][if Ninth_Street_and_King is visited]3:  American Nazi Party[line break][end if][if Seventh_Street_and_Queen is visited]4:  Mastiff[line break][end if][if Tenth_Street_and_Park_Place is visited]5:  Asylum[line break][end if][if Gas_Station is visited]6:  Gas Station[line break][end if][if No_Man's_Land is visited]7:  Battlefield[end if]"

room teleporting is an action applying to one real number.  understand "Goto [real number]" or "Go to [real number]" as room teleporting

check room teleporting:
	if real number is 1:
		if crossroads is unvisited:
			say "You haven't been to that location yet (1).";
			stop the action;
	if real number is 2:
		if At_the_Top_of_the_Staircase is unvisited:
			say "You haven't been to that location yet (2).";
			stop the action;
	if real number is 3:
		if Ninth_Street_and_King is unvisited:
			say "You haven't been to that location yet (3).";
			stop the action;
	if real number is 4:
		if Seventh_Street_and_Queen is unvisited:
			say "You haven't been to that location yet (4).";
			stop the action;
	if real number is 5:
		if Tenth_Street_and_Park_Place is unvisited:
			say "You haven't been to that location yet (5).";
			stop the action;
	if real number is 6:
		if Gas_Station is unvisited:
			say "You haven't been to that location yet (6).";
			stop the action;
	if real number is 7:
		if No_Man's_Land is unvisited:
			say "You haven't been to that location yet (7).";
			stop the action;
	otherwise:
		continue the action		

carry out room teleporting:
	if number is 1:
		now player is in crossroads;
		stop the action;
	if number is 2:
		now player is in At_the_Top_of_the_Staircase;
		stop the action;
	if number is 3:
		now player is in Ninth_Street_and_King;
		stop the action;
	if number is 4:
		now player is in Seventh_Street_and_Queen;
		stop the action;
	if number is 5:
		now player is in Tenth_Street_and_Park_Place;
		stop the action;
	if number is 6:
		now player is in Gas_Station;
		stop the action;
	if number is 7:
		now player is in No_Man's_Land;
		stop the action;

In the above code, even if I have visited (for example) numbers 1, 2, and 4 it gives me the reject response of number 6 (this is why I have the numbers in the sentences, to suss out the problem). The program does not recognize locations as being visited, even if I confirm with SHOWME that the room is visited.

If I visit all seven locations, then the game will teleport the player but only to location 1. It doesn’t consider all of the other locations.

Thank you for your help, I’ve been coding for about 12 hours today and am stumped.

Not sure why you need to use real numbers rather than just numbers here. Anyway, does anything change if you change the “ifs” after 1 to “otherwise if”? And also change “if number is 1” to “if number understood is 1”? As in:

room teleporting is an action applying to one number.  understand "Goto [number]" or "Go to [number]" as room teleporting

check room teleporting:
	if number understood is 1:
		if crossroads is unvisited:
			say "You haven't been to that location yet (1).";
			stop the action;
	otherwise if number understood is 2:
		if At_the_Top_of_the_Staircase is unvisited:
			say "You haven't been to that location yet (2).";
			stop the action;
	otherwise if number understood is 3:
		if Ninth_Street_and_King is unvisited:
			say "You haven't been to that location yet (3).";
			stop the action;
	otherwise if number understood is 4:
		if Seventh_Street_and_Queen is unvisited:
			say "You haven't been to that location yet (4).";
			stop the action;
	otherwise if number understood is 5:
		if Tenth_Street_and_Park_Place is unvisited:
			say "You haven't been to that location yet (5).";
			stop the action;
	otherwise if number understood is 6:
		if Gas_Station is unvisited:
			say "You haven't been to that location yet (6).";
			stop the action;
	otherwise if number understood is 7:
		if No_Man's_Land is unvisited:
			say "You haven't been to that location yet (7).";
			stop the action;
	otherwise:
		continue the action		

carry out room teleporting:
	if number understood is 1:
		now player is in crossroads;
		stop the action;
	otherwise if number understood is 2:
		now player is in At_the_Top_of_the_Staircase;
		stop the action;
	otherwise if number understood is 3:
		now player is in Ninth_Street_and_King;
		stop the action;
	otherwise if number understood is 4:
		now player is in Seventh_Street_and_Queen;
		stop the action;
	otherwise if number understood is 5:
		now player is in Tenth_Street_and_Park_Place;
		stop the action;
	otherwise if number understood is 6:
		now player is in Gas_Station;
		stop the action;
	otherwise if number understood is 7:
		now player is in No_Man's_Land;
		stop the action;

Not sure if this will solve your problem and I can’t check right now, just thought I’d mention it.

Real Numbers was just one of the permutations I tried. I thought it might make a difference and never revised the code when it didn’t. Thank you for your suggestion, I will try it out!

“Real numbers” are decimals. This would only be useful if you want the player to be able to teleport to room 2.75.

1 Like

Gotcha, thank you for that piece of knowledge. I will remember this.

As a note, if you want more concise code:

carry out room teleporting:
	let n be the number understood;
	if n is greater than the number of entries in the list of rooms:
		stop the action;
	let target-room be entry n of the list of rooms;
	if target-room is unvisited:
		say "You haven't been to that location yet ([n]).";
	else:
		now player is in target-room.

This assumes that all rooms are teleportable. The list of rooms is built into Inform and based on the order of the rooms in the code. If you want only certain rooms to be teleportable, add the following:

a room can be teleportable or not teleportable. a room is usually not teleportable.

and label your teleportable rooms as teleportable. Then, replace all instances of the list of rooms in the above code with the list of teleportable rooms.

3 Likes

Thank you, I am always looking for more ways to be concise!

Thanks, Hidnook ! is exactly what I need, if Lord Inform don’t hit again with version incompatibilities between now and 2027…
(yea, I have long-term planning…)

Best regards from Italy,
dott. Piergiorgio.