FP.choose() problem?


(Bora Kasap) #1

I’ve using FP.choose() function inside the update function of the main World class file, but it works only 1 time for each level;

FP.choose(STORE.needabrain.play(), STORE.needabrainstorm.play(), STORE.whatthefuckareyoudoing.play(), STORE.youlooktiredsir.play());

but every time it is returning the first value, what is the problem?


(Justin Wolf) #2

Try this:

FP.choose(STORE.needabrain.play, STORE.needabrainstorm.play,
STORE.whatthefuckareyoudoing.play, STORE.youlooktiredsir.play)();

You can use FP.choose on functions that require parameters as well:

FP.choose(myFunction0, myFunction1)("Function Parameter 1", 1, new Point(x, y));


(azrafe7) #3

Was going to post the same thing as @justinwolf.

Well, I’ll add a little explaination to that:

  • in @AlobarNon version each function will be called, and their respective result values will then be passed to FP.choose()
  • in @justinwolf version FP.choose will select a random Function first, and then call it

You can easily check that by running this little snippet and see what it traces out:

	var f1:Function = function():int { trace(1); return 1; };
	var f2:Function = function():int { trace(2); return 2; };
	var f3:Function = function():int { trace(3); return 3; };
			
	trace("AlobarNon:");
	trace("choose:", FP.choose(f1(), f2(), f3()));

	trace("justinwolf:");
	trace("choose:", FP.choose(f1, f2, f3)());

(Bora Kasap) #4

Thanks so much :smiley: Next time i’ll use it like that, i think i got it now…