Frictional Games Forum (read-only)
Rounding off. - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: Rounding off. (/thread-25947.html)

Pages: 1 2


RE: Rounding off. - TheGreatCthulhu - 08-25-2014

Just a few comments to help out people who might be searching the forums because they have similar problems/questions.

(08-25-2014, 12:00 PM)FlawlessHappiness Wrote: For some reason end damage = 0
It really shouldn't

EDIT: NEVERMIND! I got it to work.

Now, I don't know what the values of the variables were in this particular case, but this kind of thing usually happens when you use integer division inadvertently. If both of your operands are integers (variables or constants, it doesn't matter), then "/" is "integer division".

E.g.,
5 / 2 = 2 (+ remainder 1), or
1 / 3 = 0 (+ remainder 3) <-- this kind of thing is usually the problem

But if at least one of the operands is a float (floating point type), then you get your "standard" division:

E.g.,
5.0 / 2 = 2.5, or
1 / 3.0 = 0.33333... , or
7.0 / 3.5 = 2.0

Now, if you have an integer variable and you need floating point division by a hardcoded number, it's pretty easy - you can just do:
Code:
int a = 5;

// later...
int b = a / 2;  // returns 2, because both 'a' and '2' are integers
float c = a / 2.0;   // returns 2.5, because 2.0 was used; the result is of type float!

But what to do when you have two integer variables, and you need floating point division? In that case you'd use something called type conversion (or type-casting). Now, I don't recall the exact syntax, but I think it's something like this - try it out and see if it works:
Code:
int a = 5;
int b = 2;

// later...
float c = float(a) / b;   // float(a) returns a float with the same value as 'a'

That should work I think; remember - it's enough that one of the operands is a float. Now, if type conversions don't work for some reason, IIRC float variables can accept and implicitly convert an int value, so you should also be able to do something like:
Code:
float tempA = a;
float c = tempA / b;

About the other thing:
(08-24-2014, 04:55 PM)Romulat✪r (✿◠‿◠) Wrote: Only problem is, I got no idea how to use it Tongue

(08-24-2014, 07:07 PM)FlawlessHappiness Wrote: What, so the code
[...]
Actually needs to be in my file, but with nothing editted into it?

To use the script modules available on the wiki you pretty much have include them at the top of your script - in every script file where you intend to use them. Once they are in there, you should not change anything; you use them by calling the functions defined in them, in the same way you'd call any of the other, preexisting engine functions. (Look at the function signatures to see what parameters they expect, and what values they return, if any).

You would include them either by a direct copy-paste, or, in a more involved scenario, when working in a setup that relies on a C-preprocessor, by writing a single line "include directive" that refers to a separate script file that actually contains the code of the module. Something like this
Code:
#include "module_name.hph"

// your code here...

The C-preprocessor (which is just a program of sorts) then replaces this include directive, and literally includes the contents of the module file in its place - so the end result is the same; the file generated by the preprocessor is the one that is actually used in the game. While this may seem a bit more complicated, working with script files which include large modules can be a drag, and using the C-preprocessor simplifies the "development" versions of the script files, so if your game requires a lot of module code, it's quite a bit easier to work this way.


RE: Rounding off. - Romulator - 08-26-2014

Gee, thanks Cthulhu! Big Grin I may not understand everything perfectly right now, but give it about two or three more reads and a good sleep and I should be able to process it Smile