Suggestion needed for random generation method.

Get help using Construct 2

Post » Wed Jan 14, 2015 5:16 am

Hi guys. I need to generate a random galaxy with let's say 10 stars. When you mouse over a star it will have a list of how many planets are present and what types. When you click on a star a new layout is loaded showing this system up close and in detail.

How I've done it thus far is on start of layout generate random stars. Each star has a variable named "planets." On star creation planets is set to random. On clicking on a star layout 2 is loaded and the amount of random planets are spawned based on star.planets.

There should be a cleaner and more effective way to do this. Possibly by using a database? I haven't touched those features of Construct yet.

Suggestions please. Thank you guys.
B
3
Posts: 4
Reputation: 210

Post » Wed Jan 14, 2015 5:34 am

There's nothing terribly wrong with that. Depends on how you expect your project to grow, i.e. will you eventually have 100 stars, etc. Perhaps give all stars an ID on creation (or use their IID) and use this ID as an index into an array that has the number of planets for each star. Might be overkill at the moment but as you add more info to your stars you can just add another 'x' value for each star. Also you can load/save as JSON file, etc. and even create the file offline in some editor. I'm not sure if I'd go down the database path just yet (C2 doesn't really have it's own db as such) but it depends on the aims of your project. Welcome to C2.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Wed Jan 14, 2015 5:53 am

Thank you for the reply. How well does Construct handle save states after a galaxy is generated? I don't want it to be random every time you enter and leave a view.
B
3
Posts: 4
Reputation: 210

Post » Wed Jan 14, 2015 6:12 am

You should have a scan of the manual, there is 'persistent' behaviour, plus different options for saving game state, some quite new.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Fri Jan 16, 2015 4:13 pm

Hmmm... I'm starting to think arrays might be the way to handle this. Thoughts?
B
3
Posts: 4
Reputation: 210

Post » Fri Jan 16, 2015 4:45 pm

If you want it to persist between sections, check the Webstorage object or write state to a DB.

Regarding arrays, yes, they are good for that and you could even save a whole array to a Webstorage object using JSON.
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
15
S
3
G
1
Posts: 329
Reputation: 2,012

Post » Fri Jan 16, 2015 4:55 pm

Or you could do it the true procedural way and use seeded random numbers so given a seed the outcome is always the same. I believe Rex had a plugin for this.
B
19
S
6
G
6
Posts: 1,101
Reputation: 5,646

Post » Sat Jan 17, 2015 7:03 pm

I have a galaxy generation algorithm that outputs 10,000+ stars with planets etc.
ui-withGalxBkg.jpg

It is all in the math that you use. We store all of our information in JSON flat file, load via AJAX, parse with RexRainbow's Hash plugin.
You do not have the required permissions to view the files attached to this post.
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"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
22
S
6
G
1
Posts: 1,414
Reputation: 4,822


Return to How do I....?

Who is online

Users browsing this forum: Alvaro2 and 14 guests