# Game Inventory Problem

• Proficient
• Posts: 254

3+ Months Ago

Hey,
Basically i have 16 inventory slots and a heap of items you can pick up along the way. You add them to your inventory by dragging the item onto one of the slots. There is no designated slot for each item, and it doesn't need to add in order, i just want you to be able to drag the item onto any random slot. I've got the code for that, but I was just wondering if there is a way i can test which slot i drop the item on without a truckload of if statements? Any help would be much appreciated =D

Grant.
• Fart Bubbles
• Posts: 13506
• Loc: Florida

3+ Months Ago

If you drag items to a slot, I'm guessing there's movieclips setup to represent drop targets for each slot.

If you assign a slotID to each of thoose movieclips, you should be able to keep track of what slot has been used with a generic function.
Realisticly, you should be able to do somthing with the instanceName of the movieclips.
• Proficient
• Posts: 254

3+ Months Ago

Quote:
If you drag items to a slot, I'm guessing there's movieclips setup to represent drop targets for each slot.

when you drag and item to a slot all it does is stops the drag and sets the x and y position of the MC to the center of the slot.
• Fart Bubbles
• Posts: 13506
• Loc: Florida

3+ Months Ago

Are there movieclips representing the slots ?
Could you alter the function that sets the x & y to also return the name of the movieclip that centerpoint is being determined from ?
• Proficient
• Posts: 254

3+ Months Ago

joebert wrote:
Are there movieclips representing the slots ?

Yes

Quote:
Could you alter the function that sets the x & y to also return the name of the movieclip that centerpoint is being determined from ?

Thats exactly what im after =D however im not sure how to go about it...i found this tutorial http://www.tutorialized.com/tutorial/Droptarget-Great-for-Games/2399 but i've gone through it and i don't really understand it.
• Fart Bubbles
• Posts: 13506
• Loc: Florida

3+ Months Ago

If you look in the library for that movie, you'll see a movieclip named "text field movie".
If you edit that movieclip & look at the actions, you'll see this.

Code: [ Select ]
displayText = getProperty("", _droptarget);

The _droptarget property is the name of the movieclip that the movieclip being dragged is on top of.

If you got the _droptarget of your inventory movieclip, you'ld get the name of the slot it's getting dropped in.
• Proficient
• Posts: 254

3+ Months Ago

hmm ok that makes sense. The only other thing though is that i can't find where it is setting the contents of the dynamic text box to the contents of the displayText variable?
• Fart Bubbles
• Posts: 13506
• Loc: Florida

3+ Months Ago

displayText is the variable name assigned to that dynamic text field.
Not the instance name, the variable name.
• Proficient
• Posts: 254

3+ Months Ago

ahh i get ya now. Hmm i've just had a bit of a play with it and its working well except for one tiny error. This is the function that is being run when you release your mouse (after holding down the mouse on the item to drag it).

Code: [ Select ]
function dropitem(drop) {
trace(drop);
trace(_global.text1);
if(_global.text1.hitTest(drop)==true) {
trace("on target");
} else {
trace ("off target");
}
}
1. function dropitem(drop) {
2.     trace(drop);
3.     trace(_global.text1);
4.     if(_global.text1.hitTest(drop)==true) {
5.         trace("on target");
6.     } else {
7.     trace ("off target");
8.     }
9. }

the _global.text1 is equal to the name of the MC which you drop it on (invslot1 or invslot2). For some reason though when i have it with the global variable there it wont work..but if i replace it with a specific slot name it will work like a charm...any ideas why its doing this?

source - drag and drop test
• Proficient
• Posts: 254

3+ Months Ago

Yes! i got it working...all i had to change was:

if(_global.text1.hitTest(drop)==true) {

to

if(eval(_global.text1).hitTest(drop)==true) {

Thanks a heap for the help Joebert =D
• Fart Bubbles
• Posts: 13506
• Loc: Florida

3+ Months Ago

Somthing about that eval looks kinda scarry.

Have you tried _root.text1 instead of _global.text1 ?
• Proficient
• Posts: 254

3+ Months Ago

Yep, i'm using that way now.

## Post Information

• Total Posts in this topic: 12 posts
• Users browsing this forum: No registered users and 4 guests
• You cannot post new topics in this forum
• You cannot reply to topics in this forum
• You cannot edit your posts in this forum
• You cannot delete your posts in this forum
• You cannot post attachments in this forum