6 registered members (AndrewAMD, Ayumi, degenerate_762, 7th_zorro, VoroneTZ, HoopyDerFrood),
1,268
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
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
Expert
|
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
Expert
|
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
Last edited by Kartoffel; 10/11/12 20:00.
POTATO-MAN saves the day! - Random
|
|
|
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
Expert
|
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: Realspawn]
#409131
10/11/12 22:58
10/11/12 22:58
|
Joined: Sep 2007
Posts: 101 Luxembourg
krial057
Member
|
Member
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)
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)
|
|
|
|