From d52d3b7ef1dee1737d806a920518b50b81f206b3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 29 Nov 2024 05:19:40 +0000 Subject: [PATCH 1/2] Bump System.Text.Json from 8.0.4 to 8.0.5 in /YarnSpinner.Compiler Bumps [System.Text.Json](https://github.com/dotnet/runtime) from 8.0.4 to 8.0.5. - [Release notes](https://github.com/dotnet/runtime/releases) - [Commits](https://github.com/dotnet/runtime/compare/v8.0.4...v8.0.5) --- updated-dependencies: - dependency-name: System.Text.Json dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- YarnSpinner.Compiler/YarnSpinner.Compiler.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/YarnSpinner.Compiler/YarnSpinner.Compiler.csproj b/YarnSpinner.Compiler/YarnSpinner.Compiler.csproj index 41b141af7..edf444524 100644 --- a/YarnSpinner.Compiler/YarnSpinner.Compiler.csproj +++ b/YarnSpinner.Compiler/YarnSpinner.Compiler.csproj @@ -23,7 +23,7 @@ This package provides support for compiling Yarn source code, so that you can ex - + From 0fca50fb3223038d350a3859acc3b4c059cc96f6 Mon Sep 17 00:00:00 2001 From: Jon Manning Date: Fri, 13 Dec 2024 10:58:20 +1100 Subject: [PATCH 2/2] Add random_range_float; make random_range consistent with YS3's behaviour. Fixes #389. --- CHANGELOG.md | 3 +++ YarnSpinner/Dialogue.cs | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4886a7796..a52c27641 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed +- `random_range(min, max)` now returns a random integer between `min` and `max`, inclusive. (Previously, it returned a float.) +- Added a new function, `random_range_float` now returns a random float between `min` and `max`, inclusive. (This is the previous behaviour of `random_range`.) + ### Removed ## [2.4.2] 2024-02-24 diff --git a/YarnSpinner/Dialogue.cs b/YarnSpinner/Dialogue.cs index fe45b7ac9..fa71c19b3 100644 --- a/YarnSpinner/Dialogue.cs +++ b/YarnSpinner/Dialogue.cs @@ -1142,7 +1142,12 @@ public StandardLibrary() return Random.NextDouble(); }); - this.RegisterFunction("random_range", delegate (float minInclusive, float maxInclusive) + this.RegisterFunction("random_range", (float min, float max) => + { + return Random.Next((int)max - (int)min + 1) + min; + }); + + this.RegisterFunction("random_range_float", delegate (float minInclusive, float maxInclusive) { var t = Random.NextDouble(); return minInclusive + t * (maxInclusive - minInclusive);