Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 677 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
random moving #147122
08/10/07 18:57
08/10/07 18:57
Joined: Jul 2002
Posts: 857
Québec
Marky Mark Offline OP
User
Marky Mark  Offline OP
User

Joined: Jul 2002
Posts: 857
Québec
Hey,

I'd like to do a function that choose randomly a angle between 10 and 170 degrees, then move the entity into this way. Here's my plan:

function chooseway()
{
//choose a random direction
}

then in some entities actions that I want to follow the given directions,

action X
{
...
// move at X speed to the direction chosen by chooseway()
}

is this possible? Can someone help me coding my idea?
Thanks a lot !

Last edited by Marky Mark; 08/10/07 18:58.

Yeah! IE sucks, use Mozilla...
Marc Rémillard.
Re: random moving [Re: Marky Mark] #147123
08/10/07 21:00
08/10/07 21:00
Joined: Apr 2005
Posts: 67
InnerSpace
dudeBot Offline
Junior Member
dudeBot  Offline
Junior Member

Joined: Apr 2005
Posts: 67
InnerSpace
try using randomize() - 'Seeds' the random() sequence with a new random number.

and then random() - Returns a random number.

I dont think that you can set a numeric range, so to get an integer
between 10 and 170 here's what I'd do...

//newPanValue is set to a number beween 0 and 160
newPanValue = int(random(161));

//incrementing it by 10 will get you in your 10 to 170 range
newPanValue += 10;

Now you can set the pan of the entity to this value.

Re: random moving [Re: Marky Mark] #147124
08/10/07 21:15
08/10/07 21:15
Joined: Sep 2002
Posts: 700
Orange County, CA
L
LogantheHogan Offline
Developer
LogantheHogan  Offline
Developer
L

Joined: Sep 2002
Posts: 700
Orange County, CA
Yep. Dudebot is right. And then the rest:

Code:


function choose_way()
{
my.pan = random(160) + 10;
}


action X
{
randomize();
choose_way();
while(1)
{
temp.x = 5*time_step; // change 5 to whatever speed you want
temp.y = 0;
temp.z = 0;
c_move(me,temp,nullvector,null);
wait(1);
}
}



Hope that helps.

Re: random moving [Re: LogantheHogan] #147125
08/10/07 21:33
08/10/07 21:33
Joined: Jul 2002
Posts: 857
Québec
Marky Mark Offline OP
User
Marky Mark  Offline OP
User

Joined: Jul 2002
Posts: 857
Québec
But I want the result of choose_way() to be the same once called. Let's say I want the result in 4 actions, I can't use the way you showed cause the action is calling choose_way(), so if in my second action I call choose_way again, it will generate a new random number?


Yeah! IE sucks, use Mozilla...
Marc Rémillard.
Re: random moving [Re: Marky Mark] #147126
08/10/07 22:04
08/10/07 22:04
Joined: Sep 2002
Posts: 700
Orange County, CA
L
LogantheHogan Offline
Developer
LogantheHogan  Offline
Developer
L

Joined: Sep 2002
Posts: 700
Orange County, CA
Okay, I understand. In that case you'll just need to use a global variable. Let's call it picked_angle.

Code:

var picked_angle;

starter choose_way()
{
randomize();
picked_angle = random(160) + 10;
}

action X
{
while(picked_angle == 0) { wait(1); } // wait until choose_way has run
my.pan = picked_angle;
while(1)
{
temp.x = 5*time_step; // change 5 to whatever speed you want
temp.y = 0;
temp.z = 0;
c_move(me,temp,nullvector,null);
wait(1);
}
}



Now, all entities with action X attached will travel in the same (but random) direction.

Better?

EDIT: changed choose_way to a starter, and added WHILE at the beginning of X

Last edited by LogantheHogan; 08/10/07 22:07.
Re: random moving [Re: LogantheHogan] #147127
08/10/07 23:35
08/10/07 23:35
Joined: Jul 2002
Posts: 857
Québec
Marky Mark Offline OP
User
Marky Mark  Offline OP
User

Joined: Jul 2002
Posts: 857
Québec
Ok let's try it, it looks like working. I'll post back in some minutes


Yeah! IE sucks, use Mozilla...
Marc Rémillard.
Re: random moving [Re: Marky Mark] #147128
08/10/07 23:37
08/10/07 23:37
Joined: Jul 2002
Posts: 857
Québec
Marky Mark Offline OP
User
Marky Mark  Offline OP
User

Joined: Jul 2002
Posts: 857
Québec
Oh btw, Can I just store what you put inside the action into a function so it would be much more easy to work with? (1 line of code instead of 11 in each actions)

thanks


Yeah! IE sucks, use Mozilla...
Marc Rémillard.
Re: random moving [Re: Marky Mark] #147129
08/10/07 23:44
08/10/07 23:44
Joined: Jul 2002
Posts: 857
Québec
Marky Mark Offline OP
User
Marky Mark  Offline OP
User

Joined: Jul 2002
Posts: 857
Québec
Btw #2: It works I love you.


Yeah! IE sucks, use Mozilla...
Marc Rémillard.

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