Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rounding off.
TheGreatCthulhu Offline
Member

Posts: 213
Threads: 10
Joined: Oct 2010
Reputation: 32
#11
RE: Rounding off.

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:
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:
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:
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
#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.
08-25-2014, 05:34 PM
Find
Romulator Offline
Not Tech Support ;-)

Posts: 3,628
Threads: 63
Joined: Jan 2013
Reputation: 195
#12
RE: Rounding off.

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

Discord: Romulator#0001
[Image: 3f6f01a904.png]
08-26-2014, 04:21 PM
Find




Users browsing this thread: 1 Guest(s)