Mixed number and string types in playerorder array

Game development with Board Game Arena Studio
Post Reply
User avatar
salty-horse
Posts: 78
Joined: 14 June 2012, 23:08

Mixed number and string types in playerorder array

Post 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:

Code: Select all

[ "2310748", 2310747 ]
Is there a reason for this type mixup? Shouldn't they all be strings?
User avatar
Victoria_La
Posts: 665
Joined: 28 December 2015, 20:55

Re: Mixed number and string types in playerorder array

Post 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
User avatar
salty-horse
Posts: 78
Joined: 14 June 2012, 23:08

Re: Mixed number and string types in playerorder array

Post 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*
User avatar
salty-horse
Posts: 78
Joined: 14 June 2012, 23:08

Re: Mixed number and string types in playerorder array

Post 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.
User avatar
tchobello
Posts: 693
Joined: 18 March 2012, 13:19

Re: Mixed number and string types in playerorder array

Post 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 ?
User avatar
salty-horse
Posts: 78
Joined: 14 June 2012, 23:08

Re: Mixed number and string types in playerorder array

Post 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.
Thalack
Posts: 71
Joined: 31 July 2022, 19:42

Re: Mixed number and string types in playerorder array

Post 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.
User avatar
LeSteffen
Posts: 75
Joined: 13 July 2020, 15:32

Re: Mixed number and string types in playerorder array

Post 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
Post Reply

Return to “Developers”