How to series - 'In Game Shop'

UpvoteUpvote 5 DownvoteDownvote

Index

Features on these Courses

Stats

13,269 visits, 33,093 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.

Published on 12 Jan, 2012. Last updated 19 Feb, 2019

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.

  • 5 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • Figuring out how to make your shop actually work—not just exist—is a whole journey. For me, the turning point was realizing how much smoother things run when all systems talk to each other properly. I was struggling with keeping inventory, orders, and customer data synced until I came across a team that helped me integrate everything through Magento. It seriously made a difference. I used perspectiveteam.com/services/magento-integration for the integration part, and the whole setup just clicked after that. If anyone’s stuck juggling disconnected tools, getting solid integration help is a game changer.

  • Can i get the capx? This capx is not active. Pls help me!

  • Thank you! You help me so much! :D

  • Same here. I t will be nice to have this tutorial again. Very useful!

    Thank you

  • Hi. The capx address is not valid anymore. Is there a way to get it again?

    Thanks