Difference between revisions of "Bot Playground/Commands/getLocation"
From SmartBots Developers Docs
(8 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript"> | ||
− | + | await Bot.getLocation(); | |
− | + | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 41: | Line 40: | ||
Note: [[../status|Bot.status()]] command also returns 'location' but it may be cached for up to 30 seconds. | Note: [[../status|Bot.status()]] command also returns 'location' but it may be cached for up to 30 seconds. | ||
+ | |||
+ | 'position' is just a rounded copy of 'exactPosition'. It has been added for convenience, to avoid clogging code with ''Math.round()'' calls. | ||
+ | |||
+ | === Calling when offline === | ||
+ | |||
+ | If ''getLocation()'' is being called when bot is offline, then: | ||
+ | |||
+ | * 'online' flag is false | ||
+ | * region is an empty string | ||
+ | * all coordinates (x, y, z) are ''null'' | ||
== Examples == | == Examples == | ||
Line 48: | Line 57: | ||
if(loc.region == "DuoLife") { | if(loc.region == "DuoLife") { | ||
console.log("Wow, I'm in SmartBots region now!"); | console.log("Wow, I'm in SmartBots region now!"); | ||
+ | console.log(loc); | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Example output: | ||
+ | <syntaxhighlight lang="json"> | ||
+ | { | ||
+ | "online":true, | ||
+ | "region":"DuoLife", | ||
+ | "position":{ | ||
+ | "x":230, | ||
+ | "y":78, | ||
+ | "z":32 | ||
+ | }, | ||
+ | "exactPosition":{ | ||
+ | "x":229.6, | ||
+ | "y":77.69, | ||
+ | "z":32.1 | ||
+ | } | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Latest revision as of 09:44, 27 February 2025
Returns current location of the bot bot.
await Bot.getLocation();
Reference
This command accepts the following parameters:
Variable | Required | Description
| |
---|---|---|---|
Input: | |||
Output: | |||
Function returns a Promise with the following data: | |||
success | bool | true if command completed successfully | |
error | string | error string if command has failed | |
online | boolean | Bot online flag | |
region | string | Bot region name | |
position | object | Current bot position, rounded to integer:
{
x: number; // 100
y: number; // 110
z: number; // 20
}
| |
exactPosition | object | Exact bot position (the same as 'position' but with decimals):
{
x: number; // 100.01
y: number; // 109.65
z: number; // 20.4
}
|
Details
Command returns bot position, mostly in real-time. Use this command to track actual bot position.
Note: Bot.status() command also returns 'location' but it may be cached for up to 30 seconds.
'position' is just a rounded copy of 'exactPosition'. It has been added for convenience, to avoid clogging code with Math.round() calls.
Calling when offline
If getLocation() is being called when bot is offline, then:
- 'online' flag is false
- region is an empty string
- all coordinates (x, y, z) are null
Examples
const loc = await Bot.getLocation();
if(loc.region == "DuoLife") {
console.log("Wow, I'm in SmartBots region now!");
console.log(loc);
}
Example output:
{
"online":true,
"region":"DuoLife",
"position":{
"x":230,
"y":78,
"z":32
},
"exactPosition":{
"x":229.6,
"y":77.69,
"z":32.1
}
}