Using the CapX


Using the CapX

The 'Array' Object

The 'Array' object you'll find in the capx is the one all of the functions work on. If you want to store data created using the toolkit, you'll want to use another data storage system as well - but we'll get into that later. What each function in the toolkit is designed to do is load an array using a function call, which returns the post-process JSON of the array.

Loading Arrays With Functions

What does it mean to load an array with a function call? When we use the 'Load' action on an array, it expects a JSON string. If you use the expression Function.Call( ... ), it gives the return value of that function. So, each function in the toolkit takes a JSON string as its first parameter. It then loads the included 'Array' object using that JSON, performs its function on the 'Array' object, and then sets its return value to the new JSON of the 'Array' object. This is why you shouldn't try and use the existing 'Array' object to store data - its contents will change whenever a function is run. Take a look at the first and last events in the 'Invert' function, and you'll see the Array is loaded on start, and returned at the end:

Using the Functions in Your Game

If you don't want to store maps, you don't need to add any new data structures. You can simply load the existing 'Array' object using the Function.Call( ... ) expression, and render from that, like so:

Storing Your Output

If you want to store maps, you will need either another Dictionary, or another Array object. Which you choose will depend on your requirements, as each can be used in different ways, and these methods can be combined:

Dictionary: Each map's JSON would be stored under a uniquely named ID. Additional data about each map would have to be stored under additional unique named IDs.

Array: Each map's JSON would be stored as a column in a 2D array. Additional data about each map could then be stored in subsequent rows on the array.



Array: Each map's JSON would be stored in a cell in a 2D array. Neighbouring cells would represent neighbouring parts of a larger map - 'chunk' building.



Array: Each map would be stored in a Z-index on a 3D array, not as a JSON, but with X,Y cells filled accordingly for each Z-index.



Parsing a Script

Any scripts you write in the input panel of the toolkit's sandbox can be transported into your project to save you the hassle of writing individual 'Array>Load' actions. Included in the examples you'll now find a 'Parse' function, which will help with this. A parser is a piece of code that reads a script. This one checks each line to find a function. If the line starts with a "#" or is empty, it ignores it - just like in the sandbox. The 'Parse' function here takes two parameters - the first being the script, the second being the number of times to run that script. Included in the latest update are the above-pictured example events, and the parser.

Get Level Generator Toolkit

Buy Now$4.99 USD or more

Comments

Log in with itch.io to leave a comment.

Can you generate rooms to go vertically?

I want to do something with that concept.

hello good morning, I want to ask if tilemaps are used to generate the scenarios

or if you have any chance that they can be used.

This pack is simply amazing. I cannot believe the amount of power you have packed into Construct. I was able to easily import this into Construct 3 (Licensed) without any issues and run. This is something I have been looking for, for a long time. Thank you!!

Oh wow, that's great to hear! I hadn't tried it on C3 yet (no license, working too hard during the jam) so that's great to hear :)