Flash Actionscript 2.0 Tutorial – Making a Shop System for Your Game

So you have your characters, your world, your
foes and now you want to give your players a shop to
visit so they can buy weapons, armor or spells or maybe
you’re not even making a combat game maybe your players
are just looking for clues to a mystery. Whatever the
case may be, if you need a shop for any reason this
tutorial will help you. Keep in mind that there are other
and most likely much better ways of doing this but since
your reading this I’m assuming you don’t much know how to
do this so we’re keeping this at beginner’s level.

Step 1 – Getting the Money

The very first thing you want of course is for
your player to have some money to spend. To do this just
simply go to either your setup frame which is just a blank
frame with all your variables or if you don’t have one put
the variable on your main frame saying:

Money = 0

Now when your character defeats an enemy have it
add to your Money. There are a couple ways to do this. If
you have it set to where your enemies are movie clips
then when you have your clips unload, go directly under
that line and add

_root.Money+=10;

or however much you want to. Another way if your
game consists of your player opening treasure chests or
something have it say the same line on release. If any of
this is confusing and you need more info feel free to
contact me. I’m trying to keep this short but it looks
like that’s not going to happen so if I miss anything
please feel free to inform me.

Step 2 – Making Your Shop Button

Start by making a new frame and on your main frame with
your hero make a button that says shop. Or if you want to
get detailed you can draw a shop and make an invisible
square around it (just make a static text box and type
nothing in it) and make that into a button so when people
click on the shop it’ll take them to the shop page. If
you don’t know how to make a button you can click the
link in the resources and that’s a tutorial that will
show you how. Once your button is made, click on it,
press f9
and type in:

on(release){
gotoAndStop();
}

Where you see the () put in between them the
number of the frame that the shop is in. Or you can name
that frame “shop” and type it in like this:

on(release){
gotoAndStop(“shop”);
}

Step 3 – Making Your Shop Page

Now go to your shop page and maybe just to give
it some looks you can put in a Static Text in the center
top saying SHOP. You can decorate it more later but for
now we’ll keep it simple. To put items in your shop like
say an apple. Draw an apple somewhere or whatever you
want and then put an invisible box around it and make it a
button. Also make a Static Text somewhere like on top of
it or beside saying it’s price. For lets say 5 bucks so
type in:

Price – $5

Now make another new frame and have the button over your
apple take you to that page. On your new page put a
Static Text saying “Would you like to buy an Apple for
$5?”
and under that put two more Static Text one on the
bottom left saying Yes and on the bottom right saying
No. Convert both of these to buttons and on the Yes
button type in:

on(release){
_root.apple+=1;
_root.Money-=5;
gotoAndStop(“shop”);
}

Of course you can also say gotoAndStop( whatever
frame number your shop is in ); On the No button just
simply have it take you back to the shop:

on(release){
gotoAndStop(“shop”);
}

To make multiple items just repeat Step 3 for
each item. To bring yourself back to the main frame just
set up a BACK button on the bottom of the shop page
somewhere and of course have it take you back to the main
frame. And that’s it for making a shop. Simple right?
As I was reading over this I can see how some things may
get confusing so if you have any questions feel free to
contact me at [email protected] Take care and good
luck.


People also view

Leave a Reply

Your email address will not be published. Required fields are marked *