d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Probability In C
Prev123
Add Reply New Topic New Poll
Member
Posts: 1,753
Joined: Apr 12 2011
Gold: 0.00
Mar 26 2013 04:27pm
if i store names in structs, like you said i'll be forced to keep them all at the same length, so there will inevitably be several names with white space at the end of them. what i'm saying is that each time i display those names, to keep things evenly spaced, i would have to detect and trim off whatever white space it has. i'd be using that function 4 times each round (skill and monster name for both monsters currently fighting) so i'm wondering if it's a good idea to store names like that or not


i haven't even thought about how i will be displaying the game - i never learned how and i don't have an idea of where to start. but i want to make the guts of the game before i move on to that
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Mar 26 2013 06:52pm
Quote (Reverence @ Mar 26 2013 06:27pm)
if i store names in structs, like you said i'll be forced to keep them all at the same length, so there will inevitably be several names with white space at the end of them.  what i'm saying is that each time i display those names, to keep things evenly spaced, i would have to detect and trim off whatever white space it has.  i'd be using that function 4 times each round (skill and monster name for both monsters currently fighting) so i'm wondering if it's a good idea to store names like that or not


i haven't even thought about how i will be displaying the game - i never learned how and i don't have an idea of where to start.  but i want to make the guts of the game before i move on to that


WHAT?

just set an array of characters and initialize to \0 (nullbyte)

then use functions like snprint() to take your information and put it into a buffer in which you will print.

all string functions stop at the first nullbyte so there is no "trimming" nessistary.

ext:

char something[10] = {'1', '2', '3', '4', '5', 0, 0, 0, 0, 0};

will always print 12345

id just do something like this tbh

Code
struct{
  char name[15] = {0};
  int damage = 0;
  int multiplier = 0;
  char something_else[100] = {0};
} data_set;

struct data_set monsters[100];

sprintf(monsters[1].name, "%s", "lolwat");
monsters[1].damage = 20000;
monsters[1].multiplier = 2;


that way you can have a common data_set for players and monsters but you can create two different arrays for holding the info.

edit from here you could even randomly select a monster from your array for the player to face and based on the player level you can change the multiplier to change the monsters fixed hp/damage

This post was edited by AbDuCt on Mar 26 2013 06:58pm
Member
Posts: 1,753
Joined: Apr 12 2011
Gold: 0.00
Mar 26 2013 07:00pm
Quote (AbDuCt @ Mar 26 2013 02:52pm)
WHAT?

just set an array of characters and initialize to \0 (nullbyte)

then use functions like snprint() to take your information and put it into a buffer in which you will bring.

all string functions stop at the first nullbyte so there is no "trimming" nessistary.

ext:

char something[10] = {'1', '2', '3', '4', '5', 0, 0, 0, 0, 0};

will always print 12345

id just do something like this tbh

Code
struct{
  char name[15] = {0};
  int damage = 0;
  int multiplier = 0;
  char something_else[100] = {0};
} data_set;

struct data_set monsters[100];

sprintf(monsters[1].name, "%s", "lolwat");
monsters[1].damage = 20000;
monsters[1].multiplier = 2;


that way you can have a common data_set for players and monsters but you can create two different arrays for holding the info.


guess i need to look into that then. like i said, only had a semester of C which was very basic - and that was the only programming class i took lol

This post was edited by Reverence on Mar 26 2013 07:01pm
Go Back To Programming & Development Topic List
Prev123
Add Reply New Topic New Poll