How do I implement a lot of constant data efficiently?

Get help using Construct 2

Post » Wed Jan 27, 2016 2:03 pm

Hi Guyz,

It's already 3rd day I think how should I do it the right way, so I thought maybe you could give me your opinion.

The game
The game is a single-player 2d action shooter, where you have 10 different weapons and each weapon has 10 upgrades so it's like 100 weapons. And each weapon has a primary and a secondary shot. Each weapon upgrade gives different stats for the weapon and those are:
- fire rate (primary shot)
- fire rate (secondary shot)
- min damage (p. shot)
- min damage (s. shot)
- max damage (p. shot)
- max damage (s. shot)
- radius of impact (p. shot)
- radius of impact (s. shot)


So 8 variables (constants actually) per one level of each weapon which gives after all 800 numeric variables.

BTW: game is dedicated to be released on desktop (Steam) so I have to think locally (no MySQL etc.).


The problem
My problem is that I am not really sure how should I implement these data to C2 the right way. I mean here to do not make a mess in the code and to be able to easily change it whenever I need.

Possible solutions

Solution 1 - XML
First thing that came to my mind was XML. I can create some XML file and put data there, then load it on start of the game. But I don't really want to have an external file somewere in the project directory which could be "hacked". I was thinking to encode it with some salt using some two-way encryption algorythm like Base64 or so, but then again there is nothing implemented in C2 and I don't really want to use any third party plugins here, cause I had a lot of performance issues with previous game.

Solution 2 - Dictionary/Array
I can also put data to some C2 data holder like Array or Dictionary. But I would have to set all data programmatically at the start, and this involves a lot of index constants etc... Then for any change it would be really not readable searching among 800 "set" functions... for some reason it gives a messy feeling.

Solution 3 - local constants
At the beginning that seemed to me the worse idea, but it starts to be the best in my opinion. First of all constants are the fastest to read for engine I believe. Second thing is that I have each weapon behaviour in separate event sheet so I would put only 80 local constants per event sheet. They seems to be readable and easy to change. I have even implemented part of this solution.
Image

But still I'm not 100% sure it's the best way to keep the readability and architecture clean.

Any suggestions would be very appreciated.
ImageImageImage
B
28
S
16
G
82
Posts: 1,030
Reputation: 45,804

Post » Wed Jan 27, 2016 5:44 pm

If you don't want to use a project file, but still read from a xml file, you could paste in the contents of your xml file into the xml load action.

I'm not sure how much minifying does to that string. Perhaps you will still end up with a "hackable" solution, just less obvious. Though imo my philosophy would be "let people hack the game, if it is fun for them", as long as it is single player.

If you don't want to use project files or pasting file contents in somewhere, I think it only leaves the solutions of setting the values in events / variables.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

Post » Wed Jan 27, 2016 6:00 pm

mindfaQ wrote:If you don't want to use a project file, but still read from a xml file, you could paste in the contents of your xml file into the xml load action.

Thanks for reply @mindfaQ. Setting XML directly as a string into loading function would be a horror to edit it later :)

mindfaQ wrote:"let people hack the game, if it is fun for them", as long as it is single player.

Well... ye... I had that thoughts as well... hmm...
ImageImageImage
B
28
S
16
G
82
Posts: 1,030
Reputation: 45,804

Post » Wed Jan 27, 2016 7:06 pm

BackendFreak wrote:Setting XML directly as a string into loading function would be a horror to edit it later :)

Just curious: why? (I'm not saying it is easier maintainable than the variables spelled out in the engine, just don't see a big hurdle)
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

Post » Wed Jan 27, 2016 9:53 pm

Because it would be a pure/raw string data. XML for 800 values would be pretty big so to use it in a comfortable way you would expect collapse/uncollapse options for nodes and surely a syntax colorization. C2 does not have XML syntax colorization for string values. I could use a second editor only for this XML but then again it's getting messy to me. I like code to be tidy and readable.
ImageImageImage
B
28
S
16
G
82
Posts: 1,030
Reputation: 45,804

Post » Wed Jan 27, 2016 10:03 pm

I think you would use your prefered xml editor on the sidelines and after you are done editing, copy it over again into the Construct 2 field.
(I wouldn't do it either, but wouldn't have a big problem with it ^^)
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

Post » Wed Jan 27, 2016 10:14 pm

Allright... maybe I overreacted with this "horror" :D... but I like to keep things the best way possible :)
ImageImageImage
B
28
S
16
G
82
Posts: 1,030
Reputation: 45,804

Post » Sun May 15, 2016 12:00 am

Did you end up coming up with a good solution? I'm dealing with the same problem atm. For me it all comes down to scale-ability and how well I can change things and how efficient it all is. I am considering 3rd party plugins such as rexrainbow's csv, csv2array, asv2dictionary.
Image
B
33
S
11
G
2
Posts: 564
Reputation: 5,163

Post » Sun May 15, 2016 12:16 am

B
109
S
27
G
276
Posts: 4,480
Reputation: 154,420

Post » Mon May 16, 2016 4:16 pm

I don't think you can avoid hacking in a local HTML game, even if you store it in memory.
https://www.ravenheart.ca/home
I don't check the forums much anymore, but I will receive an email for PMs.

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
23
S
6
G
1
Posts: 1,419
Reputation: 4,857


Return to How do I....?

Who is online

Users browsing this forum: R0J0hound and 52 guests