Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@PrimaryFeather
Created January 21, 2019 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PrimaryFeather/d4507fb95c0c8c5eff8d7e2d498b99ca to your computer and use it in GitHub Desktop.
Save PrimaryFeather/d4507fb95c0c8c5eff8d7e2d498b99ca to your computer and use it in GitHub Desktop.
Quick test of the 'createdAt' and 'updatedAt' properties in Flox
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";
}
@PrimaryFeather
Copy link
Author

Here's some sample output:

[Info] Game started
attempting login with key: CIAKPp2APcbzOJjw
login complete.
player ID: 81Wzq2OfzUlCHOdB
createdAt: Mon Jan 21 13:27:33 GMT+0100 2019
updatedAt: Mon Jan 21 13:27:33 GMT+0100 2019
waiting 2s ...
changing name ...
save complete.
createdAt: Mon Jan 21 13:27:33 GMT+0100 2019
updatedAt: Mon Jan 21 13:27:35 GMT+0100 2019
waiting 2s ...
logged out player
trying to login again with key: CIAKPp2APcbzOJjw
login complete.
player ID: 81Wzq2OfzUlCHOdB
createdAt: Mon Jan 21 13:27:33 GMT+0100 2019
updatedAt: Mon Jan 21 13:27:35 GMT+0100 2019
checkout player here: [removed]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment