Gamestudio Links
Zorro Links
Newest Posts
Zorro S for Oanda US
by AndrewAMD. 06/06/20 16:39
The Black Book
by SteveG. 06/06/20 14:01
Indicator coding
by danatrader. 06/06/20 11:53
New AUM
by Aku_Aku. 06/06/20 10:10
Reading a TXT file on server
by Truth. 06/05/20 18:22
Oanda instruments
by Morris. 06/05/20 10:24
AUM Magazine
Latest Screens
The Space Between
Pogostuck: Rage With Your Friends
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Who's Online Now
4 registered members (AndrewAMD, SteveG, kalmar, Grat), 472 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Frank_Shieh, PBSeven, Hardi01, Giuseppe, AdamWu
18461 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: 76
G
gamers Offline OP
Junior Member
gamers  Offline OP
Junior Member
G

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

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

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

Joined: Jan 2012
Posts: 76
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: 563
Turkey, izmir
Emre Offline
User
Emre  Offline
User

Joined: Jul 2007
Posts: 563
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: 76
G
gamers Offline OP
Junior Member
gamers  Offline OP
Junior Member
G

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