random music

OK. I got a problem with rand and I'm confused what number to input. I'm trying to make the other song play. I know it sometimes plays but it seems that one of follows (1 & 2) plays and then reverts back to anim idle instead of going to follow3. I like it to play. Please don't mind the delays. Please mind this r > or < for follow3. Is there something I'm doing wrong? I added follow3 for another music.

Code:
name      Randommusic
type      none

anim idle
@script
    if(frame==1){
      playmusic("data/music/ken.ogg", 1);
    }
    if(frame==2){
      void self = getlocalvar("self");
      int r = rand()%30;

      if( r > 10 ){
        changeentityproperty(self, "animation", openborconstant("ANI_FOLLOW1"));
      } else if( r < -10 ){
        changeentityproperty(self, "animation", openborconstant("ANI_FOLLOW2"));
      } else if( r > 15 ){
	changeentityproperty(self, "animation", openborconstant("ANI_FOLLOW3"));
      }
    }
@end_script
   loop   1
   delay   1
   offset   1 1
   frame   data/chars/misc/empty.gif
   delay   1000 #delay 6000 is 1 minute; 100 centiseconds is 1 second;
   frame   data/chars/misc/empty.gif
   delay   1
   frame   data/chars/misc/empty.gif

anim follow1
@script
    if(frame==1){
      playmusic("data/music/bison.ogg", 1);
    }
    if(frame==2){
      void self = getlocalvar("self");
      int r = rand()%30;

      if( r > 10 ){
        setidle(self, openborconstant("ANI_IDLE"));
      } else if( r < -10 ){
        changeentityproperty(self, "animation", openborconstant("ANI_FOLLOW2"));
      } else if( r > 15){
	changeentityproperty(self, "animation", openborconstant("ANI_FOLLOW3"));
      }
    }
@end_script
   loop   1
   delay   1
   offset   1 1
   frame   data/chars/misc/empty.gif
   delay   1000
   frame   data/chars/misc/empty.gif
   delay   1
   frame   data/chars/misc/empty.gif

anim follow2
@script
    if(frame==1){
      playmusic("data/music/ryu.ogg", 1);
    }
    if(frame==2){
      void self = getlocalvar("self");
      int r = rand()%30;

      if( r > 10 ){
        changeentityproperty(self, "animation", openborconstant("ANI_FOLLOW1"));
      } else if( r < -10 ){
        setidle(self, openborconstant("ANI_IDLE"));
      } else if( r > 15 ){
	changeentityproperty(self, "animation", openborconstant("ANI_FOLLOW3"));
      }
    }
@end_script
   loop   1
   delay   1
   offset   1 1
   frame   data/chars/misc/empty.gif
   delay   1000
   frame   data/chars/misc/empty.gif
   delay   1
   frame   data/chars/misc/empty.gif


anim follow3
@script
    if(frame==1){
      playmusic("data/music/cody1.ogg", 1);
    }
    if(frame==2){
      void self = getlocalvar("self");
      int r = rand()%30;

      if( r > 10 ){
        changeentityproperty(self, "animation", openborconstant("ANI_FOLLOW1"));
      } else if( r < -10 ){
        setidle(self, openborconstant("ANI_IDLE"));
      } else if( r > 15 ) {
	changeentityproperty(self, "animation", openborconstant("ANI_FOLLOW2"));
      }
    }
@end_script
   loop   1
   delay   1
   offset   1 1
   frame   data/chars/misc/empty.gif
   delay   17000
   frame   data/chars/misc/empty.gif
   delay   1
   frame   data/chars/misc/empty.gif
 
Damon Caskey said:
Default is valid in OpenBOR.

DC

Thanks for the explanation.

@maxman:
t's great that I don't have to be an expert on C programming for working on C based stuff for OpenBOR, so I cannot be too hyped or excited about it with no skill. Anyone with any level can do this especially those with lower level. I never learned scripts before, but since I'm learning scripts, it is very interesting to do.

I am not THAT super programmer, but I learned that you need to learn the programming Logic first. Then when you understand it, to apply it for some language is way easier. And C shares many aspects with other languages, like PHP. So its good for your real life too :)

int r = rand()%30 means 61 values, ranging from -30 to 30 (including 0).Your triggers are wrong, take a look:

a) r>10 = from 11 to 30
b) r< -10 = from -30 to -11
c) r>15 = from 16 to 30

1- There are no covered values (like from -9 to 10). The code will do nothing if the random is equal to those values.
2- There are overlapping values. The triggers A (r>10) and C (r>15) will works on values from 16 to 30. And since the code is read from top to bottom, once the first trigger is valid, the code changes FOLLOW1 and never to FOLLOW3. IOW once the first trigger is valid, the code executes it.
 
Ah you're right Ilu, I forgot that this script is to play random music after playing one music

Anyways maxman, if you want to expand the script to play more randomized music, you can replace it with switch and case you posted above. I can't give specific script for you since I don't know how many music files you are going to randomize
 
Back
Top Bottom