Teleport in script not working

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
User avatar
JtoTheB
Posts: 55
Joined: Sat Aug 09, 2025 9:46 am
Operating System Version (Optional): Windows 11
Location: New Jersey

Teleport in script not working

Post by JtoTheB »

What I'm trying to do is have a small cutscene play, and then have the player teleported into where the level begins. The only issue with this is that everything works besides the teleport script. Any fix for this?

Code: Select all

Script 1 OPEN
{
ChangeCamera (1,0,0);
SetHUDSize (640, 480, 0);
	hudmessage (s:"This is the Car Battery Store. You must find your car battery, and leave";
		HUDMSG_TYPEON|HUDMSG_LOG, 1, CR_GOLD, 320.4, 340.0, 3.0);
Delay (50);
 ChangeCamera (2,0,0);
 delay(50);
 ChangeCamera (3,0,0);
 delay(50);
	ChangeCamera(0,0,0);
	TeleportOther(10, 11, 1);
	hudmessage (s:"OBJECTIVE: FIND YOUR IDEAL CAR BATTERY";
		HUDMSG_TYPEON|HUDMSG_LOG, 1, CR_GOLD, 320.4, 340.0, 3.0);
}
User avatar
Enjay
 
 
Posts: 27321
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

Re: Teleport in script not working

Post by Enjay »

If it's the player you want to teleport, and the player is activating the script, use Teleport rather than TeleportOther.

As implied, TeleportOther is for teleporting something other than the activator of the script. In your case, your script is saying "teleport a thing with tid 10 to a teleport destination with tid 11".

There are a few teleport-related things that might also be relevant:

You should use one of the proper teleport landing things as the destination, not a map spot.

Teleport lines are usually directional (you have to cross them from the front (this allows you to walk off teleport pads surrounded by teleport lines). This even carries across to teleport instructions embedded inside a script. So, if a script is activated by the player crossing from the back, everything else bar the teleport instruction might work. In UDMF, lines can be set to activate from both sides using a line flag. However, in UDB, this property is called "Player can use from back side". Note, "use" not "activate" or "activate by crossing". However, that could just be because it's a shorter word. I haven't checked if that would fix a situation like I just described, but it might do. There are other ways around it too, if it becomes important.

Just in case you've done it this way, you cannot give the player a tid by allocating a tid to the player start spot. You usually allocate tids to the player using a script. This is typically done by using Thing_ChangeTID in an enter script or in a player activated script.
User avatar
JtoTheB
Posts: 55
Joined: Sat Aug 09, 2025 9:46 am
Operating System Version (Optional): Windows 11
Location: New Jersey

Re: Teleport in script not working

Post by JtoTheB »

I'll try the Thing_ChangeTID method, as i've already tried the teleport method.
User avatar
JtoTheB
Posts: 55
Joined: Sat Aug 09, 2025 9:46 am
Operating System Version (Optional): Windows 11
Location: New Jersey

Re: Teleport in script not working

Post by JtoTheB »

When i tried it, literally nothing changed.

Code: Select all

Script 1 OPEN
{
Thing_ChangeTID (0, 10+PlayerNumber());
ChangeCamera (1,0,0);
SetHUDSize (640, 480, 0);
	hudmessage (s:"This is the Car Battery Store. You must find your car battery, and leave";
		HUDMSG_TYPEON|HUDMSG_LOG, 1, CR_GOLD, 320.4, 340.0, 3.0);
Delay (50);
 ChangeCamera (2,0,0);
 delay(50);
 ChangeCamera (3,0,0);
 delay(50);
	ChangeCamera(0,0,0);
	Teleport(11, 9, 1);
	hudmessage (s:"OBJECTIV: FIND YOUR IDEAL CAR BATTERY";
		HUDMSG_TYPEON|HUDMSG_LOG, 1, CR_GOLD, 320.4, 340.0, 3.0);
}
User avatar
JtoTheB
Posts: 55
Joined: Sat Aug 09, 2025 9:46 am
Operating System Version (Optional): Windows 11
Location: New Jersey

Re: Teleport in script not working

Post by JtoTheB »

By the way, I changed the map spot to a Teleport Destination.
User avatar
Enjay
 
 
Posts: 27321
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

Re: Teleport in script not working

Post by Enjay »

Oh! I just noticed it's an OPEN script. Those are run by the world (i.e. the world is said to be the activator, not the player). What happens if you use the word Enter instead of OPEN? (An enter script is run on entering the map as if the player was the activator.)

I note that your line says Teleport(11, 9, 1);
The 9 is for the sector tag and is generally not needed unless you specifically want to do something with the sector tag.

Try Teleport(11, 0, 1); instead.
Also, just to check, you have set the last parameter to 1. That means no source fog. If that's not what you want, leave it as 0.

And, just in case you don't know, you can type puke [script number] to run the script from the console - useful for testing. So, in this case, it would be puke 1
Given thet "puking" a script would mean the player was the activator, it might be useful as a quick test to see if the teleport works with puking the script but not running as an OPEN script. That would confirm that it's a "who activated this script" problem.
User avatar
JtoTheB
Posts: 55
Joined: Sat Aug 09, 2025 9:46 am
Operating System Version (Optional): Windows 11
Location: New Jersey

Re: Teleport in script not working

Post by JtoTheB »

Changing it to ENTER made the script work. Thanks, Enjay!
User avatar
Enjay
 
 
Posts: 27321
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

Re: Teleport in script not working

Post by Enjay »

No worries. Glad you got it working. So it was just that the world was running the script, rather than the player. It's worth remembering that can happen because there are a few other situations where it is important for the player to be the owner of the script.

Just to remind you, if you haven't already removed it (and unless you need the player to have a tid) you can remove the Thing_ChangeTID (0, 10+PlayerNumber()); from your script.

Return to “Scripting”