How do I fix this in game shop?

0 favourites
  • 10 posts
From the Asset Store
50 front view of buildings JPG - residences shops and offices - 2048x2048
  • Hello all im trying to create a in-game shop.

    However, I have encounter a weird problem,

    I got this shop example from an old forum post.

    Here's my problem,

    I have a global variable called totalMoney which is basically the total coins the player has collected during playtime.

    When you enter the shop with a totalMoney amount, example, System --> Start of layout --> System --> set TotalMoney to 10 and you try to buy

    a item from the shop the bought and selected functionality works fine however, NO coin is deducted from the 'TotalMoney' global variable.

    Here's an example where it does NOT work.

    https://drive.google.com/file/d/0B9tGN8-NMP_xZzBETjhwbnBzc00/view?usp=sharing

    If you go to the event sheet and look for System-->TotalMoney > item_buy.price and delete "System --> Restart Layout"

    you can see that now it starts deducting from the totalMoney but however the bought/selected functionality does NOT work.

    But, if I go into the layout with totalMoney = 0 and somehow add coins inside the 'in-game' shop everything works fine.

    I made an example of this:

    https://drive.google.com/file/d/0B9tGN8-NMP_xeVZfeTFtNU9Udmc/view?usp=sharing

    Sorry if this is confusing,

    English is not my first language and I tried my best to describe it properly.

    If you can help me fix this will be great .

    If there's an easier way to create a in-game shop please let me know or show me a capx file.

  • this is pretty simple and i can see why you didn't find it....so you have on start of layout to set the coin for start and you have when bought restart the layout will actively re-trigger the on start of layout to set the coin back to ten. So in other word the Event that is causing the problem is the restart layout.

    And you are telling construct two to buy an item reduce total money coin and then restart on layout and then on the beginning of loading the layout (on start of layout) to set coin to ten and then the text back to the ten. If you disable the on-start it will function correctly.

  • this is pretty simple and i can see why you didn't find it....so you have on start of layout to set the coin for start and you have when bought restart the layout will actively re-trigger the on start of layout to set the coin back to ten. So in other word the Event that is causing the problem is the restart layout.

    And you are telling construct two to buy an item reduce total money coin and then restart on layout and then on the beginning of loading the layout (on start of layout) to set coin to ten and then the text back to the ten. If you disable the on-start it will function correctly.

    Hi, you are basically saying to disable system --> ON start of layout --> MoneyDisplay --> Set Text to TotalMoney?

    if you are saying that, I already tried that and doesn't work. Even on debug you can see that it's not deducting the coins.

    Sorry probably I misunderstand what you said, could you give me an example?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • He's right saying the "restart" is the problem. Everytime you restart the layout, you basically start the layout, and you asked to set money = 10 at start of layout.

    You can make what you want by setting the global number Money = 10 and remove the condition "at start of layout set money = 10"

    But restart the whole layout to update your wallet feels a bit inadequate for Construct 2 I believe, it will ask to reload all the assets and things. You better update dynamically without restarting maybe ?

  • You haven't set a price on the Item_Buy.price.

  • He's right saying the "restart" is the problem. Everytime you restart the layout, you basically start the layout, and you asked to set money = 10 at start of layout.

    You can make what you want by setting the global number Money = 10 and remove the condition "at start of layout set money = 10"

    But restart the whole layout to update your wallet feels a bit inadequate for Construct 2 I believe, it will ask to reload all the assets and things. You better update dynamically without restarting maybe ?

    How do I update dynamically without restarting?

  • You haven't set a price on the Item_Buy.price.

    Hi tekniko, if you go to the shop layout and click on the item_buy,

    there's a instance variable name 'price'. Thats where I put the price value.

  • Yea, but in the example there was no price set. Are you sure you set it?

  • The prices are set as a variable, I'm wondering why you are resetting the layout all the time though, what were you trying to achieve with that? Just trying to get my head around it so I can suggest a more efficient way than resetting the layout.

  • Instead of resetting the layout, you just update the elements that needs to be updated ! That shoud involve :

    • The item you bought
    • Your inventory if there's one visible
    • Your money

    When you're playing Mario Bros, the level doesn't restart to update each time you get a mushroom or a gold coin

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)