Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 835 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 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: 108
G
gamers Offline OP
Member
gamers  Offline OP
Member
G

Joined: Jan 2012
Posts: 108
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,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
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: 108
G
gamers Offline OP
Member
gamers  Offline OP
Member
G

Joined: Jan 2012
Posts: 108
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: 108
G
gamers Offline OP
Member
gamers  Offline OP
Member
G

Joined: Jan 2012
Posts: 108
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: 619
Turkey, Izmir
Emre Offline
User
Emre  Offline
User

Joined: Jul 2007
Posts: 619
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: 108
G
gamers Offline OP
Member
gamers  Offline OP
Member
G

Joined: Jan 2012
Posts: 108
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