add ability to pick random value from array
(cherry picked from commit 9f4dbf415d)
Co-authored-by: BleedingXiko <66162192+BleedingXiko@users.noreply.github.com>
This commit is contained in:
committed by
Rémi Verschelde
parent
d80396db03
commit
eb5b297fef
@ -31,6 +31,7 @@
|
||||
#include "array.h"
|
||||
|
||||
#include "core/hashfuncs.h"
|
||||
#include "core/math/math_funcs.h"
|
||||
#include "core/object.h"
|
||||
#include "core/variant.h"
|
||||
#include "core/vector.h"
|
||||
@ -407,6 +408,10 @@ Variant Array::pop_front() {
|
||||
}
|
||||
return Variant();
|
||||
}
|
||||
Variant Array::pick_random() const {
|
||||
ERR_FAIL_COND_V_MSG(_p->array.size() == 0, Variant(), "Can't take value from empty array.");
|
||||
return operator[](Math::rand() % _p->array.size());
|
||||
}
|
||||
|
||||
Variant Array::pop_at(int p_pos) {
|
||||
if (_p->array.empty()) {
|
||||
|
||||
Reference in New Issue
Block a user