<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Execute script when new user is registered]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I'd like to create a script that is executed when a new user is registered, to assign a random player name if one is not present (something like player12243534) but am struggling with the docs to see where / how I can do this?</p>
<p dir="auto">Thanks</p>
]]></description><link>https://forums.getbraincloud.com/topic/159/execute-script-when-new-user-is-registered</link><generator>RSS for Node</generator><lastBuildDate>Mon, 18 May 2026 06:46:41 GMT</lastBuildDate><atom:link href="https://forums.getbraincloud.com/topic/159.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 21 Aug 2022 09:12:13 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Execute script when new user is registered on Thu, 01 Sep 2022 21:11:58 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forums.getbraincloud.com/uid/60">@JasonL</a> Thanks, I ended up with this cloudCode:</p>
<pre><code>isForceCreate = String(data.callingMessage.forceCreate) == "true";
isNewUser = String(data.message.newUser) == "true";

var response = {};
response.status = 200;
response.data = data.message;

if (isForceCreate &amp;&amp; isNewUser) {

    var min = 10000000,
    max = 999999999
    prefix = ["player", "user", "member"]
    
    const num = Math.floor(Math.random() * (max - min + 1)) + min;
    const pre = prefix[Math.floor(Math.random() * prefix.length)];
    
    var defaultPlayerName = pre + String(num);

    var playerStateProxy = bridge.getPlayerStateServiceProxy();
    // We are changing the player name on the server.
    playerStateProxy.updatePlayerName(defaultPlayerName);
    // And in this API Call's return data.
    response.data.playerName = pre + String(num);
}

response; //return the object
</code></pre>
<p dir="auto">This works just the way I need</p>
]]></description><link>https://forums.getbraincloud.com/post/465</link><guid isPermaLink="true">https://forums.getbraincloud.com/post/465</guid><dc:creator><![CDATA[Gavin Beard]]></dc:creator><pubDate>Thu, 01 Sep 2022 21:11:58 GMT</pubDate></item><item><title><![CDATA[Reply to Execute script when new user is registered on Wed, 31 Aug 2022 16:56:27 GMT]]></title><description><![CDATA[<p dir="auto">You can hook the script to brainCloud authentication API and check the <code>loginCount</code> from the response, the related doc can be found <a href="https://getbraincloud.com/apidocs/cloud-code-central/cloud-code-tutorials/cc-tutorial-4-pre-and-post-hooks/" rel="nofollow ugc">here</a>.</p>
]]></description><link>https://forums.getbraincloud.com/post/464</link><guid isPermaLink="true">https://forums.getbraincloud.com/post/464</guid><dc:creator><![CDATA[JasonL]]></dc:creator><pubDate>Wed, 31 Aug 2022 16:56:27 GMT</pubDate></item></channel></rss>