User Tools

Site Tools


en:tutorials:config_stepped_random_values

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

en:tutorials:config_stepped_random_values [2019/03/07 02:21 (7 months ago)] (current)
sausage created
Line 1: Line 1:
 +====== Getting Stepped Random Values from Config ======
 +
 +You would be familiar with retrieving a random value from the config by writing:
 +
 +<code ini>
 +[Values]
 +Randoms = 0 ~ 1999
 +</​code>​
 +
 +And in code:
 +
 +<code c>
 +if (orxConfig_PushSection("​Values"​)){
 + orxU32 value = orxConfig_GetU32("​Randoms"​);​
 + orxLOG ("​Value:​ %d", value);
 +
 + orxConfig_PopSection();​
 +}
 +</​code>​
 +
 +This will give you a random number, eg:
 +
 +   ​Value:​ 1675
 +
 +
 +===== Stepped Integers =====
 +
 +You can also define **stepped** random values using the following format:
 +
 +<code ini>
 +[Values]
 +Angles = 0 ~ 45 ~ 360
 +</​code>​
 +
 +<code c>
 +orxU32 value = orxConfig_GetU32("​Angles"​);​
 +</​code>​
 +
 +   ​Value:​ 270
 +
 +In the example above, ''​0 ~ 45 ~ 360''​ would mean to define a range of values between 0 and 360, 45 steps apart.
 +
 +Other examples would be:
 +
 +   0 ~ 1 ~ 10  (standard number range of 1 to 10, steps of 1)
 +   0 ~ 1 ~ 1   (like a binary switch 0 or 1, same as 0 ~ 1)
 +   1 ~ 5 ~ 100 (1 to 100 in steps of 5)
 +   0 ~ 2 ~ 10  (an even number between 0 to 10)
 +
 +
 +===== Code examples =====
 +
 +You can also do this from code using any of the following functions:
 +
 +  - ''​orxMath_GetSteppedRandomFloat''​
 +  - ''​orxMath_GetSteppedRandomU32''​
 +  - ''​orxMath_GetSteppedRandomS32''​
 +  - ''​orxMath_GetSteppedRandomU64''​
 +  - ''​orxMath_GetSteppedRandomS64''​
 +
 +An example:
 +
 +<code c>
 +orxFLOAT val = orxMath_GetSteppedRandomFloat(1,​ 100, 2.1);
 +orxLOG ("​Value:​ %f", val);
 +</​code>​
 +
 +   ​11.50000
 +
 +So the above would be floats 1 to 100 in steps of 2.1. You can get more details about those functions here: http://​orx-project.org/​orx/​doc/​html/​group__orx_math.html
 +
 +
 +===== Stepped Vectors =====
 +
 +A little tricker, but the same nonetheless:​
 +
 +<code ini>
 +[Values]
 +MyRandomVector = (1, 3, 5) ~ (0, 0.1) ~ (2, 4, 6)
 +</​code>​
 +
 +  * X will be unconstrained between 1 and 2 (step = 0)
 +  * Y will be between 3 and 4 with a step of 0.1 and;
 +  * Z will be unconstrained between 5 and 6 (no Z component, which means: Z = 0)
 +
 +
 +===== More details =====
 +
 +You can get more detail and examples in the Creation Template [[https://​github.com/​orx/​orx/​blob/​master/​code/​bin/​CreationTemplate.ini|here]] or in your local repo of Orx.
  
en/tutorials/config_stepped_random_values.txt ยท Last modified: 2019/03/07 02:21 (7 months ago) by sausage