Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Solved
  • Unsolved
  • Users
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Darkly)
  • No Skin
Collapse
brainCloud Forums
  1. Home
  2. Cloud Code
  3. Execute script when new user is registered

Execute script when new user is registered

Scheduled Pinned Locked Moved Cloud Code
cloud code scriptregistrationauthentication
3 Posts 2 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gavin Beard
    wrote on last edited by
    #1

    Hi,

    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?

    Thanks

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JasonL
      bitHeads
      wrote on last edited by
      #2

      You can hook the script to brainCloud authentication API and check the loginCount from the response, the related doc can be found here.

      1 Reply Last reply
      1
      • G Offline
        G Offline
        Gavin Beard
        wrote on last edited by
        #3

        @JasonL Thanks, I ended up with this cloudCode:

        isForceCreate = String(data.callingMessage.forceCreate) == "true";
        isNewUser = String(data.message.newUser) == "true";
        
        var response = {};
        response.status = 200;
        response.data = data.message;
        
        if (isForceCreate && 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
        

        This works just the way I need

        1 Reply Last reply
        0

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Solved
        • Unsolved
        • Users