• Categories
  • Recent
  • Tags
  • Popular
  • Solved
  • Unsolved
  • Users
Skins
  • Light
  • 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

Execute script when new user is registered

Scheduled Pinned Locked Moved Cloud Code
cloud code scriptregistrationauthentication
3 Posts 2 Posters 502 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

  • Login

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