Gamestudio Links
Zorro Links
Newest Posts
Sortino(vars Data, int TimePeriod): var
by danatrader. 11/26/20 20:45
Need code for Williams Sentiment Index
by danatrader. 11/26/20 20:42
Binance Futures Plugin
by Mio. 11/26/20 10:54
Optimizing global & local parameters
by dBc. 11/25/20 15:16
Enter FOK orders simultaneously
by jcl. 11/25/20 10:55
looking how basic functions are made
by jcl. 11/25/20 10:47
IB TWS and IB api live data inaccuracy
by marr. 11/24/20 10:03
AUM Magazine
Latest Screens
Paradox Vector
The Space Between
Pogostuck: Rage With Your Friends
Worst Case Z
Who's Online Now
5 registered members (alibaba, danatrader, Quad, ozgur, 1 invisible), 491 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
MMK, raed, liquidbread, Dmitry_Shesterin, ddczp
18543 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Random Functions? #479407
03/27/20 10:56
03/27/20 10:56
Joined: Jan 2012
Posts: 79
G
gamers Offline OP
Junior Member
gamers  Offline OP
Junior Member
G

Joined: Jan 2012
Posts: 79
Hi guys,
There are two different functions in my project that I want to use. How do I get these two different functions to be displayed to the user 15 times and randomly.
So I would like to present a set of these two functions to users 15 times.
For example, one function is A and the other is B. I want to present the A and B functions to the user randomly 15 times.
How can I do that (i.e, "A, A, B, B, B, A, B, A, B, A, A, A, B, B, A" - OR - "B, A, B, A, B, B, B, A, A, A, B, A, B, B, B")
Thanks for your support.
Regards,

Re: Random Functions? [Re: gamers] #479409
03/27/20 12:28
03/27/20 12:28
Joined: Jun 2007
Posts: 1,334
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,334
Hiporope and its pain
Hi,
something like this?
Code
var _i = 0;
for(; _i < 15; _i += 1) {
   if(random(1) < 0.5)
      A();
   else
      B();
}

Re: Random Functions? [Re: txesmi] #479432
03/29/20 07:59
03/29/20 07:59
Joined: Jan 2012
Posts: 79
G
gamers Offline OP
Junior Member
gamers  Offline OP
Junior Member
G

Joined: Jan 2012
Posts: 79
Thank you very much @txesmi, I will try this..

Originally Posted by txesmi
Hi,
something like this?
Code
var _i = 0;
for(; _i < 15; _i += 1) {
   if(random(1) < 0.5)
      A();
   else
      B();
}

Re: Random Functions? [Re: gamers] #479465
03/31/20 12:08
03/31/20 12:08
Joined: Jan 2012
Posts: 79
G
gamers Offline OP
Junior Member
gamers  Offline OP
Junior Member
G

Joined: Jan 2012
Posts: 79
I tried using different functions by assigning this code to a key (i.e., space), but I can use it more than 15 times. Is there another way to limit it to 15?

Re: Random Functions? [Re: gamers] #479466
03/31/20 12:32
03/31/20 12:32
Joined: Jul 2007
Posts: 581
Turkey, izmir
Emre Offline
User
Emre  Offline
User

Joined: Jul 2007
Posts: 581
Turkey, izmir
You should declare the variable "_i" as a global variable.

Code

var _i=0; //global var

function on_space_event()
{
	for(; _i < 15; _i += 1) {
		if(random(1) < 0.5)
		A();
		else
		B();
	}
}


and if you want just one function to work each time you press the key, you don't need to use "for" loop. Something like this works:

Code
var _i=0;

function on_space_event()
{
	_i+=1;
	if( _i>15)
	{
		return;
	}

	if(random(1) < 0.5)
	A();
	else
	B();
}
}

Re: Random Functions? [Re: Emre] #479481
04/02/20 09:01
04/02/20 09:01
Joined: Jan 2012
Posts: 79
G
gamers Offline OP
Junior Member
gamers  Offline OP
Junior Member
G

Joined: Jan 2012
Posts: 79
Originally Posted by Emre
You should declare the variable "_i" as a global variable.

Code

var _i=0; //global var

function on_space_event()
{
	for(; _i < 15; _i += 1) {
		if(random(1) < 0.5)
		A();
		else
		B();
	}
}


and if you want just one function to work each time you press the key, you don't need to use "for" loop. Something like this works:

Code
var _i=0;

function on_space_event()
{
	_i+=1;
	if( _i>15)
	{
		return;
	}

	if(random(1) < 0.5)
	A();
	else
	B();
}
}


Thank you @Emre, I think that's exactly what I want!


Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1