Next revision | Previous revisionNext revisionBoth sides next revision |
getcvarfixed [2018/01/08 01:12] – created korshun | getcvarfixed [2019/04/22 22:43] – korshun |
---|
====== GetCVarFixed ====== | ====== GetCVarFixed ====== |
| |
fixed a_GetCVarFixed(str name) | ZDoom provides [[zdoom>GetCVar]] for ints and [[zdoom>GetCVarString]] for strings, but doesn't provide a way to retrieve the value of ''float'' CVars. ACSUtils implements ''GetCVarFixed'' by calling [[zdoom>GetCVarString]] to retrieve the value of the CVar as a string, and parsing it with [[number_parsing#atof|atof]]. |
fixed a_GetUserCVarFixed(int player, str name) | |
| |
| <note important>If the CVar's value is outside the range of fixed-point numbers, the functions return ''32767.99997'', or ''-32768.0'', depending on the sign.</note> |
| |
| <note important>The function names begin with ''a_'' because [[GDCC]] defines its own broken ''GetCVarFixed'', which causes a compilation error if another function named ''GetCVarFixed'' exists.</note> |
| |
| <note tip>If you're not using [[GDCC]], you can remove the ''a_'' prefix by adding the following to your code: |
| <code> |
| function GetCVarFixed(str name) |
| { |
| return a_GetCVarFixed(name); |
| } |
| |
| function GetUserCVarFixed(int player, str name) |
| { |
| return a_GetUserCVarFixed(player, name); |
| } |
| </code> |
| </note> |
| |
| ===== Functions ===== |
| |
| ==== GetCVarFixed ==== |
| ''fixed a_GetCVarFixed(str name)'' |
| |
| Analogous to [[zdoom>GetCVar]] and [[zdoom>GetCVarString]]. |
| |
| ==== GetUserCVarFixed ==== |
| ''fixed a_GetUserCVarFixed(int player, str name)'' |
| |
| A version of ''GetCVarFixed'' for user CVars. Calls [[zdoom>GetCVarString]] internally instead of [[zdoom>GetCVar]]. Analogous to [[zdoom>GetUserCVar]] and [[zdoom>GetUserCVarString]]. |
| |
ZDoom doesn't provide a way to get a value of a ''float'' CVar as a fixed-point number. | |
| |
''GetCVarFixed'' and ''GetUserCVarFixed'' are implemented by using [[zdoom>GetCVarString]] and [[zdoom>GetUserCVarString]] to get the value as a string and converting it into a fixed-point number using [[number parsing]] functions. | |
| |
<note important>The functions have an ''a_'' prefix, because [[GDCC]] has its own unrelated ''GetCVarFixed''.</note> | |