I have built a function which carries out a set of operations given two parameters. The function looks as follows:
playingHand[Player_, Name_String] :=
Row[{Style[Name <> ":", FontSize -> 48, FontFamily -> "Calibri"],
Spacer[20]}~Join~
If[Player == {}, {Style["Not playing", 48, Gray,
FontFamily -> "Calibri"]},
{ButtonBar[Table[
With[{i = i},
Player[[i, 3]] :>
{AppendTo[discardPile, Player[[i]]],
Player = Delete[Player, i]}],
{i, Length@Player}]]}]]
The gist of this function is that as its first input it takes a list, which looks something like:
and displays the third elements of each list within that list:
It also makes these images clickable, so that when one of these cards is clicked, it should disappear from player1
and get added to an initially empty list called discardPile
. So far so good. When I run this function by itself without the defined function, namely like this:
ButtonBar[Table[
With[{i = i},
player1[[i, 3]] :>
{AppendTo[discardPile, player1[[i]]],
player1 = Delete[player1, i]}],
{i, Length@player1}]] // Dynamic
it works like a treat. The cards are clickable and they disappear from the ButtonBar
as soon as they are clicked and added to discardPile
. When I try to do the same from within the function though, namely playingHand[player1, "Aron"] // Dynamic
it suddenly stops working. A Set::shape
error message comes up warning that two lists are not the same length, and although it does add the card to discardPile
, it does not remove it from player1
. So:
- What is wrong with this function and why won't it delete the card from the list when it is clicked, and
- How come the same error does not occur when I run the function directly without calling it by its function name?