How do I Make in game Shop/upgrades without Global Variables

Get help using Construct 2

Post » Fri Aug 15, 2014 3:47 pm

Hi there, I have been struggling with this for some time. Im working on a game project where you can upgrade your ship and weapons stats in shop than continue to another level.

Something like in Tyrian (https://www.youtube.com/watch?v=w4XOBfOcYgE shop screen is in 2:10) Top Down shooter, but bit more complex. I want to change statistics of each weapon and each ship. Ship statistics would be max speed, agility, HP, Shield points etc. Weapons would have its own stats.

Here is the catch, I want to make it somehow without using lot of global variables (maybe 4 to 6 maximum). Is it even possible? If not, how many of global variables I should use.

Thanks in advance!
Try my creations on newgrounds or Google play, feedback highly appreciated!

ImageImage
B
9
S
1
Posts: 73
Reputation: 785

Post » Fri Aug 15, 2014 4:01 pm

Absolutely possible. You can store the data in either an Array or a Dictionary object (I prefer Arrays so I can just reference a spreadsheet of my own). You would store the bass stat for each as 0,1 0,2 0,3 and so on. Then the upgrade number in 1,1 1,2 1,3 etc. Then I would set the "result" in 2,1 as Array.At(0,1)+Array.At(1,1) so then you can reference all three numbers in your UI to make things even clearer for your users.
B
103
S
38
G
19
Posts: 962
Reputation: 17,996

Post » Fri Aug 15, 2014 4:47 pm

Thank you for your reply C-7, Im kind of scared of using arrays, it is much easier to pick global variable by its name like "WeaponSpread" and than using it instead of coordinates in array to localize the right value.

I am afraid it would be very confusing if I add more and more statistics, if you know what I mean. Is there a way to somehow name the value and pick it by the name, instead of coordinates ?

I tried to use dictionary just for taking the values from layout A to layout B and I failed. Can someone make a simple .Capx of how I can do that or link to some tutorial?

Arrays and Dictionaries are pretty vast topic, so I would love to know where to start.
Try my creations on newgrounds or Google play, feedback highly appreciated!

ImageImage
B
9
S
1
Posts: 73
Reputation: 785

Post » Fri Aug 15, 2014 11:46 pm

I don't like posting links to the manual, but the Dictionary object would do precisely what you are looking for. You'd use something like Dictionary>Add "shield" and set it to 50 or whatever. Then you can reference that value at any time Dictionary.Get("shield") instead of your global variable call.

The manual: https://www.scirra.com/manual/140/dictionary
B
103
S
38
G
19
Posts: 962
Reputation: 17,996

Post » Sat Aug 16, 2014 8:15 am

Thanks, I've already been in the dictionary documentation, looks like I did something wrong in my project. I'll look in to it deeper, I hope I will make it work this time :D
Try my creations on newgrounds or Google play, feedback highly appreciated!

ImageImage
B
9
S
1
Posts: 73
Reputation: 785

Post » Sat Aug 16, 2014 1:58 pm

WebStorage is also an option, especially if you want data to persist even after game closes (for example, save game progress)

https://www.scirra.com/manual/120/webstorage
B
63
S
12
G
6
Posts: 456
Reputation: 8,981

Post » Mon Aug 18, 2014 3:48 pm

Hi thx for your responses guys, I bumped in to a problem, it seems like Dictionaries arent able to store instance variables of some object as values. Am I right? How can I store value as an instance variable of some object than transfer the value from instance variable to a another layout.
How can I do it? Thanks in advance for any reasonable reply !

Capx below
You do not have the required permissions to view the files attached to this post.
Try my creations on newgrounds or Google play, feedback highly appreciated!

ImageImage
B
9
S
1
Posts: 73
Reputation: 785

Post » Tue Aug 19, 2014 12:55 am

You are doing it right but, you forgot to create an object "cage" on the LO_RabbitsNumber layout. So when you assign the "Rabbits" value of the dictionary to the instance variable of cage you are assigning that value to nothing, because there no object to assign that value to.

Also, it would be better to increase, decrease the value of items when the + or - buttons are clicked, not after going to another layout.
B
21
S
5
G
3
Posts: 53
Reputation: 3,335

Post » Tue Aug 19, 2014 2:05 am

I don't have much to offer but a helpful tip would to be to add webstorage like russpuppy said. If this is going to be a mobile application then you should webstorage to save the players purchases. I would hate it if I purchased something from a store and then when I came back to play again, I would have to start over.
B
37
S
14
G
3
Posts: 263
Reputation: 4,270

Post » Tue Aug 19, 2014 10:25 am

Im making progress it works now, thx donelwero! I feel little dumb to not being able make it on my own.

So, another questions is better to use webstorage or dictionary?
Should I use webstorage only? It looks like a better idea if I want to store these values after the program restarts. Or is there some profit of using Dictionary and than save the values to webstorage?

Working Capx below.
You do not have the required permissions to view the files attached to this post.
Try my creations on newgrounds or Google play, feedback highly appreciated!

ImageImage
B
9
S
1
Posts: 73
Reputation: 785

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 44 guests