RACE (The Random Content Engine) - Grisgram/gml-raptor GitHub Wiki

You are here:

Race - Race Flags - Race File Specs - Race Functions - Race Item Filters - RaceResult


Introduction

Race comes with a bunch of functions that will make your life easier when it comes to random content.
RACE will help you with your game development in all of these situations (and more!):

  • Generate Random Maps
  • Drop Loot (Chests, Daily Login Bonus, Dying Monsters, ...)
  • Spawn Monsters
  • Fill any board/array with random objects
  • Roll dice

Note

The most important thing about RACE is:
The elements have different chances to be picked. It is a weighted randomizer!

Create a Race Instance

Race is a script constructor class, so you create an instance through new Race(...).

/// @func	Race(_filename, _load_async = true, _add_file_to_cache = RACE_CACHE_FILE_DEFAULT)
/// @desc	Create a new random content engine, optionally loading the file async.
///		NOTE: When you load the file async, you may NOT use this race instance immediately after
///		creating it! Instead, you should add a callback through the on_load_finished(...) function
///		of this Race instance
///		Async loading should be the default and it should be done during game-startup
///		in the onLoadingScreen callback of the Game_Configuration script.
function Race(_filename = "", _load_async = true, _add_file_to_cache = RACE_CACHE_FILE_DEFAULT) constructor {

The constructor of Race will load the file you specified.
This can be done synchronously or asynchronously, where the latter is the default and allows you to get notified, when the async loading of the file is finished.

See these examples for creating a Race instance synchronously and asynchronously.

// Load synchronously
var race = new Race("myRaceFile", false); // <-- "false" disables async load
// You can use the Race instance already here in the next line
// This is convenient, but you accept maybe a frame drop or a short freeze when loading sync.
// Load asynchronously
var race = new Race("myRaceFile")
    .on_load_finished(function() {
        ilog("--- Race loading finished ---");
    });
// You can NOT use the Race instance already here in the next line!!
// Loading is still in progress. Instead do your follow-up action in the callback!

Race Classes

Class Description
Race The main class, create a new random content engine with var race = new Race()
RaceTable Represents one single loot table
RaceItem Used in the result sets of dropped loot and contains the item data and the dropped object instance
RaceItemFilter Used to create subsets of items in a RaceTable. Aquired through Race Item Filters
RaceResult Contains the result of a .query() on a RaceTable, see RaceResult

How Race works

Race is organized into tables (loot-tables). These are created in .json files or in code.
An example table is contained in the project template in the file race/demotable.json in the Included Files folder. This demo file contains all the most important options you have with a RaceTable:

  • Different item types to drop
  • The Enabled, Unique, Always and Chance flags
  • Custom attributes
  • Table link references
  • Table copy references

Don't get confused about all these new terms. We will go through them one by one.

How to drop things

This is as easy as invoking the race.query_table(table, layer, pool); method, or simply call query on a RaceTable class in your code.

With the knowledge that dropping loot is a one-liner, you'll have a powerful randomization tool at your disposal by the end of this section. Let's read on in Race Flags and the Chance.


You are here:

Race - Race Flags - Race File Specs - Race Functions - Race Item Filters - RaceResult

⚠️ **GitHub.com Fallback** ⚠️