News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

### Author Topic: Organized Battle System.  (Read 8662 times)

#### BRPXQZME

• Hero Member
• Posts: 4572
• じー
##### Re: Organized Battle System.
« Reply #20 on: November 22, 2012, 09:12:45 pm »
srand() seeds the RNG with the single argument. It gives it a starting point for faking random numbers. They’re not actually random, but for most purposes it’s really close enough. On a conceptual level, you give the RNG a “seed” number. For every call to rand(), you do crazy stuff to that seed until it looks like a random number and spit it out; that random number is the new seed. Actual implementation may vary. You probably don’t want to call srand() with the same value every time unless you are testing something, as on the same system, it will always give the same sequence from rand().

time(0) returns time in seconds since midnight 1 January 1970 (as long as the system clock is set accurately). This isn’t good enough a seed for security but for most games it is, since very few people would bother to stack randomness in their favor by setting the system clock. This way, you get a different sequence of random numbers depending on what time the srand() function was called.
we are in a horrible and deadly danger

#### InfamousKnight

• Sr. Member
• Posts: 321
##### Re: Organized Battle System.
« Reply #21 on: November 22, 2012, 09:43:40 pm »
The reason why I made a new thread was because if I double posted or edited my post nobody would notice.. right?

#### BRPXQZME

• Hero Member
• Posts: 4572
• じー
##### Re: Organized Battle System.
« Reply #22 on: November 22, 2012, 09:49:31 pm »
On these forums, double posting or editing will mark the thread new, but without bumping it.
we are in a horrible and deadly danger

#### Nagato

• Jr. Member
• Posts: 41
##### Re: Organized Battle System.
« Reply #23 on: November 22, 2012, 10:29:59 pm »
In addition to the "don't seed random every time you call rand()", I'd like to point out another bug in your code.

Code: [Select]
`eability = rand() % 1;`Modulo is the remainder of the division operation.
Assuming rand() is 10 and if you use a 1 as your modulo, the math looks like 10 - (1 * floor(10/1)) which is the same as 10 - 10. Using 1 as your modulo will always equal 0.
So if you want either 0 or 1, you would use % 2. If you want 0, 1, or 2, you would use % 3. And so on.
There are more complicated ways to do it (google if you want to learn more about getting a range out of rand()) but that's the simple method.

#### InfamousKnight

• Sr. Member
• Posts: 321
##### Re: Organized Battle System.
« Reply #24 on: November 22, 2012, 11:38:28 pm »
a range would be like:
if(rand() % 4 >= 0 && rand() % 4 <= {}

that code doesn't make a lot of sense its just a sample of range. I learned about making a range in computer programming 1 in 10th grade. Apparently, that was the ONLY thing I learned that I actually care about

#### BRPXQZME

• Hero Member
• Posts: 4572
• じー
##### Re: Organized Battle System.
« Reply #25 on: November 22, 2012, 11:49:41 pm »
It doesn’t make any sense at all. Two calls to rand() is like rolling a die twice; plus, rand()%4 will always be greater or equal than 0, and rand()%4 will always be less than or equal to 8 so you might as well omit the conditional
we are in a horrible and deadly danger

#### InfamousKnight

• Sr. Member
• Posts: 321
##### Re: Organized Battle System.
« Reply #26 on: November 23, 2012, 10:34:45 pm »
I know that code didn't make a lot of sense I should have wrote:
if(input >= 0 && input <= 7)

that ^ would make more sense.

I didn't know that about random numbers.. Like the 0 - 1 chance. That ain't random at all. Thanks for whoever told me about this! yeah, I forgot his username

November 25, 2012, 01:08:37 pm - (Auto Merged - Double Posts are not allowed before 7 days.)
I've created a battle system with some pretty ugly code so I updated it breaking the good parts into sections.

Here's my new code:
http://pastebin.com/5tkVG138
Somebody suggested that I make a damage calculation function but I couldn't bother. Sorry about all the constant text in the comments. I just like yelling at the people trying to learn lol.. no.
« Last Edit: November 25, 2012, 01:08:37 pm by InfamousKnight »

#### henke37

• Hero Member
• Posts: 643
##### Re: Organized Battle System.
« Reply #27 on: November 26, 2012, 07:02:50 am »
You still have instances of forcibly seeding the random number generator. And all the other issues I pointed out aren't addressed at all.

#### InfamousKnight

• Sr. Member
• Posts: 321
##### Re: Organized Battle System.
« Reply #28 on: November 26, 2012, 05:37:22 pm »
Like putting music and a better UI in the game? I don't think I'm advanced enough for that.. 1: I do not compose music, 2: I never deal with fancy UIs. This is a console application which are typically easy to write. If I were to make graphics in my game I might use java since java and c++ are somewhat similar. I don't know ANYTHING about java except hello world and I'm also not an artist for the game sprites although I can go on videogamesprites.net for those but then again I'm not a graphics programmer..

Give me credit! This was done all by me. Meaning just one person. Professional games take at least 10 people to work on it. One person for the programming one person for the music/graphics etc.

Also, for some reason, linux wouldn't let me install the JDK with the package manager and for some reason my code doesn't work on dev-cpp on windows. Like it crashes when you start the battle.. That is like SOOO weird. It works on linux with g++ though..

#### BRPXQZME

• Hero Member
• Posts: 4572
• じー
##### Re: Organized Battle System.
« Reply #29 on: November 26, 2012, 05:44:22 pm »
Nobody is denying it’s a start, but Henke here is just tellin’ it like it is; this code has serious outstanding issues that really aren’t outside your reach to address.
we are in a horrible and deadly danger

#### henke37

• Hero Member
• Posts: 643
##### Re: Organized Battle System.
« Reply #30 on: November 27, 2012, 02:59:46 am »
I actually didn't say anything about the assets or such. I pointed out that your design has a lot of strings that should be enums or pointers to objects. As well as pointing out that your design doesn't work for running all the rest of the tasks a game needs to run. Such as animations, sound and music.

It isn't that you don't have the assets to do it, but rather that the design wouldn't work even if you did.

#### InfamousKnight

• Sr. Member
• Posts: 321
##### Re: Organized Battle System.
« Reply #31 on: December 09, 2012, 01:34:16 pm »
Uh, does this game work for you on windows? For some reason, it only works on linux. No clue why it worked before on windows. There's no windows nor linux system calls in this game. Its pure c++. Please test my code. Note: I was using g++ to compile it.

#### LostTemplar

• Hero Member
• Posts: 906
##### Re: Organized Battle System.
« Reply #32 on: December 09, 2012, 03:47:32 pm »
Maybe your compiler is on its period.

No, seriously, shouldn't your compiler say why it's not working? If it compiles, but won't run, what happens? No error messages?

I feel ashamed I even have to ask, but you are aware that you have to recompile it with a Windows compiler in order to make it work on Windows?

#### InfamousKnight

• Sr. Member
• Posts: 321
##### Re: Organized Battle System.
« Reply #33 on: December 09, 2012, 03:54:59 pm »
It compiles just fine. It crashes when the battle starts.

#### LostTemplar

• Hero Member
• Posts: 906
##### Re: Organized Battle System.
« Reply #34 on: December 09, 2012, 03:58:02 pm »
Well, then use a debugger and look for what's wrong.