-
-
Save PrimaryFeather/d4507fb95c0c8c5eff8d7e2d498b99ca to your computer and use it in GitHub Desktop.
Quick test of the 'createdAt' and 'updatedAt' properties in Flox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package flox | |
{ | |
import com.gamua.flox.Flox; | |
import com.gamua.flox.Player; | |
import com.gamua.flox.utils.createUID; | |
import flash.display.Sprite; | |
import flash.utils.setTimeout; | |
import starling.utils.StringUtil; | |
public class PlayerTimestamps extends Sprite | |
{ | |
private static const GAME_ID:String = "..."; | |
private static const GAME_KEY:String = "..."; | |
private var _loginKey:String; | |
public function PlayerTimestamps() | |
{ | |
Flox.playerClass = CustomPlayer; | |
Flox.init(GAME_ID, GAME_KEY); | |
Player.logout(); // make sure we've got a new player | |
_loginKey = createUID(); | |
trace("attempting login with key: " + _loginKey); | |
Player.loginWithKey(_loginKey, onLoginComplete, onLoginError); | |
function onLoginComplete(currentPlayer:Player):void | |
{ | |
trace("login complete."); | |
trace("player ID: " + currentPlayer.id); | |
trace("createdAt: " + currentPlayer.createdAt); | |
trace("updatedAt: " + currentPlayer.updatedAt); | |
trace("waiting 2s ..."); | |
setTimeout(changeName, 2000); | |
} | |
function onLoginError(error:String, httpStatus:int):void | |
{ | |
trace("Error on login: " + error); | |
} | |
} | |
private function changeName():void | |
{ | |
var player:CustomPlayer = Player.current as CustomPlayer; | |
player.name = "name-" + _loginKey; | |
trace("changing name ..."); | |
player.save(onSaveComplete, onSaveError); | |
function onSaveComplete(currentPlayer:Player):void | |
{ | |
trace("save complete."); | |
trace("createdAt: " + currentPlayer.createdAt); | |
trace("updatedAt: " + currentPlayer.updatedAt); | |
trace("waiting 2s ..."); | |
setTimeout(logoutAndLoginAgain, 2000); | |
} | |
function onSaveError(error:String, httpStatus:int):void | |
{ | |
trace("Error on save: " + error); | |
} | |
} | |
private function logoutAndLoginAgain():void | |
{ | |
Player.logout(); | |
trace("logged out player"); | |
trace("trying to login again with key: " + _loginKey); | |
Player.loginWithKey(_loginKey, onLoginComplete, onLoginError); | |
function onLoginComplete(currentPlayer:Player):void | |
{ | |
trace("login complete."); | |
trace("player ID: " + currentPlayer.id); | |
trace("createdAt: " + currentPlayer.createdAt); | |
trace("updatedAt: " + currentPlayer.updatedAt); | |
trace(StringUtil.format("checkout player here: https://www.flox.cc/panel/games/{0}/entities/.player/{1}", | |
GAME_ID, _loginKey)); | |
} | |
function onLoginError(error:String, httpStatus:int):void | |
{ | |
trace("Error on login: " + error); | |
} | |
} | |
} | |
} | |
import com.gamua.flox.Player; | |
class CustomPlayer extends Player | |
{ | |
public var name:String = "unknown"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's some sample output: