Page 1 of 2

[Sandbox] Feedback and questions

Posted: 25 April 2020, 12:47
by laedit
Hello,

First, thanks for this editor for those who doesn't work well with CSS and haven't done any PHP in ten years.

I am trying to adapt Mille Sabords! (Piraten Kapern) through the Sandbox and since I haven't see much posts about the Sandbox I though to share some feedback and of course I have some questions :)


Feedback & ideas

The scripts documentation is good but the examples are too few, and if examples can't be added, I think that a documentation generated from code would suffice.

A more moderne editor (like monaco) with type completion would be awesome, or maybe typescript (or another) to check the code throught defintion files?
=> It is not easy to change editor, but the bga's functions have been added for completion.

Definitions files would also allow us to code outside the online editor and maybe have test and mock frameworks to check the code without having to run a test session.
=> I have started to create a definition file in the source code for Piraten Kapern (not finished).

The interface part is missing a documentation, at least a basic presentation of the editor and the game parts. I can propose one but I think I don't have the rights on the wiki.



Questions

1. Is it possible to add game a option like another score to achieve to win the game?
=> Yes, it is done through the game variant in game infos (see question #6).

2. How to add buttons in the action status bar? Like 'addActionButton' in the client-side framework.
I use clickable label for now but the feeling is not the same.

3. Just to be sure, the game has to be published in the original game name "Piraten Kapern"?

4. Is it possible to add images to log? Like miniatures of the dice.

5. Is it possible to replace default log for some action like roll? If the dice in the game doesn't have number it confuse the game log.
Example:

Code: Select all

laedit0 rolled Skull,Diamond,Parrot,Monkey,Monkey,Skull,Skull,Skull => custom
laedit0 rolls 6 dice and gets 4, 3, 1, 5, 5, 4 => default
6. How to access game variant option declared in the game infos?
=> You have to use the bga.getVariant method, which takes the id of the variant (1 or 2) and returns the option's id (1, 2 or 3).

7. Is there a way to set the 'bgg_id' like in gameinfos.inc.php to associate the game with BoardGameGeek?


Thanks a lot and sorry for the long post!

Re: [Sandbox] Feedback and questions

Posted: 27 April 2020, 10:39
by laedit
Another question, I want to move a discarded card on the discard zone, but after one move no other move are done, without any error message.
Here is the code:

Code: Select all

var firstCardId = bga.getElement( { parent: bga.getElement({name:'Deck'}), limit:1 } );
bga.moveTo( firstCardId, bga.getElement( {name:'Discard'} ) );
I checked the card id, which is correct, I tried to move to another zone but same result, after one move to the new zone no other card would move to it.

Did I do something wrong?
Edit:
I have misinterpreted the example on the script documentation for getElement:

Code: Select all

// Retrieve the last child element of another element
 // Here, we are requesting for elements who has element with ID=1234 (Deck) as their parent
 // Note the use of "limit:1" which allows us to retrieve only 1 element.
 var first_card_on_deck_id = bga.getElement( { parent: 1234, limit:1 } );
It is not the first element but the last which is returned.

So the underlying question is how to get the first element from another element?

Edit2:
This was a bad test, I was using removeElement, which works fine, but moveTo really seems to have an issue.

Re: [Sandbox] Feedback and questions

Posted: 27 April 2020, 11:05
by DoctorPelusa

Code: Select all

bga.getElement( { parent: bga.getElement({name:'Deck'}), limit:1 } );
With this line you're getting the id of the deck, not the card, try using {parent: deck_id}

Re: [Sandbox] Feedback and questions

Posted: 27 April 2020, 11:58
by laedit
Thanks for you answer!
But with this line, I pass the id of the deck to the parent selector, so this should be fine, no?

Re: [Sandbox] Feedback and questions

Posted: 27 April 2020, 12:29
by DoctorPelusa
You're absolutely right, din't see the second call to getElement, however are you sure you can define an object literal like that? In theory you should be able to, bt I'd suggest trying using an aux variable.

Re: [Sandbox] Feedback and questions

Posted: 27 April 2020, 12:31
by laedit
Normally Javascript handles it, but I tried with:

Code: Select all

var deckId = bga.getElement({name:'Deck'});
var firstCardId = bga.getElementsArray({parent: deckId}).reverse()[0];
With the same luck...

Re: [Sandbox] Feedback and questions

Posted: 27 April 2020, 12:46
by DoctorPelusa
Can you please debug to see what's actually the array contents?

Re: [Sandbox] Feedback and questions

Posted: 27 April 2020, 13:18
by laedit
Here are the trace of the array returned by bga.getElementsArray({parent: deckId}:

Code: Select all

DUMP : 
array(11) 
{ 
  [0]=> string(2) "14" 
  [1]=> string(2) "31" 
  [2]=> string(1) "8" 
  [3]=> string(2) "25" 
  [4]=> string(2) "21" 
  [5]=> string(1) "2" 
  [6]=> string(2) "13" 
  [7]=> string(1) "1" 
  [8]=> string(2) "33" 
  [9]=> string(1) "7" 
  [10]=> string(2) "27"
} 
"14" is returned when I use getElement with limit:1 and "27" is returned when I use the reversed array method.

In either case, the card should be moved but the discard zone always have only 1 card after the first move.

Re: [Sandbox] Feedback and questions

Posted: 27 April 2020, 15:47
by DoctorPelusa
I made a quick test and moveTo() is working fine for me. Few questions:
-On "How to arrange elements on it?" Stack/deck is selected?
-On "What can be placed here?" everything or the card tag is selected?

Re: [Sandbox] Feedback and questions

Posted: 27 April 2020, 16:50
by laedit
Thanks a lot, I have copied the origin zone to create the target zone but haven't checked the properties, and "How to arrange elements on it" have been reset, so a change to "Stack/Deck" have fixed it.
That said, a warning or error message would have been helpful :)