PDA

View Full Version : Found objects get stuck in inventory


Kullsyre
06-23-2009, 05:47 PM
Hello everyone. This is my very first post in this forum and I hope someone will be able to give some advice to my problem.
I have just finished my very first flash-game. (I am a total newbie) Its an escape the room-kind of game (except you try to enter a house instead and everything works like a charm EXCEPT for one little very serious snag:
When you have located and collected objects and they are in the inventory you can drag them around - and if you click when youre in the inventory the object snaps back to the x and y values just fine - BUT - IF you drag them into the "rooms"-view first and then release the mouse-button and "drop" (click) them on another object already in the inventory - it gets stuck on top or behind it and the game is ruined. You cant get any further - the object can never be removed.
I have followed this tutorial:
http://www.shatteredgames.com/tutorial
and all code is copied from there.
If someone wants to try out my game and see the problem - here is the link: http://pissekult.com/house
So you wont have to search for things: - there is a cigarette hidden to the right low down from the front door of the house - a badly drawn ketchup bottle to the right in the frame with the grassy field - and a hotdog on the little bench in the middle of the frame with the barn, just to name a few. The problem happens regardless of what object is used/dragged.
If someone would be kind enough to have a look and give me some tips to solve this problem - it would be greatly appreciated. And if it would help - I could upload my .fla - file for you to look at.

rrh
06-23-2009, 06:54 PM
It also seems that I can get the bug by dragging items on the right onto items on the left, but not the opposite. I only tested with three objects, but it seems to be the case.

In which case, is there some kind of for loop where you test the locations of the items? You might need to handle that differently. If you're doing two actions in the same loop, you might need to split it into two loops to ensure that the first action is complete for all items before starting the second loop.

Kullsyre
06-23-2009, 11:03 PM
I dont think there is any loop - at least not in the scripting, - down below in the game - all of that is the inventory (inv_mc) and the area with pictures is another mc called rooms_mc - so u drag objects from inv_mc out onto the rooms_mc - and something happens if i touch the closeup view of another/the right object - and there is a script which snaps the object back to its original position if itHitTests - background_mc which is the background of the inventory - which works - apart from the bug. It seems that if the object you are dragging is EXACTLY over another object, it stopsDrag - which is understandable - because it doesnt hit "background_mc" - but then is there another way of doing it I wonder? I,ve tried resizing the objects to different sizes - but it still sticks.

Kullsyre
06-23-2009, 11:10 PM
I just thaught of something... - this is the script for dragging the objects:

var cig2_mc:MovieClip;
cig2_mc.onPress=function()
{ cig2_mc.startDrag(); }
cig2_mc.onRelease=function()
{ if(cig2_mc.hitTest(background_mc))
{ cig2_mc.stopDrag();
cig2_mc._x=42.9;
cig2_mc._y=-2.6;
}
}

Would if be possible I wonder to include the names of all the other draggable objects to be included in addition to "background_mc" - then the dragged object would snap back even if it was directly over another object - I would like to try - Anybody know what the script would be? (like: background_mc, object2_mc,object3_mc) How would the syntax look?

rrh
06-23-2009, 11:29 PM
Oho. The difference isn't which one is to the left, it's which one did I pick up first. The order I pick them up changes the order they are layered in. So it's only when I'm carrying one that's behind the new target that it's a problem.

One cheap way to fix it could be to use swapDepths(HighestPossibleDepthOfAnItem) when you pick up an item to make sure it's above all the other items.

Kullsyre
06-24-2009, 12:36 AM
Really? They get layered behind other objecs?? How do I - um swap - that thing you said - do you have an example of a script I could use?

Kullsyre
06-24-2009, 08:18 AM
Hallelujah ! Thank you and bless you man ! You led me onto the right track ! After a night of searching for the right syntax I found an example here in the forum, and sort of muddled the correct syntax from there, so I ended up with attaching this script to every draggable object:

onClipEvent(enterFrame)
{
this.onPress = function()
{
this.startDrag();
this.swapDepths(this.getNextHighestDepth());

}
}
and that did it ! Now when you click and drag an object it always goes above the other objects - and the problem is solved ! I would never have figured this out without your comment, and it was very kind of you to actually take the time to play my game and so if youre ever in Norway - youre welcome to come stay with me :-)

Kullsyre
06-24-2009, 09:40 AM
... game works fine in Internet Explorer - but if I play the game in Mozilla Firefox - there are all kinds of strange bugs !???
Like I can drag the ketchup bottle out and it still remains so I have 2 of them, and after I collect an object - it disappears - like its supposed to - but its back if I go to the same place later??

Any thaughts on this?

Kullsyre
06-24-2009, 09:59 AM
huh ! um - I restarted firefox and closed flash, then I couldnt get any bugs to appear, so I guess I jumped the gun on that one - everything seems to work a ok :-)