Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

 Is there an easy way to make random numbers? I don't think I found anything in the docs, the closest I got was "chance"....


In the end I made my own basic rand function  It's a bit rough and ready, but it seems to work, mostly. :)


 rand : subroutine {
     : set_integer var="rand_result" value="0";
     : if (chance(50) == true) {      

      : add var="rand_result" value="50";
      }
      : if (chance(50) == true) {
      : add var="rand_result" value="25";
      }
      : if (chance(50) == true) {
      : add var="rand_result" value="12";
      }
      : if (chance(50) == true) {    

             : add var="rand_result" value="6";
       }
      : if (chance(50) == true) {
      : add var="rand_result" value="3";
      }
      : if (chance(33)  == true) {
      : add var="rand_result" value="2";
      }
      : if (chance(33) == true) {
      : add var="rand_result" value="1";
      }
   }


:)

(+1)

Nice maths there. Anyway, it's a lot easier than all that.

random() will return a number between 0 and 99.

start_at = my_location
locations {
   my_location : location "Type <RANDOM<12>> to see the next random number." ;
} on_command {
   : match "random _"  {
      : print {("Random : " + random())}
   }
}

Ah, cool. thanks...  And I see an entry in the documentation now too! Super! I'll switch out my multiples-of-11-hating shonky random alg for something smoother :)

(+1)

random(n) would also be handy, but it's not there at the moment.

Another useful command is :execute_one_at_random{}. There's an example in the doco. I used this in combination with chance(n) to get the troll in 'Seeker of Magic' to do one of ten different things at random 30% of the time.