Difference between revisions of "Bot Playground/Commands/name2key"

From SmartBots Developers Docs
Jump to: navigation, search
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
 
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
<onlyinclude>Converts given resident name to UUID.</onlyinclude>
+
<onlyinclude>Returns the UUID of the given resident by name.</onlyinclude>
  
 
<syntaxhighlight lang="javascript">
 
<syntaxhighlight lang="javascript">
Bot.name2key(slname);
+
Bot.name2key(slname, function(result) { ... });
 +
</syntaxhighlight>
 +
 
 +
or using promises:
 +
 
 +
<syntaxhighlight lang="javascript">
 +
Bot.name2key(slname)
 +
  .then(function(result) { ... });
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 10: Line 17:
  
 
{{API Variable Group|Input}}
 
{{API Variable Group|Input}}
{{API Variable|slname|yes}} The name of the resident. {{Full name required}}
+
{{API Variable|slname|yes}} The name of the resident.
 +
 
 +
Important: this value has to contain a full name: "FirstName LastName", or "FirstName Resident".
  
 
{{API Variable Group|Output}}
 
{{API Variable Group|Output}}
Line 21: Line 30:
  
 
<syntaxhighlight lang="javascript">
 
<syntaxhighlight lang="javascript">
var slname = "Glaznah Gassner";
+
var AVATAR = "Glaznah Gassner";
  
Bot.name2key(slname)
+
Bot.name2key(AVATAR)
.then(function(result) {
+
.then(function(result) {
  if(result.success) {
+
console.log("The uuid using promises is " + result.slkey);
    console.log("The UUID of " + slname + " is ", result.slkey);
+
exit();
  } else {
+
});
    console.log("Error executing name2key: " + result.error);
+
 
  }
+
Bot.name2key(AVATAR, function(result) {
 +
console.log("The uuid using callback is " + result.slkey);
 +
exit();
 
});
 
});
 
</syntaxhighlight>
 
</syntaxhighlight>

Latest revision as of 13:41, 12 May 2017

Returns the UUID of the given resident by name.

Bot.name2key(slname, function(result) { ... });

or using promises:

Bot.name2key(slname)
  .then(function(result) { ... });

Reference

This command accepts the following parameters:

Variable Required Description


Input:
slname yes The name of the resident.

Important: this value has to contain a full name: "FirstName LastName", or "FirstName Resident".

Output:
Function returns a Promise with the following data:
success bool true if command completed successfully
error string error string if command has failed
slkey The UUID of the avatar

Examples

var AVATAR = "Glaznah Gassner";

Bot.name2key(AVATAR)
	.then(function(result) {
		console.log("The uuid using promises is " + result.slkey);
		exit();
	});

Bot.name2key(AVATAR, function(result) {
	console.log("The uuid using callback is " + result.slkey);
	exit();
});