# MakeCode player.teleport() & world(~,~,~)

**URL:** https://forum.makecode.com/t/makecode-player-teleport-world/2793
**Category:** Minecraft
**Created:** [July 15, 2020, 5:51pm UTC](https://forum.makecode.com/t/makecode-player-teleport-world/2793 "2020-07-15T17:51:49Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![seaquinn64](https://avatars.discourse-cdn.com/v4/letter/s/3e96dc/32.png) [@seaquinn64](https://forum.makecode.com/u/seaquinn64)
#### Post date: [July 15, 2020, 5:51pm UTC](https://forum.makecode.com/t/makecode-player-teleport-world/2793/1 "2020-07-15T17:51:49Z")

</div>

Hi, kind of new, sorry if I don’t format my post properly I didn’t see too much on that.

I’m having trouble trying to figure out why this won’t work:

```
if (player.position() == world(-147, 4, -76)){
player.teleport(world(-148, 4, -80))
}

```

When I run and walk over the point, nothing happens.

Am I missing something obvious?

---

<div class="post-metadata">

### Author: ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)
#### Post date: [July 15, 2020, 5:58pm UTC](https://forum.makecode.com/t/makecode-player-teleport-world/2793/2 "2020-07-15T17:58:32Z")

</div>

What does the rest of the code look like? Is this inside a walk event or a forever loop?

---

<div class="post-metadata">

### Author: ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)
#### Post date: [July 15, 2020, 6:02pm UTC](https://forum.makecode.com/t/makecode-player-teleport-world/2793/3 "2020-07-15T18:02:10Z")

</div>

Also, not sure that `==` will work on two positions. You probably need to do something like:

```typescript
const target = world(-147, 4, -76);
const playerPosition = player.position();

if (
    playerPosition.getValue(Axis.X) === target.getValue(Axis.X) &&
    playerPosition.getValue(Axis.Y) === target.getValue(Axis.Y) &&
    playerPosition.getValue(Axis.Z) === target.getValue(Axis.Z)
    ) {
    player.teleport(world(-148, 4, -80))
}

```

---

<div class="post-metadata">

### Author: ![seaquinn64](https://avatars.discourse-cdn.com/v4/letter/s/3e96dc/32.png) [@seaquinn64](https://forum.makecode.com/u/seaquinn64)
#### Post date: [July 15, 2020, 8:15pm UTC](https://forum.makecode.com/t/makecode-player-teleport-world/2793/4 "2020-07-15T20:15:29Z")

</div>

Okay, so I tried incorporating that and it was having me teleporting if I was anywhere but the destination block (-148, 4, -80). Then I had to do stuff and came back to try again, and now it does nothing. Maybe I should try storing each coordinate to compare outside of the if statement? Or does that not make much of a difference?

EDIT: I suspect that this is a typing issue, I’m just not sure how to fix it.

Entire script:

> ```
> const target = world(-148, 4, -76);
> 
> const playerPosition = player.position();
> 
> loops.forever(function () {
> 
> if (
> 
> playerPosition.getValue(Axis.X) === target.getValue(Axis.X) &&
> 
> playerPosition.getValue(Axis.Y) === target.getValue(Axis.Y) &&
> 
> playerPosition.getValue(Axis.Z) === target.getValue(Axis.Z)
> 
> ) {
> 
> player.teleport(world(-148, 4, -80))
> 
> }
> 
> })
> 
> player.onChat("location", function () {
> 
> player.say("I am at " + player.position())
> 
> })
> 
> ```

---

<div class="post-metadata">

### Author: ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)
#### Post date: [July 15, 2020, 10:33pm UTC](https://forum.makecode.com/t/makecode-player-teleport-world/2793/5 "2020-07-15T22:33:51Z")

</div>

you need to set the `playerPosition` inside the forever function, otherwise it will just fetch it once at the start of the program.

---

<div class="post-metadata">

### Author: ![seaquinn64](https://avatars.discourse-cdn.com/v4/letter/s/3e96dc/32.png) [@seaquinn64](https://forum.makecode.com/u/seaquinn64)
#### Post date: [July 15, 2020, 10:36pm UTC](https://forum.makecode.com/t/makecode-player-teleport-world/2793/6 "2020-07-15T22:36:02Z")

</div>

Yes! You’re right! Thank you so much!

---

<div class="post-metadata">

### Author: ![magilisaau](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/magilisaau/32/1186_2.png) [@magilisaau](https://forum.makecode.com/u/magilisaau)
#### Post date: [August 9, 2020, 3:25am UTC](https://forum.makecode.com/t/makecode-player-teleport-world/2793/7 "2020-08-09T03:25:59Z")

</div>

you can use str() to check equal, for example

if( str(world(0,0,0))==str(world(0,1,0))):  
dosomthing

---

<div class="post-metadata">

### Author: ![magilisaau](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/magilisaau/32/1186_2.png) [@magilisaau](https://forum.makecode.com/u/magilisaau)
#### Post date: [August 9, 2020, 6:52am UTC](https://forum.makecode.com/t/makecode-player-teleport-world/2793/8 "2020-08-09T06:52:18Z")

</div>

javascript code

if("" + world(0, 0, 0) == “” + world(0, 0, 0)){

```
player.say(":)")

```

}
