Script to change °C into Fahrenheit?
Sebastian2203
25 Oct 2016, 17:44In my game, the temperatures are randomly generated and ignoring the fact that it would be tremendous effort to manually convert every °C into Fahrenheit is just madness, that´s why I ask you, dear forum dwellers;
Is there any way to make Quest calculate, simply, convert °C into Fahrenheit?
To avoid confusion, I am using gamebook not text-adventures.
Pykrete
25 Oct 2016, 19:19You could feed the temperature in Celcius into a set of expressions to get the result in Fahrenheit.
http://www.rapidtables.com/convert/temperature/how-celsius-to-fahrenheit.htm
hegemonkhan
25 Oct 2016, 21:02all you do is use a Function:
give the Function a Parameter for your input argument, have its scripting be the conversion formula using the Parameter (the input), and then have the Function return the output.
a slightly more involved Function, which can do both directional conversions. Actually, you could include the kelvin too, but I'm lazy. Also, if you rather, you can work with Doubles (decimal numbers), instead of Integers (non-decimal numbers).
the, type="xxx", is the return (output) type
I've put in both an 'input type' and 'output type' for my Parameters, in case you want to expand it to converting with kelvin, too, which requires specifying the 'input type' and 'output type', hence the need for both of these Parameters.
<function name="celsius_and_fahrenheit_conversion_function" parameters="input_type_parameter, output_type_parameter, input_value_parameter" type="int">
if (input_type_parameter = "fahrenheit" and output_type_parameter = "celsius") { // from fahrenheit to celsius
return ((input_value_parameter - 32) * 5 / 9)
} else if (input_type_parameter = "celsius" and output_type_parameter = "fahrenheit") { // from celsius to fahrenheit
return (input_value_parameter * 9 / 5 + 32)
}
</function>
example function calls:
(I show both using a literal/direct value, the "celsius/fahrenheit" input/output type arguments, and using a VARIABLE/indirect-value, an Attribute VARIABLE, which holds the value, the 'global_data_object.celsius/fahrenheit_integer_attribute' input value argument. You can use whatever combination of literal/direct and VARIABLE/indirect that you want: all literals, all VARIABLES, or whatever combination of literals and VARIABLES)
// global_data_object.fahrenheit_integer_attribute = 100 // input
global_data_object.celsius_integer_attribute = celsius_and_fahrenheit_conversion_function ("fahrenheit", "celsius", global_data_object.fahrenheit_integer_attribute)
// global_data_object.celsius_integer_attribute = ~ 38 // output
// global_data_object.celsius_integer_attribute = 100 // input
global_data_object.fahrenheit_integer_attribute = celsius_and_fahrenheit_conversion_function ("celsius", "fahrenheit", global_data_object.celsius_integer_attribute)
// global_data_object.fahrenheit_integer_attribute = ~ 212 // output
and of course you can make any type of input-output/conversion Function you want, not just temparature, such as metric (world) (base 10) vs american (norse/ancient scandavia) (base 12) or whatever else / etc etc etc