How do I fix this in game shop?

Get help using Construct 2

Post » Tue Aug 23, 2016 1:20 am

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 :D.
If there's an easier way to create a in-game shop please let me know or show me a capx file.
B
30
S
14
G
2
Posts: 24
Reputation: 3,343

Post » Tue Aug 23, 2016 3:49 am

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.
B
51
S
24
G
6
Posts: 391
Reputation: 7,820

Post » Tue Aug 23, 2016 10:20 pm

Gearworkdragon wrote: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?
B
30
S
14
G
2
Posts: 24
Reputation: 3,343

Post » Tue Aug 23, 2016 10:35 pm

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 ?
B
8
S
4
Posts: 131
Reputation: 1,205

Post » Tue Aug 23, 2016 10:37 pm

You haven't set a price on the Item_Buy.price.
B
56
S
15
G
13
Posts: 825
Reputation: 17,643

Post » Tue Aug 23, 2016 11:04 pm

c13303 wrote: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?
B
30
S
14
G
2
Posts: 24
Reputation: 3,343

Post » Tue Aug 23, 2016 11:05 pm

Tekniko wrote: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.
B
30
S
14
G
2
Posts: 24
Reputation: 3,343

Post » Wed Aug 24, 2016 3:02 am

Yea, but in the example there was no price set. Are you sure you set it?
B
56
S
15
G
13
Posts: 825
Reputation: 17,643

Post » Wed Aug 24, 2016 11:21 am

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.
B
45
S
15
G
73
Posts: 2,026
Reputation: 43,434

Post » Tue Aug 30, 2016 7:33 pm

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 ;-)
B
8
S
4
Posts: 131
Reputation: 1,205


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot], troxx and 1 guest