Ryan
February 7, 2018, 5:12pm
#1
I’m trying to add a message to my game over screen in a dice gambling game that will change based on whether or not the player wins, and which win condition they met.
I was trying a method similar to how I manipulate the players total coins and jackpot values, but it doesn’t seem to work.
var GameOverMessage = pc.createScript('gameOverMessage');
GameOverMessage.attributes.add('manager', {type: 'entity'});
// initialize code called once per entity
GameOverMessage.prototype.initialize = function()
{
this.message = this.entity.findByName("GameOverTag");
this.tag = this.manager.script.gameManager._tag;
this.on('Enable', this.onEnable, this);
this.on('Disable', this.onDisable, this);
this.onEnable();
};
GameOverMessage.prototype.onEnable = function()
{
this.app.on("game:gameover", this._changeTag, this);
this._changeTag(this.tag);
};
GameOverMessage.prototype.onDisable = function()
{
this.app.off("game:gameover", this._changeTag, this);
};
GameOverMessage.prototype._changeTag = function(newTag)
{
this.message.element.text = newTag;
};
Ryan
February 7, 2018, 5:19pm
#2
Every time I post a question lately I find the solution…
Ryan
February 7, 2018, 6:04pm
#3
Never mind, problem came back. The second time the dice are rolled the toString comes back undefined.
This is what I’m attempting to do now:
var GameOverMessage = pc.createScript('gameOverMessage');
GameOverMessage.attributes.add('manager', {type: 'entity'});
// initialize code called once per entity
GameOverMessage.prototype.initialize = function()
{
this.message = this.entity.findByName("GameOverTag");
this.tag = this.manager.script.gameManager._tag;
this.winnings = this.entity.findByName("RollWinnings");
this.amount = this.manager.script.winCheck.winnings;
this.on('Enable', this.onEnable, this);
this.on('Disable', this.onDisable, this);
this.onEnable();
};
GameOverMessage.prototype.onEnable = function()
{
this.app.on("game:gameover", this._changeTag, this);
this._changeTag(this.tag);
this._changeAmount(this.amount);
};
GameOverMessage.prototype.onDisable = function()
{
this.app.off("game:gameover", this._changeTag, this);
};
GameOverMessage.prototype._changeTag = function(newTag)
{
this.message.element.text = newTag;
};
GameOverMessage.prototype._changeAmount = function(newAmt)
{
this.winnings.element.text = newAmt;
};
Error appears on line 33 (this.message.element.text = newTag;
.
mcmorry
February 7, 2018, 6:06pm
#4
Ryan:
this.on(‘Enable’, this.onEnable, this);
this.on(‘Disable’, this.onDisable, this);
are you sure that enable and disable events have the correct case?
this.on('enable', this.onEnable, this);
this.on('disable', this.onDisable, this);
Ryan
February 7, 2018, 6:06pm
#5
Oddly enough, yes. I did initially have them with lower case and it didn’t work for some reason.
mcmorry
February 7, 2018, 6:08pm
#6
Ryan
February 7, 2018, 6:09pm
#7
I understand that, I was following a tutorial to make the ui transitions and changes that had it that way, but it never worked when I tried it. And that’s not the issue I’m facing with this, the non existent toString call is returning an error.
Ryan
February 7, 2018, 6:18pm
#8
Or maybe the lack of toString is the problem.
Ryan
February 7, 2018, 6:33pm
#9
Nope, either way I get the error on the second roll.