Cloaked Games
Member
I am working on some scripts for terrain generation, and I have some functions which include arguments for a random chance of one instance changing into another instance. For example: "jen_change_change(obj_dirt, obj_sand, 50)" would turn 50% (about) of the dirt into sand.
I was considering the possibility of the ability to add functions, such as sin(), into the argument for percent chance that depend on local variables within the script to create more advanced distributions. Here is the code:
For example, if I could put "(100*sin(xx/10))" in replacement of the variable "percent_chance", I could create a distribution of changed instances that looked like a repeated series of vertical bars. Or "random(random(xx))" which would create a horizontal gradient. This would greatly increase the flexibility of my functions.
I tried doing it with macros, defining a function such as:
(Please note, I literally learned about macros today because I thought they might work. My understanding is lacking I'm sure).
But the variable "xx" is not able to be pre-defined, as it's a temporary variable (var) to the script, and if I change it to an instance variable, I discovered that this code only runs it once when the variable percent_chance is defined. I have also considered passing script names through as the argument instead, but I don't expect this to be a feature used frequently, and I don't know if it's worth the extra effort to make it possible.
Any feedback on how to make it work with macros or scripts would be appreciated.
I was considering the possibility of the ability to add functions, such as sin(), into the argument for percent chance that depend on local variables within the script to create more advanced distributions. Here is the code:
Code:
//Iterate through entire jen_grid
for (var yy = 0; yy < height; yy ++) {
for (var xx = 0; xx < width; xx ++) {
//If the current value matches, it will change based on a certain chance
if (jen_grid[# xx, yy] == replace || replace == all)
{
//If the chance ends up true (a percentage)
if (random(100) <= percent_chance)
{
jen_grid[# xx, yy] = new_object;
}
}
} xx = 0; }
I tried doing it with macros, defining a function such as:
Code:
#macro function (100*sin(xx/10))
jen_change_change(obj_dirt, obj_sand, function)
But the variable "xx" is not able to be pre-defined, as it's a temporary variable (var) to the script, and if I change it to an instance variable, I discovered that this code only runs it once when the variable percent_chance is defined. I have also considered passing script names through as the argument instead, but I don't expect this to be a feature used frequently, and I don't know if it's worth the extra effort to make it possible.
Any feedback on how to make it work with macros or scripts would be appreciated.