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?
What does the rest of the code look like? Is this inside a walk event or a forever loop?
Also, not sure that ==
will work on two positions. You probably need to do something like:
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))
}
1 Like
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())
})
you need to set the playerPosition
inside the forever function, otherwise it will just fetch it once at the start of the program.
1 Like
Yes! You’re right! Thank you so much!
you can use str() to check equal, for example
if( str(world(0,0,0))==str(world(0,1,0))):
dosomthing
javascript code
if("" + world(0, 0, 0) == “” + world(0, 0, 0)){
player.say(":)")
}