Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Moox on Mon 14/06/2004 23:01:41

Title: Suggestion: Random (min int, max int) (SOLVED)
Post by: Moox on Mon 14/06/2004 23:01:41
Well I am taking time off from my game to port one of my old basic games into ags . One key feature is a random dungeon generator. I want to have a random forest dungeon, mine dungeon, etc...
To accomplish this their needs to be both a minimum and a maximum so I can set the range between the backgrounds, perhaps 1-20 are forest 20-40 are cave. I need random number between 20-40 for a cave. One possible work around would be something like If int is between 0-20 then redo random. But a script like that could be kinda slow and time consuming to add to every room. Could you add a min range to random please cj
Title: Re: Suggestion: Random (min int, max int);
Post by: on Mon 14/06/2004 23:14:19
Random(20) + 20

gives you the same effect
Title: Re: Suggestion: Random (min int, max int);
Post by: strazer on Mon 14/06/2004 23:18:48
You can define your own custom function:

Global script

function RandomEx(int min, int max) { return (min + Random(max-min)); }

Script header (so you can use it outside the global script, ie in rooms)

import function RandomEx(int min, int max);
Title: Re: Suggestion: Random (min int, max int);
Post by: Moox on Mon 14/06/2004 23:35:52
I didnt know that was possible, thanks