Page 1 of 2
How to detect "has current player won" using JavaScript only.
Posted: 13 July 2021, 10:58
by JonChambers
Surely I must be missing something. I've been going through all the docs, all the game data, all of everything, and cannot figure it out...
In javascript, is there a quick and simple way of writing:
Code: Select all
if(i_have_won_the_game){
//do something
}
Of course it's easy if I get PHP involved, but can working out whether or not the current player has won be solved with pure javascript?
Re: Probably the dumbest question I'll ever ask here...
Posted: 13 July 2021, 11:03
by vincentt
Hi
No, you should use a specific state for this that will trigger the JS code
Cheers
Re: Probably the dumbest question I'll ever ask here...
Posted: 13 July 2021, 11:51
by JonChambers
vincentt wrote: ↑13 July 2021, 11:03
Hi
No, you should use a specific state for this that will trigger the JS code
Cheers
Just in case I didn't make it clear, the game state is "gameEnd". Looking for something that differentiates a game I just won from a game I just lost. It's definitely clear that it's a game I just finished.
Re: Probably the dumbest question I'll ever ask here...
Posted: 13 July 2021, 12:03
by Tisaac
JonChambers wrote: ↑13 July 2021, 11:51
vincentt wrote: ↑13 July 2021, 11:03
Hi
No, you should use a specific state for this that will trigger the JS code
Cheers
Just in case I didn't make it clear, the game state is "gameEnd". Looking for something that differentiates a game I just won from a game I just lost. It's definitely clear that it's a game I just finished.
Just outputing state args in the onEnteringState function. I think you should figured it out from here.
Code: Select all
Entering state: gameEnd
Object { id: 99, active_player: 2322020, args: {…}, type: "manager", reflexion: {…}, name: "gameEnd", description: "End of game", action: "stGameEnd" }
action: "stGameEnd"
active_player: 2322020
args: Object { table: {…}, result: (2) […] }
result: Array [ {…}, {…} ]
0: Object { name: "Tisaac0", color: "7b7b7b", score: "-14", … }
1: Object { name: "Tisaac1", color: "ff0000", score: "-20", … }
table: Object { concede: false, disagreement: false, neutralized: "0", … }
concede: false
disagreement: false
neutralized: "0"
stats: Object { 1: 2, 2: -17, 3: "-14" }
description: "End of game"
id: 99
name: "gameEnd"
type: "manager"
Re: Probably the dumbest question I'll ever ask here...
Posted: 13 July 2021, 12:24
by JonChambers
Tisaac wrote: ↑13 July 2021, 12:03
JonChambers wrote: ↑13 July 2021, 11:51
vincentt wrote: ↑13 July 2021, 11:03
Hi
No, you should use a specific state for this that will trigger the JS code
Cheers
Just in case I didn't make it clear, the game state is "gameEnd". Looking for something that differentiates a game I just won from a game I just lost. It's definitely clear that it's a game I just finished.
Just outputing state args in the onEnteringState function. I think you should figured it out from here.
Code: Select all
Entering state: gameEnd
Object { id: 99, active_player: 2322020, args: {…}, type: "manager", reflexion: {…}, name: "gameEnd", description: "End of game", action: "stGameEnd" }
action: "stGameEnd"
active_player: 2322020
args: Object { table: {…}, result: (2) […] }
result: Array [ {…}, {…} ]
0: Object { name: "Tisaac0", color: "7b7b7b", score: "-14", … }
1: Object { name: "Tisaac1", color: "ff0000", score: "-20", … }
table: Object { concede: false, disagreement: false, neutralized: "0", … }
concede: false
disagreement: false
neutralized: "0"
stats: Object { 1: 2, 2: -17, 3: "-14" }
description: "End of game"
id: 99
name: "gameEnd"
type: "manager"
Okay, so it wasn’t a stupid question.
My solution is simpler than that, and it still works even if the page is reloaded. Thanks anyway.
Re: Probably the dumbest question I'll ever ask here...
Posted: 13 July 2021, 12:27
by Tisaac
Simpler than getting the highest score of the two players in the js ??
These are also sent in getAllDatas by framework, so you really don't have to do anything more than that.
Re: Probably the dumbest question I'll ever ask here...
Posted: 13 July 2021, 12:47
by JonChambers
Tisaac wrote: ↑13 July 2021, 12:27
Simpler than getting the highest score of the two players in the js ??
These are also sent in getAllDatas by framework, so you really don't have to do anything more than that.
The highest score of the two players is not in JavaScript. The need for the client to know the score never came up. And I’m not going to create a client side scoring system just for that one issue.
Re: Probably the dumbest question I'll ever ask here...
Posted: 13 July 2021, 14:30
by Tisaac
JonChambers wrote: ↑13 July 2021, 12:47
Tisaac wrote: ↑13 July 2021, 12:27
Simpler than getting the highest score of the two players in the js ??
These are also sent in getAllDatas by framework, so you really don't have to do anything more than that.
And I’m not going to create a client side scoring system just for that one issue.
What are you talking about ?? The BGA framework already do that for you, that's the little stars right next the player names. They get automatically initialized with the value from the DB that is send in getAllDatas without you having to do anyting.
You can access basic player infos by using this.gamedatas.players
Re: Probably the dumbest question I'll ever ask here...
Posted: 13 July 2021, 16:59
by thoun
You need more than player's score, in case of a tie
Re: Probably the dumbest question I'll ever ask here...
Posted: 14 July 2021, 10:37
by JonChambers
Tisaac wrote: ↑13 July 2021, 14:30
JonChambers wrote: ↑13 July 2021, 12:47
Tisaac wrote: ↑13 July 2021, 12:27
Simpler than getting the highest score of the two players in the js ??
These are also sent in getAllDatas by framework, so you really don't have to do anything more than that.
And I’m not going to create a client side scoring system just for that one issue.
What are you talking about ?? The BGA framework already do that for you, that's the little stars right next the player names. They get automatically initialized with the value from the DB that is send in getAllDatas without you having to do anyting.
You can access basic player infos by using this.gamedatas.players
I'm talking about exactly what you think. I've read the documentation too. I know exactly how to do everything you suggested. But I won't.
Partly because it's a couple of lines longer, but more because the score doesn't get involved until the last second (1 for winner, 0 for loser) and I want to avoid displaying said score to the player as much as possible. I know veteran players know what 0 stars mean, but for me it's just clutter. Dash-star isn't much better, but it's a mild improvement.
Also, my solution is slightly shorter.