RPG Battle System

Started by
15 comments, last by ARC inc 14 years, 1 month ago
Quote:Original post by Tiblanc
You need to swap str and dmg in your damage calculations.
You have addressed this issue a little too thoroughly. You calculate c.dmg but then you now use c.str to alter the health variable.

In regards to the random variable, which number always gets used? Does it change if you restart the game?
- Haptic
Advertisement
It keeps on landing on rand 2 and no it does not change when I restart it.
time_t is a variable type, not a function.

So what you are basically doing is calling srand(NULL) every time before you calculate damage. This resets the list of random numbers, and because it's the same seed, you will always get the first number (in this case 2). You only need to seed once, at the start of your program.

I would replace time_t with time, and move the srand call to your init code where it will only run once.
- Haptic
that worked thanks is this something to worry about

1>c:\documents and settings\computer\desktop\game\untitled_text_game\untitled_text_game\attack.h(38) : warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data

It's just a warning but is there a way to get it to go away? Besides using time_t? That's the reason I had the srand as time_t
This happens because srand() expects an integer, and time() gives it a time_t variable. You can try typecasting the time_t as an unsigned integer. This would look something like
srand((unsigned int)time(NULL))

This stuff isn't my strong point so it may or may not work but it's worth a try.
- Haptic
@Haptic That should work. Some tutorials and the like suggest that.

If it doesn't work, just use (unsigned) since the int will be implied.
That worked thanks fellas, now on to the next step lol

This topic is closed to new replies.

Advertisement