How to series - 'In Game Shop'

6
  • 79 favourites

Index

Stats

12,137 visits, 31,447 views

Tools

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Developing our shop

- We need to handle clicking the buttons and taking the money away.

Variables

Firstly we need some varaible's on that vars event sheet:,

- Add a Global variable called Money, Give it a initial value i set it to 1000.

- Add a Global variable called PlayerSpeed, Give it a initial value. Mine is set to 400

- Add a Global variable called PlayerHP, Give it a initial value. Mine is set to 100. this is the players health.

- Add a Global variable called PlayerArmor, Give it a initial value. Mine is set to 50. This is the armor of the player

- Add a Global variable called MaxJump, Give it a initial value. Mine is set to 100. This is the maximum jump value of the player.

Lets but things

The buttons allready have a onClicked action, So lets assign that to our three buttons. Should look something like this:

Once we have something like this, We need to check if we can afford it.

So on the button, Give it a instance variable of Price, set it to something like 100.

Should look a little like this:

Repeat for all three buttons giving them a price of which your happy with.

Check to see if we can afford it

Now on the button add Another condition(right click -> add another condition)

the condition we want is:

    {ButtonName}.compareInstanceVariable(Price <= Money)

Were checking to see if the price associated with the current button is less than the money variable, If it is then we can buy it.

Repeat this process for each button, making sure you compare the price with the correct button..

Should look a little like this:

Lets take some money

Events:

Now we have compared to see if we have the money we can easily take the money away and apply the upgrade.

- All were doing here is subtracting the price instance variable from the Global variable 'Money'.

Lets add some powers

to do this all we have to do is add to the other variables, according to the button pressed. Should look a little like this:

Congratzzzzz!! we have sucesfully managed to take money away from the player and add it to his game. But were not done yet.

Lets add a quick event so we can see the money in that text box.

Add this event:

     System.EveryTick
          ->TotalMoney.setText("Money:" & Money)

For brownie points

Lets add three more text fields to show the current value of the othe variables were adding to.

So i added 3 more named:

-> MaxJumpText

-> PlayerSpeedText

-> PlayerArmorText

so to get them to say the variables values, Its the same as the money.

So overall your every tick event should look like this:

     System.EveryTick
          ->TotalMoney.setText("Money:" & Money)
          ->MaxJumpText.setText("Max Jump:" & MaxJump)
          ->PkayerSpeedText.setText("Player Speed:" & PlayerSpeed)
          ->PlayerArmorText.setText("Player Armor:" & PlayerArmor)

Here's a image:

I'm sure some of you have realized by now nothing has really happened. Well on the next page we will apply these vars to the game.

  • 4 Comments

  • Order by
Want to leave a comment? Login or Register an account!