LayerToFront (possibly bug)

Report any Hollywood bugs here
Post Reply
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

LayerToFront (possibly bug)

Post by Bugala »

Heres the piece of code I am using in case someone can point an error in it:

Code: Select all

Local t_resourcecardsinhand = t_player.resourcecardsinhand
   InsertItem(t_resourcecardsinhand, "empty", 0)
   Local multiplier=0
   ForEachI(t_resourcecardsinhand, Function(index, value)
		If value = "empty" Then Return
		LayerToFront(value)
		MoveLayer(value, #USELAYERPOSITION, #USELAYERPOSITION, t_player.resourcecardx + (carddata.spacebetweencards * multiplier ), t_player.resourcecardy, {speed=carddata.movingspeed} )
		multiplier = multiplier + 1
					  EndFunction)
   RemoveItem(t_resourcecardsinhand, 0)
Here is same code with some number values and name modifications to make it easier to read:

Code: Select all

   InsertItem(t_cardsinhand, "empty", 0)
   Local multiplier=0
   ForEachI(t_cardsinhand, Function(index, value)
		If value = "empty" Then Return
		LayerToFront(value)
		MoveLayer(value, #USELAYERPOSITION, #USELAYERPOSITION, x + (100 * multiplier ), y, {speed=20} )
		multiplier = multiplier + 1
					  EndFunction)
   RemoveItem(t_cardsinhand, 0)
And bit of explanation:

Point of this piece of code is to arrange cards in hand (displayed on screen) in such way that the left most card would be shown on top of the other cards, and then rest of the cards would be partially hidden under previous cards, making the right most card be on bottom of every other card. Just like when you hold real playing cards in your hand.

Because of Hollywoods "Foreach" command works in such way, that location 0 is checked last, I am adding this value "empty" to index 0 so that cards would stay in same order, otherwise every time this routine is ran, all cards would change their positions to one place left, plus the left most one would change to become the most right one (or by other words, the last one).

After this routine is ran, I am using "Removeitem" to remove that index 0:s "empty" away again to make the table hold only those cards in it.


Personally I cant find a fault in this code, but when i execute it, it results in following:
https://www.dropbox.com/s/17nayj3r8rcmn ... m.jpg?dl=0

Even if it would execute all the table items in random order, it should still result only in cards changing place and still be in intended way of one being on top of the others, and rest neatly below that card, partially shown.

I have used gimp to put together those pictures of different situations to demonstrate the problem better.

Top most picture i have the original 2 cards (this piece of code havent been executed at that time yet)

Then next pictures I am taking one more card to the hand, and each time card is placed in hand, this piece of code is executed.

Strangest in this is that cards keep switching their places in relative to their neighbor cards from top to bottom each time new card is added.

I havent tried running this piece of code without new cards being add to hand. So I dont know if this is a result of more items being in table, or would this switching from top to bottom to top also happen if i would just be runing the code with same amount of cards.


Any ideas if this a bug or I am doing something wrong here?
User avatar
airsoftsoftwair
Posts: 5443
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: LayerToFront (possibly bug)

Post by airsoftsoftwair »

Impossible to tell from a quick look. You need to break this code down into very small pieces in order to check what's wrong there.
Post Reply