Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FlxRandom.getObject() does not respect startIndex #2009

Closed
Poobslag opened this issue Dec 5, 2016 · 5 comments
Closed

FlxRandom.getObject() does not respect startIndex #2009

Poobslag opened this issue Dec 5, 2016 · 5 comments

Comments

@Poobslag
Copy link

Poobslag commented Dec 5, 2016

  • Flixel version: 4.1.1

FlxRandom.getObject does not respect the startIndex. If you specify a startIndex of 3, for example, FlxRandom.getObject will still return array items with starting indexes below 3.


Code snippet reproducing the issue:

package;

import flixel.FlxG;
import flixel.FlxState;
import flixel.text.FlxText;

class PlayState extends FlxState
{
	override public function create():Void
	{
		var s:String = "";
		for (i in 0...10) {
			s += FlxG.random.getObject(["x", "y", "z", "e", "e"], null, 3, 4);
		}
		add(new FlxText(0, 0, 0, "Have a d" + s + "lightful day"));
	}
}

Observed behavior:
"Have a dxxxyyyyxxxlightful day" is printed, FlxG.random.getObject returns random array items with index [0, 1].

Expected behavior:

"Have a deeeeeeeeeelightful day" should be printed. FlxG.random.getObject should return random array items with index [3, 4].

@Beeblerox
Copy link
Member

i guess that the line https://github.com/HaxeFlixel/flixel/blob/dev/flixel/math/FlxRandom.hx#L292
selected = Objects[weightedPick(_arrayFloatHelper)];
should be changed to
selected = Objects[StartIndex + weightedPick(_arrayFloatHelper)];

@Beeblerox
Copy link
Member

Beeblerox commented Dec 5, 2016

@Poobslag i've commited this change (f7c2991), could you check if the issue is gone?

@Poobslag
Copy link
Author

Poobslag commented Dec 5, 2016

Yeah, looks like that change fixes the issue. Thanks!

@Beeblerox
Copy link
Member

@Poobslag can we close this issue then?

@Poobslag Poobslag closed this as completed Dec 5, 2016
@MSGhero
Copy link
Member

MSGhero commented Dec 5, 2016

Unit test 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants