RaceResult - Grisgram/gml-raptor GitHub Wiki
You are here:
Race - Race Flags - Race File Specs - Race Functions - Race Item Filters - ✔RaceResult
When you query a table either on the Race object through race.query_table(tablename,...)
or directly on the table through table.query(...)
, you will receive a struct (not an array!), containing the result of the query.
The reason, why the result is a struct and not an array is simple:
It allows you to supply this result to any Race function, taking an item subset as argument!
Examples are the Race Item Filters and all set_all_*
functions, a table has to offer. Those functions make no difference between the items in a table or a supplied subset of them.
The RaceResult class
Property | Description |
---|---|
instance |
The dropped instance. This member is always undefined , if you did not supply a _layer_name_or_depth_ argument to the query(...) function |
table_name |
The name of the Race table, where this item dropped |
item_name |
The name of the item |
item |
The RaceItem struct. This contains also all .attributes of the item |
[!NOTE] A note on
attributes
: If the race entry had no attributes, this member is set to an empty struct{}
by Race, and is neverundefined
.
All contained objects already exist on the layer and are instantiated.
Their onCreate
events have already been executed.
If no drop was generated, instance
contains undefined
.
Example
To avoid confusion about item name
and asset name
, I want to post a simple example here demonstrating the link between one item line in the json file of a race table and the result struct when this item drops.
{
"Epics": {
"loot_count": 1,
"items": {
"EpicWeapon1": {"type": "Thunderstrike", "always": 0, "unique": 1, "enabled": 1, "chance": 1.05, `
"attributes" : {
"base_damage": 1250.0
}
}
}
}
}
When this drops in a query, the result struct looks like this:
Property | Description |
---|---|
instance |
An existing object instance in the room, of type Thunderstrike |
table_name |
Contains "Epics" |
item_name |
Contains "EpicWeapon1" |
item |
Contains {"type": "Thunderstrike", "always": 0, "unique": 1, "enabled": 1, "chance": 1.05, "attributes" : { "base_damage": 1250.0 } |
onRaceDrop Callback
Sometimes you might want to know, when an item got hit by a query, when it drops.
To react on the moment, when an item gets spawned through a Race query, you may create
onRaceDrop = function(_item_struct) {
}
If this function exists in the spawned object, it will be invoked, right after the object has been created.
This means, the query is still running, there might be more drops occuring after this one.
You are here:
Race - Race Flags - Race File Specs - Race Functions - Race Item Filters - ✔RaceResult