Shuffle code only shuffling one list item/not showing all in label

Hi! I'm attempting to make a card game in App Inventor, and I need to shuffle cards. It's supposed to pick a random card, save the card and index of the card, then if the card selection is currently in the unshuffled deck (basedeck) it adds the selected card to a different list and removes it from basedeck, essentially moving it. I set up a Label component to show the result to confirm it works, yet it only shows 1 card. I checked and it does shuffle, but doesn't show the other 51 cards in the Label. I've attached both the code for the shuffle and the code for the Label, can someone check what the problem is? Thanks!


image

Hello,

which is the content and where are you setting "global temp"? (are you comparing it with an empty string or with a blank?)

Because if with the last item of shuffleddeck, the check "global temp" = "" is true, then you will see only that last item in the label. In that if you are not joining the current label.Text with the new item.

This is my temp variable:
image
The text block is the same block as the two "global temp =" checks.

I'm unsure what you mean by which is my content.

Here you are joining the label.Text with the item you are removing in each iteration so, finally, label.Text will contain all the removed items:

However, here you are not joining label.text with the item you are removing. Here you are assigning only the item removed in each iteration so, only the last item removed is displayed:

so, in the "while" loop, which is the value of "global temp"?

If "global temp" = "", then you are displaying only the last item into the label.

I see! I fixed it by adding a join block in the first if/then statement between the set Label1.Text block and the select list item block as shown here.
image
Thanks!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.