Skip to content

Commit 0c4951a

Browse files
committed
Update docs
1 parent aca6b9a commit 0c4951a

File tree

3 files changed

+74
-7
lines changed

3 files changed

+74
-7
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@
99
* `_uniq`
1010
* `_contains`
1111
* Bug fixes and behavior alignment for `_contains`
12-
* New script: `_to_list(array)`
12+
* `_keys` now returns an empty array for empty maps
13+
* New scripts:
14+
* `_to_list(array)`
15+
* `_list_of(values...)`
16+
* `_map_of(values...)`
17+
* `_error(message [, fatal])`
1318
* Documentation is now generated directly from code comments in the source

README.md

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ gdash is a functional utility library for GML, inspired by [lodash](https://loda
1919
* [`_concat(arrayA, arrayB)`](#_concatarraya-arrayb)
2020
* [`_contains(collection, target [, fromIndex, dsType])`](#_containscollection-target--fromindex-dstype)
2121
* [`_destroy(object)`](#_destroyobject)
22+
* [`_error(message [, fatal])`](#_errormessage--fatal)
2223
* [`_filter(collection, script)`](#_filtercollection-script)
2324
* [`_find(array, findScript)`](#_findarray-findscript)
2425
* [`_free(id [, ds_type])`](#_freeid--ds_type)
@@ -28,7 +29,9 @@ gdash is a functional utility library for GML, inspired by [lodash](https://loda
2829
* [`_join(array, joinChar)`](#_joinarray-joinchar)
2930
* [`_keys(map)`](#_keysmap)
3031
* [`_length(collectionOrString)`](#_lengthcollectionorstring)
32+
* [`_list_of(values...)`](#_list_ofvalues)
3133
* [`_log(values...)`](#_logvalues)
34+
* [`_map_of(values...)`](#_map_ofvalues)
3235
* [`_map(collection, script [, ds_type])`](#_mapcollection-script--ds_type)
3336
* [`_nth(collection, index)`](#_nthcollection-index)
3437
* [`_or(valueA, valueB)`](#_orvaluea-valueb)
@@ -141,7 +144,7 @@ _concat([0, 1, 2], [3, 4, 5]);
141144
142145
### `_contains(collection, target [, fromIndex, dsType])`
143146
144-
Returns true if the given array contains the given value
147+
Returns true if the given array contains the given value, otherwise returns false
145148
146149
```gml
147150
@param {String|Array|DS_Map|DS_List} collection The collection to search
@@ -176,6 +179,22 @@ _destroy(obj_enemy);
176179
_map(_filter(_collect(obj_enemy)), hasNoHealth), _destroy);
177180
```
178181
182+
### `_error(message [, fatal])`
183+
184+
When running with the debugger, displays an error window. Otherwise, logs an error using `_log`.
185+
186+
> *Note*: Only mark an error as `fatal` if you are okay with it ending your game
187+
188+
```gml
189+
@param {String} message The message to error with
190+
@param {Boolean} fatal [Optional] If true, will force a show_error() call with `abort` set to true
191+
192+
@example
193+
_error("This is an error that will let the game continue");
194+
_error("This is an error that will let the game continue", false);
195+
_error("This is an error that will kill the game", true);
196+
```
197+
179198
### `_filter(collection, script)`
180199

181200
Returns a collection where values of the input collection are truthy when run through the provided function.
@@ -336,12 +355,52 @@ _length(some_list_id_of_size_5);
336355
// => 5
337356
```
338357
358+
### `_list_of(values...)`
359+
360+
Returns a DS_List containing the provided values. This DS_List should be destroyed as you would any other DS.
361+
362+
```gml
363+
@param {*} values... As many starting values for the list as desired
364+
365+
@returns {DS_List} A new DS_List containing the provided values
366+
367+
@example
368+
369+
var list = _list_of(1, 2, 3, 4);
370+
_log(list[| 2]) // logs 3
371+
```
372+
339373
### `_log(values...)`
340374

341375
Convenience method for show_debug_message(). Automatically convetrs arguments to strings.
342376

343377
```gml
344-
@param {Mixed} Message The message or value to log
378+
@param {Mixed} Messages... The message or value to log
379+
380+
```
381+
382+
### `_map_of(values...)`
383+
384+
Returns a DS_Map containing the provided values. Arguments are split into key/value pairs in the order they are provided.
385+
386+
> *Note*: This script must take an even number of arguments. Keys can only be integers or strings.
387+
388+
```gml
389+
@param {*} values... As many starting values for the map as desired
390+
391+
@returns {DS_Map} A new DS_Map containing the provided key/value pairs
392+
393+
@example
394+
395+
var map = _map_of(
396+
"health", 100,
397+
"mana", 20,
398+
"level", 1
399+
);
400+
401+
map[? "health"] // = 100
402+
map[? "mana"] // = 20
403+
map[? "level"] // = 1
345404
346405
```
347406

@@ -445,11 +504,12 @@ _push([1, 2], 3);
445504
446505
### `_reduce(collection, reducer)`
447506
448-
Reduces a collection by iterating over it with a function. Provided script should take 2 arguments: total, value. On the first call, total is undefined.
507+
Reduces a collection by iterating over it with a function. Provided script should take 2 arguments: total, value.
449508
450509
```gml
451510
@param {Array|ds_list} collection The collection to reduce
452511
@param {Script} recuderScript The script to reduce with
512+
@param {*} value [Optional] The default value to begin reducing with. If not provided, the default is `undefined`
453513
454514
@returns {*} The reduced value from the given script
455515
@@ -617,7 +677,9 @@ list[| 2]; // 10
617677

618678
### `_type_of(value)`
619679

620-
Returns the variable type of the given argument
680+
Returns the variable type of the given argument as a string.
681+
682+
> *Note*: Works exactly as the native typeof(), though refers to `number` as `real` to be more consistent with GM:S terminology
621683
622684
```gml
623685
@param {*} value A variable to check the type of
@@ -641,7 +703,7 @@ _type_of(undefined);
641703
// => "undefined";
642704

643705
_type_of(sprite_get_texture(spr_player, 1));
644-
// => "pointer";
706+
// => "ptr";
645707
```
646708
647709
### `_uniq(array)`

src/scripts/_error/_error.gml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// @func _error(message [, fatal])
2-
/// @desc When running with the debugger, displays an error window. Otherwise, logs an error using _log.
2+
/// @desc When running with the debugger, displays an error window. Otherwise, logs an error using `_log`.
33
/// @param {String} message The message to error with
44
/// @param {Boolean} fatal [Optional] If true, will force a show_error() call with `abort` set to true
55
/// @note Only mark an error as `fatal` if you are okay with it ending your game

0 commit comments

Comments
 (0)