Page 1 of 1
Mixed number and string types in playerorder array
Posted: 28 September 2020, 17:14
by salty-horse
Hi,
New developer here, so I may be missing something obvious.
In the gamedatas that's sent to the Javascript code, the playerorder property is an array that's supposed to include the player IDs, with the first code belonging to the logged-in player.
It seems like the first element is always a string, and the other elements are numbers.
For example:
Is there a reason for this type mixup? Shouldn't they all be strings?
Re: Mixed number and string types in playerorder array
Posted: 30 September 2020, 03:46
by Victoria_La
Does it really matter? In general you should never make assumptions of type of data which is passed between php and java and cast explicitly if this matters
Re: Mixed number and string types in playerorder array
Posted: 02 October 2020, 14:31
by salty-horse
Well, it doesn't matter in the sense that I can deal with anything that's thrown at me, but should there really be a reason for this mix-up?
It's just makes no sense. Of course, I can't find any documentation in the wiki for that specific field, but that's another issue.
And I just found another oddity: The deck object's countCardInLocation() returns a string instead of a number. *shrug*
Re: Mixed number and string types in playerorder array
Posted: 03 February 2024, 17:21
by salty-horse
One way this affects me is when using indexOf() to find the player's position in the turn order. I have to "normalize" the array before searching.
Re: Mixed number and string types in playerorder array
Posted: 03 February 2024, 21:40
by tchobello
salty-horse wrote: ↑03 February 2024, 17:21
One way this affects me is when using indexOf() to find the player's position in the turn order. I have to "normalize" the array before searching.
what do you want to do ?
Re: Mixed number and string types in playerorder array
Posted: 05 February 2024, 10:24
by salty-horse
Find the left and right neighbors of the player. I know there are PHP functions for it (getPlayerBefore/After), but couldn't find JS ones, and it felt silly to pass it in gamedatas.
Re: Mixed number and string types in playerorder array
Posted: 06 February 2024, 11:21
by Thalack
You are not missing anything obvious, it's just a weird quirk in the BGA framework. So if you want to use the playerorder property you need handle it yourself. I am just storing the player order in a const on setup, all as a number.
Re: Mixed number and string types in playerorder array
Posted: 06 February 2024, 14:06
by LeSteffen
Thalack wrote: ↑06 February 2024, 11:21
You are not missing anything obvious, it's just a weird quirk in the BGA framework. So if you want to use the playerorder property you need handle it yourself. I am just storing the player order in a const on setup, all as a number.
I second this