Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (degenerate_762, Nymphodora), 1,012 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
random number generator #464624
03/01/17 20:57
03/01/17 20:57
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
I am trying to create a random number generator that will create a random number every time a dragon needs to decide what direction to run, once the player gets within a certain distance of it. Depending on what the random number that gets generated, the dragon will run to a certain vector location, once the player gets within a certain close distance to the dragon.

Here is the code I have to try and make this happen:

Code:
action dragon_action() 
{  
   ...

   rndmIntGenerator = integer(random(4)); // Generate random
      //    number between 0 to 3, and store it in variable.

   ...

   while (my.status != dead)
   {
      ...

      dragnPlyrDist = vec_dist (hero.x, my.x); // Distance in
         //    units between dragon and player.

      ...

      if(my.status == dragonBiteAttack) // Dragon tries to bite
         //    player.
      {
         ...

         if (dragnPlyrDist <= 200) // (Distance Between Dragon 
                                   //    and Player) <= 200
         {
            my.status = dragonRetreatFromPlayer; // Dragon
               //    retreats from player.
         }

         ...
      }

      if(my.status == dragonRetreatFromPlayer)
      {
         ent_animate(my, "walk", run_percentage, ANM_CYCLE); 
         run_percentage -= 6 * time_step;

         if(rndmIntGenerator == 0)
	 {
	    ent_moveto(me, vector(-3, -592, -103), 30);
               // If random number is 0, dragon moves to this
               //    vector location.
	 }
			
	 if(rndmIntGenerator == 1)
	 {
	    ent_moveto(me, vector(-599, 46, -103), 30);
               // If random number is 1, dragon moves to this
               //    vector location.
	 }
			
	 if(rndmIntGenerator == 2)
	 {
	    ent_moveto(me, vector(-54, 642, -103), 30);
               // If random number is 2, dragon moves to this
               //    vector location.
	 }
			
	 if(rndmIntGenerator == 3)
	 {
	    ent_moveto(me, vector(665, 57, -103), 30);
               // If random number is 3, dragon moves to this
               //    vector location.
	 }
      }
      
      ...
   }
}



The random number generator is generating a number, and the dragon moves to that number vector location, but the number never changes, when I continually move the player to within 200 units of it in the same game. The random number stays the same, and the dragon just keeps moving to the same spot, instead of a different spot every time I get the player to within 200 units of it. If I restart the game, then the random number generator will generate a new number again, but then it stays the same for the remainder of that game.

Does anyone have advice on how I can make it so that a random number gets generated each time the player gets to within 200 units of the dragon, in the same game? In other words, the random number can change each subsequent time the player gets to within 200 units of the dragon, instead of repeating the same value over and over, within the same game?

Any help would be appreciated. Thank you.

Last edited by Ruben; 03/01/17 21:00.
Re: random number generator [Re: Ruben] #464625
03/01/17 21:57
03/01/17 21:57
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Quote:
The random number generator is generating a number, and the dragon moves to that number vector location, but the number never changes


I will probably come across as a massive dick, but... You do realize that that's due to you never changing the variable ever?

Where you assign the `dragonRetreatFromPlayer` state, you can simply generate a new random number.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: random number generator [Re: WretchedSid] #464626
03/02/17 01:06
03/02/17 01:06
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
Originally Posted By: WretchedSid
Quote:
The random number generator is generating a number, and the dragon moves to that number vector location, but the number never changes


I will probably come across as a massive dick, but... You do realize that that's due to you never changing the variable ever?

Where you assign the `dragonRetreatFromPlayer` state, you can simply generate a new random number.

I tried that before. However, when I call the random number in the "dragonRetreatFromPlayer" state, and the player gets to within 200 units of the dragon, the dragon keeps continually trying to move to the different vector locations, just as if the random number is constantly being called and changed in real time, and the dragon is trying to follow the direction of the random number that keeps changing. The dragon never actually gets to a location. It just keeps wiggling here and there in the middle of the room without going anywhere.

Last edited by Ruben; 03/02/17 01:07.
Re: random number generator [Re: Ruben] #464627
03/02/17 03:18
03/02/17 03:18
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
I figured it out. I made each instance of the random number vector location into its own individual my.status. By doing that, once the random number is generated inside the "dragonRetreatFromPlayer" state, if it is any particular random number, it will make my.status equal the status of the individual vector location to travel. It therefore knocks out of the "dragonRetreatFromPlayer" state, and goes to the new my.state that tells the program to move the dragon to a particular location.


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