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
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,089 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Randomize and actions #134157
06/06/07 02:21
06/06/07 02:21
Joined: Oct 2005
Posts: 131
C
CBSection31 Offline OP
Member
CBSection31  Offline OP
Member
C

Joined: Oct 2005
Posts: 131
Hey everyone,

I have several models next to each other in a level that all have the same action assigned to them. The action has a loop that calls for the model to move via c_move after a random period of time. I have set this up using the random command. I have randomize() set up properly (I think), so that the time before they move varies every loop.

So basically, it works something like this:

Code:

action lalala
{
var looptime;
while (1)
{
randomize();
looptime=int(random(100))+20;
wait(looptime); // wait between 20 and 120 ticks
c_move (blahblahblah);
}
}



The problem is, each model that has the action moves at the same time. So, each loop the value of looptime changes successfully. BUT, the value of looptime is the same for EVERY model assigned the action.

Is there a way for the value to be random for each model, even if they share the same action?

Thanks!

Last edited by CBSection31; 06/06/07 07:09.
Re: Randomize and actions [Re: CBSection31] #134158
06/06/07 03:41
06/06/07 03:41
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
...move it after the {. And also, wait(x); waits by frames, not ticks. use wait(-x); to wait seconds. ex: wait(-0.5); = wait half a second...

Code:

action lalala
{
var looptime;
while (1)
{
randomize();
looptime=int(random(100))+20;
wait(looptime); // wait between 20 and 120 ticks
c_move (blahblahblah);
}
}



Even better, use entity skills instead!

Code:

action lalala
{
while (1)
{
randomize();
my.skill1 = int(random(100))+20;
wait(-my.skill1); // wait between 20 and 120 ticks
c_move (blahblahblah);
}
}



Last edited by xXxGuitar511; 06/06/07 03:42.

xXxGuitar511
- Programmer
Re: Randomize and actions [Re: xXxGuitar511] #134159
06/06/07 07:24
06/06/07 07:24
Joined: Oct 2005
Posts: 131
C
CBSection31 Offline OP
Member
CBSection31  Offline OP
Member
C

Joined: Oct 2005
Posts: 131
Thanks for your fast reply!

I switched the variables over to entity skills. The other mistake was just a typo of mine in making this post. Unfortunately, all the entities still move at the same time.

It's like the same random number is used for EVERY model that has the action attached, instead of coming up with a random number for each individual model.

I'll go ahead and post the exact code I'm using, so that someone can give me an idea of how I'm screwing this up haha. The action is for small bugs that crawl around the level randomly.

Code:

action bugs
{
while (1)
{
randomize();
my.skill21=int(random(300))+200; // Random number of frames to wait before moving
my.skill20=0; // Counter for current frame of sanding
ent_animate(me,NULL,0,0);
while (my.skill20<my.skill21) // Is current frame less than total number of standing still frames?
{
ent_animate(my,"stand", my.skill48,anm_cycle); // play the "stand" frames animation
my.skill48 += 1 * time; // "stand" animation speed
my.skill48 %= 100; // loop animation
my.skill20+=1; // increase counter by one
wait (1);
}
my.skill22=0; //Counter for current frame of walking
ent_animate(me,NULL,0,0); // reset animation
while (my.skill22<20) // Is current frame less than total number of movement frames?
{
ent_animate(my, "walk",my.skill46,anm_cycle); // play the "walk" frames animation
my.skill46 += 12 * time; // "walk" animation speed
my.skill46 %= 100; // loop the animation
randomize();
temp.z -= 10000;
temp.z = -c_trace (my.x, temp.x, ignore_me | ignore_passable);
temp.x = int(-(random(4)));
temp.y = 0;
c_move (my, temp.x, nullvector, ignore_passable | glide); // move bug randomly along floor
randomize();
my.skill24=int(random(5))+1; // set random value to my.skill24 to determine if the bug should rotate
randomize();
my.skill23=int(random(179))+1; // set random value to my.skill25 to determine degree of bug rotation
if (my.skill24==1) // if my.skill24 is 1, then the bug will rotate clockwise
{
randomize();
c_rotate (my, vector((int(random(50))+1),0,0),ignore_passable); // rotate
}
if (my.skill24==2) // if my.skill24 is 2, then the bug will rotate counter-clockwise
{
randomize();
c_rotate (my, vector((-int(random(50))+1),0,0),ignore_passable); // rotate
}
my.skill22+=1; // increase counter by one
wait (10*time);
}
}

}



Last edited by CBSection31; 06/06/07 07:25.
Re: Randomize and actions [Re: CBSection31] #134160
06/06/07 14:30
06/06/07 14:30
Joined: Dec 2005
Posts: 252
MyOwnKingdom
nipx Offline
Member
nipx  Offline
Member

Joined: Dec 2005
Posts: 252
MyOwnKingdom
I dont know about your problem but you only have to call randomize() _once_.
Best would be at the startup.


nipx

Re: Randomize and actions [Re: nipx] #134161
06/06/07 17:33
06/06/07 17:33
Joined: Oct 2005
Posts: 131
C
CBSection31 Offline OP
Member
CBSection31  Offline OP
Member
C

Joined: Oct 2005
Posts: 131
^
Interestingly, that fixed the problem. Thank you very much!

Re: Randomize and actions [Re: CBSection31] #134162
06/06/07 18:23
06/06/07 18:23
Joined: Dec 2005
Posts: 252
MyOwnKingdom
nipx Offline
Member
nipx  Offline
Member

Joined: Dec 2005
Posts: 252
MyOwnKingdom
No problem.


I guess its because randomize() uses the GetTime (returns the time from booting till now in milliseconds) as you do in c. And all this actions start simultaneously, so they get the absolutely same time -> they are initalized with the same number -> return the same random number.

Just a little supposition, correct me if Im wrong


nipx


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