static const char aString[] = "This is a constant static string.";
static const char *arrayOfStrings[] = {
"This is an array of constant static strings.",
"Another string.",
"Yet another string."
};
char myString[] = "some string";
char *myString = "some string";
char myString[] = "some string"; // Explicitly create an array of characters
char *stringPointer = &myString[0]; // Make stringPointer point to the first character in myString
char *stringPointerTwo = "some string"; // Implicitly create an array of characters and make stringPointerTwo point to the first character
// stringPointer and strPointerTwo now each point to a different character array
// containing "some string" and will show as equal when comparing with string functions, e.g., strcmp()
static const char myArraryOfCharacterArrays[][] = {
"String1",
"String2",
"String3'
}
static const char *myArrayOfStringPointers[] = {
"String1",
"String2",
"String3"
}
bobby@dev1:~$ cat test.c
int main(void) {
char *myString = "a string";
char myChar = '\0';
myChar = myString; // Can't assign a string (character array) to a character.
return 0;
}
bobby@dev1:~$ gcc test.c
test.c: In function 'main':
test.c:4: warning: assignment makes integer from pointer without a cast
bobby@dev1:~$
struct gem_data
{
const char *name;
const char *short;
const char *long;
};
#define NUM_GEMS 2
const struct gem_data gem_list[NUM_GEMS] =
{
{ "amethyst", "small amethyst gem", "A small amethyst beautifully glowing" },
{ "etc etc", "small etc etc", "A small etc etc beautifully glowing" }
};
int gnum = number_range( 0, NUM_GEMS );
gem = create_object (get_obj_index (OBJ_VNUM_RGEM), 0);
gem->name = gem_list[gnum].name;
gem->short_descr = gem_list[gnum].short;
gem->description = gem_list[gnum].long;
Anyway, I've decided that I need to learn how to use them properly, 1) It is how all the stats are setup to do their respective abilities, and 2) I got to start stepping outside of my coding boundaries…
So, this is the magic missile I have setup…
void spell_magic_missile( int sn, int level, CHAR_DATA *ch,void *vo,int target)
{
CHAR_DATA *victim = (CHAR_DATA *) vo;
static const sh_int dam_each[] = //Inside the brackets I could set a number to set a max on the following numbers allowed?
{ //So 10 would make it so only 10 numbers could be included?
0,
25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
35, 35, 35, 35, 35, 40, 40, 40, 40, 40,
45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
50, 50, 50, 50, 50, 50, 50, 50, 50, 100
};
int dam,i;
level = UMIN(level, sizeof(dam_each)/sizeof(dam_each[0]) - 1);
level = UMAX(0, level);
for(i = 1 + (ch->level / 10) ; i > 0; i–)
{
dam= number_range( dam_each[level], dam_each[level] * 2 ); //Is this pulling a random number from the dam_each table where the
if ( saves_spell( level, victim,DAM_ENERGY) ) //random number is defined "players level" to "players level * 2"
dam /= 2; //and if I wanted to pull a number from the table = to the players level
damage( ch, victim, dam, sn, DAM_ENERGY ,TRUE); //I would have to go back and define numbers until I get 100 setup?
} //Then I would just do dam = dam_each[level]?
return;
}
I didn't write this, it was a snippet…
Running ROM 2.4 QuickMUD
–Silence Tyire of Reanimation