PDA

View Full Version : Please help with pop up inventory!



slayerX2
April 10th, 2007, 04:49 PM
Thanks to hybrid101 i finally got the flipping code i need, thanks hyvrid101

hmm.... yes so anyway
I need help with a pop up inventory, EG, You pick up something on the ground and it goes to ur inventory, now u wanna check this out, so u decide to presss I to bring up the inventory, how do u make it so if u press i the inventory screen comes up, BUT not to a new page, (if anyone has played maplestory, something like that):-/ :-/

hybrid101
April 10th, 2007, 09:08 PM
haven't played maplestory, but could you post a screenshot?
im thinking of making the inventory a movieclip and using
this._visible = true or false
to make it seen:)

and no probs:)

slayerX2
April 10th, 2007, 11:50 PM
http://www.maplestory-online.com/gallery/albums/illustrations/Item_Inventory.thumb.jpg

here is the image

slayerX2
April 15th, 2007, 06:29 PM
understand????????


please reply, i got it wokrin but....u have to hold it down.
i want it so when u press i it stays up until u press i again

understand?

cheers
slayerX2

hybrid101
April 15th, 2007, 11:16 PM
on(release){
inventory_mc._visible = true
}
on the button

slayerX2
April 16th, 2007, 05:42 AM
thanks but err i alrdy got that working, now all i need is for it too stay up until, i press it and then it will dissappear cause i dont think u wanna be holding it while u kill things

DangerousDan
April 16th, 2007, 07:32 AM
on(release){

if(inventory_mc._visible)
{
inventory_mc._visible = false;
}

else
{
inventory_mc._visible = true;
}

}

slayerX2
April 16th, 2007, 04:40 PM
where do we put this code?

Chesso
April 17th, 2007, 01:45 AM
slayer, you need to detect key presses (such as I, or enter, space etc) if you already know how it is extremely easy.

I have not done it in flash but I am a Delphi/VB/C++ dev and this is a pretty general thing.

Basically what you want to do is either have a boolean variable (true/false) or check the visible state of the movieclip when they press the i key.

If it's visible, you want to make it invisible and vice versa.


e.g. (this may not be solid code but give you can idea):

if (mymovclip._visible) { mymovclip._visible = false; }
else {mymovclip._visible = true; }

Notice how I only check for one? Because there can only be 2 possible states (visible or not) it is completely unnecessary to check for the other, because if it isn't one, it will be the other.

This code would be place inside of some actionscript that detects the user pressing the i key.

If you need further assistance, let me know and I will search up on how to detect the key and explain that aswell.

slayerX2
April 17th, 2007, 07:00 AM
holy **** man were the **** did u learn all DAT im only newb, lol a newb trying to create a small rpg :D:D:D anyway i have an idea of waht ur saying but with this line u said here

slayer, you need to detect key presses (such as I, or enter, space etc) if you already know how it is extremely easy.

would that be using this code here to detect the I being press?
if(Key.isDown (Key.73)){

Chesso
April 17th, 2007, 07:05 AM
That's right.

If your Key is = i or whichever key.

Than you want to check if the movieclip (your inventory) is visible, if it is make it invisible, otherwise make it visible.

I know all this as I begun most of my programming experience in Visual Basic, Object Pascal and C++, I also dabble in game programming from time to time with all 3 and DirectX/GDI for graphics.

And now I'm learning flash and actionscript aswell (but due to previous programming experience, I can carry alot over so I get into it faster).


P.S. It's not the best thing to use for a potentially graphically complex game but experiment with the _alpha property of movieclips such as your inventory, like:

myclip._alpha = 50;

Will make it half visible (so you can see things underneath), use values between 0 and 100 (might be 0 and 255 not sure).

Could make some interesting effects :).

DangerousDan
April 17th, 2007, 07:39 AM
Well if you wanted keypress...


if(Key.isDown (Key.73)){
if(inventory_mc._visible)
{
inventory_mc._visible = false;
}

else
{
inventory_mc._visible = true;
}
}

Lord Rahl
April 17th, 2007, 09:58 PM
If you were to just change visibility that doesn't stop the fact that objects are still there. Buttons and such will still be pressable within the inventory movieclip. Then you would have to disable each button and so on. You can do this if you want by using


btn.enabled=false;

Where btn is you would place whatever the variable name is of the button you wish to disable.

Chesso
April 17th, 2007, 10:23 PM
It's an inventory, it will have many buttons ti disable, which equals more code.

Make it invisible and move it's X and Y offscreen, when visible just position back on screen.

Less code, much easier, similar effect.

slayerX2
April 18th, 2007, 05:13 AM
ok, fair enough, how would i do the x, y value thing? (i dont no much about the x, and y value only that they can move stuff and stuff, i no basic stuff about them)

lord rahl i sort of understand what ur saying but i need some more explanation to fully understand

chesso can u explain how i could do the x, y value thing?

Chesso
April 18th, 2007, 05:22 AM
In your situation you would do something like (not real code, just an example):

If user press i
{
if our window is already visible
{
make our window invisible
move our window off the screen // sumfin like mymc._x = -200;
}
else { // than the opposite we need to move our window back n show it }
}

X and Y represent LEFT (X) and TOP (Y), they are used in relation to what "container they are in", 0 left and 0 top is always the TOP-LEFT hand corner of the "container", for example if you dragged a window on your screen (such as your browser) to the far-left corner, it's X and Y would both be 0.

If you moved it to the right a little, it's X value would go up.

If you move it down a little, it's Y value would go up also.

If you moved either in the reverse direction, there respective values would go down.


So basically your stages LEFT position starts at 0, so you want to move your inventory screen beyond this (a -/negative value so it can't be seen), but this depends on the width of your inventory window/clip.

Let's say your inventory symbol is 200 pixels in width, I would do, myinventory._x = -250;

I added an extra 50 or perhaps less just to be safe.

When you want to make it usable again, just move it back to it's old X and Y (you could store the originals on startup of game etc so you can easily return it).

slayerX2
April 18th, 2007, 04:19 PM
ok i understand what you said but, when i tried to do a code to make it so when u press i (73) it would go off stage here is the code

onClipEvent(enterFrame){
if(Key.isDown(Key.73){
this._x = 700
}

}
but for some reason this line of code isn't working

if(Key.isDown(Key.73){
it comes up with an error message
**Error** Scene=Scene 1, layer=Layer 3, frame=26:Line 2: ')' or ',' expected
if(Key.isDown(Key.73){

WTF does this mean?

Chesso
April 18th, 2007, 08:05 PM
ok i understand what you said but, when i tried to do a code to make it so when u press i (73) it would go off stage here is the code

but for some reason this line of code isn't working

it comes up with an error message
**Error** Scene=Scene 1, layer=Layer 3, frame=26:Line 2: ')' or ',' expected
if(Key.isDown(Key.73){

WTF does this mean?

slayer, especially when you are new to programming or scripting be very careful with things like brackets ().

See how you setup if (Key.isDown, then proceed to (Key.73){

Oops, I see 2 left open brackets and one closing, you should always have an equal amount of brackets.

To make this eaiser and clear, you have:

if(Key.isDown(Key.73){

But should have:

if(Key.isDown(Key.73)){

TheCanadian
April 18th, 2007, 08:14 PM
Also, 73 isn't a property of the Key class. If you are wanting to check for when the key with the code 73 is pressed, just pass 73 into the Key.isDown function.

slayerX2
April 19th, 2007, 04:33 AM
wat do u mean TheCanadian
ok i understand Chesso
thanks lemme try

slayerX2
April 19th, 2007, 04:36 AM
um... the same thing keeps coming up?!?!

DangerousDan
April 19th, 2007, 09:13 AM
He means


if(Key.isDown(73))

Lord Rahl
April 19th, 2007, 01:03 PM
Moving it offscreen with x/y is fine. It does give you the desired effect as you claim. But as I said before, this still doesn't change the fact that its selectable. The person viewing the flash file would have only to accidently hit the tab key and they would have selected one of the many instances within the document (movieclips, buttons, etc.) and then they can use each object. Now this is something that will probally not happen much unless you put your game/move or whatever it is on webpages like newgrounds. People at those sites do purposly search for these things so they can claim they found a cheat or flaw.
I'm not saying don't use x/y coordinates with your movieclips, just mentioning what could happen if you do. I will say though the most common I have seen people do is create their movieclip and have the first frame blank while everything they need is in the second keyframe. Not sure how well this one turns out, but I see most people using it because it's simplified.

As for the keycode usage in your if statement, it's done as DangerousDan replied. Also, since your using keycodes you may want to take a look at THIS (http://www.geocities.com/myhostedstuff/KeyCode.swf). It's a swf that will tell you the keycode to any key on the keyboard. Kinda helpfull.

slayerX2
April 19th, 2007, 04:37 PM
ok NICE thanks that'll be easier then lookin up flash help :D um... hey wanna no whats funny that code that dangerous dan sent, it doesn't work, the same error keeps coming up :( why wont this work

onClipEvent(enterFrame){
if(Key.isDown(Key.73))
this._x = 700


}
please help, why this dont work

Lord Rahl
April 19th, 2007, 10:29 PM
ok NICE thanks that'll be easier then lookin up flash help :D um... hey wanna no whats funny that code that dangerous dan sent, it doesn't work, the same error keeps coming up :( why wont this work

please help, why this dont work
Because that codes not the same as what he said.
It should be


onClipEvent(enterFrame){
if(Key.isDown(73)){
this._x = 700

}
}
If statements require a opening { and a ending } just as a ClipEvent does. And you don't need "Key." in front of your keycode. You only need that for the "Ascii". For example: Key.RIGHT .

slayerX2
April 20th, 2007, 01:41 AM
ive tried that and guess what the same error comes up WTF IS WRONG WITH THIS

*edit* wait its working!!!!!!!!!!!!!! woot!!!!!!!! thanks so much!! ok now how do i make it go back? when u press i again

Lord Rahl
April 20th, 2007, 02:31 PM
Plenty of ways to do that. One simple way though would be like this.


onClipEvent(enterFrame){
if(Key.isDown(73)){
this._x = 700

}
if(Key.isDown(73)&&this._x == 700){
this._x = original position

}
}

That should do it.

slayerX2
April 20th, 2007, 05:00 PM
umm.... the secound liine of code

if(Key.isDown(73)&&this._x == 700){
this._x = original position

}
}
um... it stops the entire code, basically none of the code is working now :(
what do i do?

slayerX2
April 20th, 2007, 05:05 PM
Moving it offscreen with x/y is fine. It does give you the desired effect as you claim. But as I said before, this still doesn't change the fact that its selectable. The person viewing the flash file would have only to accidently hit the tab key and they would have selected one of the many instances within the document (movieclips, buttons, etc.) and then they can use each object. Now this is something that will probally not happen much unless you put your game/move or whatever it is on webpages like newgrounds. People at those sites do purposly search for these things so they can claim they found a cheat or flaw.
I'm not saying don't use x/y coordinates with your movieclips, just mentioning what could happen if you do. I will say though the most common I have seen people do is create their movieclip and have the first frame blank while everything they need is in the second keyframe. Not sure how well this one turns out, but I see most people using it because it's simplified.

As for the keycode usage in your if statement, it's done as DangerousDan replied. Also, since your using keycodes you may want to take a look at THIS. It's a swf that will tell you the keycode to any key on the keyboard. Kinda helpfull.

um a reply to this, see yea i understand where ur coming from and oviously there are gonna be some flaws, but this is my first game so im using the most basic of basic stuff!! :D


Also, 73 isn't a property of the Key class. If you are wanting to check for when the key with the code 73 is pressed, just pass 73 into the Key.isDown function
now i understand what "The Candian" was talking about :D

Lord Rahl
April 20th, 2007, 10:31 PM
um a reply to this, see yea i understand where ur coming from and oviously there are gonna be some flaws, but this is my first game so im using the most basic of basic stuff!! :D


now i understand what "The Candian" was talking about :D
Hey whatever works right. ;)
I just point of tips here and there and help with what I can. I did the same when I first bought flash MX when it came out.
As for my code, I tried the code and surprisngly it didn't work like you said. Only it didn't stop everything else like you said it did to you. It only would move the movieclip to 700 and wouldn't go back. I'll try and see if I can come up with anything to help.

slayerX2
April 21st, 2007, 06:23 AM
ok kewl thnx, can u suggest something for me to study in flash help, that could possibly help me with stuff