Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Ayumi), 1,266 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
pick a random function. #409112
10/11/12 19:56
10/11/12 19:56
Joined: Jul 2001
Posts: 4,801
netherlands
Realspawn Offline OP

Expert
Realspawn  Offline OP

Expert

Joined: Jul 2001
Posts: 4,801
netherlands
I have made several functions. say function 1 2 3
How can i activate a random function on a key press ?

thx for you time laugh


Find all my tutorials & Workshops at : www.rp-interactive.nl

Creativity starts in the brain
Re: pick a random function. [Re: Realspawn] #409113
10/11/12 19:57
10/11/12 19:57
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: pick a random function. [Re: Realspawn] #409114
10/11/12 19:58
10/11/12 19:58
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
you can use function-pointer-arrays and use a random integer as index number when calling it.

I'm sorry, I'm not sure how it exactly works but it should.

EDIT: JustSid was faster, and his solution might be the better one wink

Last edited by Kartoffel; 10/11/12 20:00.

POTATO-MAN saves the day! - Random
Re: pick a random function. [Re: Kartoffel] #409119
10/11/12 20:17
10/11/12 20:17
Joined: Jul 2001
Posts: 4,801
netherlands
Realspawn Offline OP

Expert
Realspawn  Offline OP

Expert

Joined: Jul 2001
Posts: 4,801
netherlands
justsids answer in the words i allready found but not really know how to use them yet wink

Last edited by Realspawn; 10/11/12 20:17.

Find all my tutorials & Workshops at : www.rp-interactive.nl

Creativity starts in the brain
Re: pick a random function. [Re: Kartoffel] #409120
10/11/12 20:19
10/11/12 20:19
Joined: Aug 2012
Posts: 14
Aquilis Offline
Newbie
Aquilis  Offline
Newbie

Joined: Aug 2012
Posts: 14
Code:
function execute_random()
{
var execute=integer(random(3));
switch (execute)
{
case 0:
function_1();
break;
case 1:
function_2();
break;
case 2:
function_3();
break;
}
}

on_f=execute_random;



Last edited by Aquilis; 10/11/12 20:31.
Re: pick a random function. [Re: Realspawn] #409121
10/11/12 20:21
10/11/12 20:21
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
Espér Offline
Expert
Espér  Offline
Expert

Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
Code:
var randofunc = 0;

....

randofunc = random(3);
if(randofunc > 2)
{function_a();}
else if(randofunc > 1)
{function_b();}
if(randofunc < 1)
{function_c();}



Selling my Acknex Engine Editions (A7 Com & A8 Pro):
>> click here if you are interested <<
Re: pick a random function. [Re: Aquilis] #409122
10/11/12 20:23
10/11/12 20:23
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
@ Aquilis

will this work? because if execute == 1.534 case 1 won't work, will it?

don't you have to use switch(integer(execute(3) + 1)) to have a random integer between 1 and 3?

Last edited by Kartoffel; 10/11/12 20:24.

POTATO-MAN saves the day! - Random
Re: pick a random function. [Re: Kartoffel] #409123
10/11/12 20:27
10/11/12 20:27
Joined: Aug 2012
Posts: 14
Aquilis Offline
Newbie
Aquilis  Offline
Newbie

Joined: Aug 2012
Posts: 14
@Kartoffel, yes you are right. It should be var execute=integer(random(3));

I changed my post above. It should work fine now.

Re: pick a random function. [Re: Aquilis] #409125
10/11/12 21:34
10/11/12 21:34
Joined: Jul 2001
Posts: 4,801
netherlands
Realspawn Offline OP

Expert
Realspawn  Offline OP

Expert

Joined: Jul 2001
Posts: 4,801
netherlands
Aquilis you rock laugh thank you for this laugh

i'll make sure it will be used in future workshops for my site laugh


Find all my tutorials & Workshops at : www.rp-interactive.nl

Creativity starts in the brain
Re: pick a random function. [Re: Realspawn] #409131
10/11/12 22:58
10/11/12 22:58
Joined: Sep 2007
Posts: 101
Luxembourg
K
krial057 Offline
Member
krial057  Offline
Member
K

Joined: Sep 2007
Posts: 101
Luxembourg
Other solution if functions are indexed(probably not as effective, but easier to implement(no need to add functions to a switch)

Code:
void quest_1();
void quest_2();
void quest_3();

void execute_random(STRING* funcprefix, int count)
{
	void myfunc();
	if(myfunc = engine_getscript(_chr(str_cat(_str(funcprefix),str_for_num(NULL, (int)random(count)+1)))))
		myfunc();
	else
	 printf("There is missing an indexed function...");
}

int main()
{
	random_seed(0);
	execute_random("quest_", 3);
	return 0;
}



(sorry, was in a compressive mood :P)

Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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