18 Oct, 2011, arholly wrote in the 1st comment:
Votes: 0
Hello again. I'm finding all sorts of hidden gems that I need help with. So, here is my problem. The code below works fine except for one thing. The syntax is "influence material <material>" to get a quantity of material in which to build or make something with. And it works. But the problem is, if they ask for something that is not in the table, it generates "x pounds of none." How can I make it so that if what they request is not in the table, it does not generate anything but gives them some message?

int scientific_materials(CHAR_DATA *ch, char *argument)
{
int fail = UMIN(dice_rolls(ch, get_curr_stat(ch, STAT_CHA)
+ ch->ability[SCIENCE].value, 7), ch->influences[INFL_SCIENTIFIC]);
char arg[MAX_INPUT_LENGTH];
int material, size;
OBJ_DATA *obj;

if(argument[0] == '\0')
{
send_to_char(
"Syntax: influence materials <material>\n\r", ch);
return FALSE;
}

argument = one_argument(argument, arg);

if((material = material_lookup(arg)) < 0)
{
send_to_char("There is no such material.\n\r", ch);
return FALSE;
}

if(fail > 0)
{
size = UMIN(fail/2, 7);
send_to_char("You manage to acquire some of the material.\n\r", ch);

sprintf(arg, "pounds %s", material_table[material].name);
if((obj = get_obj_carry( ch, arg, ch )) == NULL)
{
obj = create_object(get_obj_index(OBJ_VNUM_DUMMY));
obj->weight = size_table[size].obj_weight;
obj->cost = number_fuzzy(material_table[material].value * 100
* obj->weight);
free_string(obj->name);
sprintf(arg, "%d pounds %s", obj->weight,
material_table[material].name);
obj->name = str_dup(arg);
free_string(obj->short_descr);
sprintf(arg, "%d pounds of %s", obj->weight,
material_table[material].name);
obj->short_descr = str_dup(arg);
free_string(obj->description);
sprintf(arg, "a quantity of a %s%s%s material sits here",
material_table[material].colour,
material_table[material].is_metal?", metallic":"",
material_table[material].is_liquid?", liquid":"");
obj->description = str_dup(arg);
free_string(obj->full_desc);
sprintf(arg, "%d pounds of a %s%s%s material sits here",
obj->weight,
material_table[material].colour,
material_table[material].is_metal?", metallic":"",
material_table[material].is_liquid?", liquid":"");
obj->full_desc = str_dup(arg);
obj->wear_flags = ITEM_TAKE|ITEM_HOLD;
obj_to_char(obj, ch);
}
else
{
obj->weight += size_table[size].obj_weight;
obj->cost = number_fuzzy(material_table[material].value * 100
* obj->weight);
free_string(obj->name);
sprintf(arg, "%d pounds %s", obj->weight,
material_table[material].name);
obj->name = str_dup(arg);
free_string(obj->short_descr);
sprintf(arg, "%d pounds of %s", obj->weight,
material_table[material].name);
obj->short_descr = str_dup(arg);
free_string(obj->description);
sprintf(arg, "a quantity of a %s%s%s material sits here",
material_table[material].colour,
material_table[material].is_metal?", metallic":"",
material_table[material].is_liquid?", liquid":"");
obj->description = str_dup(arg);
free_string(obj->full_desc);
sprintf(arg, "%d pounds of a %s%s%s material sits here",
obj->weight,
material_table[material].colour,
material_table[material].is_metal?", metallic":"",
material_table[material].is_liquid?", liquid":"");
obj->full_desc = str_dup(arg);
}
}
else if(fail == 0)
{
send_to_char("You fail to avoid the trade fees.\n\r", ch);
}
else
{
send_to_char("You damage your credibility in the market.\n\r", ch);
ch->influences[INFL_SCIENTIFIC]–;
}

ch->infl_timer = 2;
return TRUE;
}
18 Oct, 2011, Vatiken wrote in the 2nd comment:
Votes: 0
if((material = material_lookup(arg)) < 0)
{
send_to_char("There is no such material.\n\r", ch);
return FALSE;
}

This should be where the problem of a errant material name is eliminated. Either there is a bug in your material_lookup() or more likely, this should be set to <= 0 instead.
18 Oct, 2011, arholly wrote in the 3rd comment:
Votes: 0
OK, so if I make it <=0, I'm telling it that if it is 0 or anything below it, it should give it that message, where it was just less than 0 before.
18 Oct, 2011, Vatiken wrote in the 4th comment:
Votes: 0
Correct
18 Oct, 2011, arholly wrote in the 5th comment:
Votes: 0
I see. Thanks. And that did fix it.
18 Oct, 2011, plamzi wrote in the 6th comment:
Votes: 0
arholly said:
I see. Thanks. And that did fix it.


You have gained a level.
18 Oct, 2011, arholly wrote in the 7th comment:
Votes: 0
WooT!

It was fine when I was suggesting all these fine ideas to the ex-coder, but now that I am the coder, it's much more difficult. C'est la vie and all that.
18 Oct, 2011, plamzi wrote in the 8th comment:
Votes: 0
arholly said:
WooT!

It was fine when I was suggesting all these fine ideas to the ex-coder, but now that I am the coder, it's much more difficult. C'est la vie and all that.


The idea is 0% of the implementation. :biggrin:
18 Oct, 2011, arholly wrote in the 9th comment:
Votes: 0
Yes, I know that. It seems I'm finding bugs in stuff that got reported but never fixed, so I'm fixing them before implementing anything new.
18 Oct, 2011, David Haley wrote in the 10th comment:
Votes: 0
Well, at least it's commendable to be doing housekeeping rather than letting issues pile up as you add new stuff. And this is a good learning experience, too…
18 Oct, 2011, arholly wrote in the 11th comment:
Votes: 0
What's the point in adding new stuff if the "new" stuff I have is broken or doesn't work quite right is my thinking. And yes, this is definitely learning, which is why I am asking questions on why, not just fix this.
19 Oct, 2011, David Haley wrote in the 12th comment:
Votes: 0
Trust me, you'd be surprised how often new features are introduced rather than bugs fixed. :wink:
19 Oct, 2011, arholly wrote in the 13th comment:
Votes: 0
Not really. I've been involved in software development or software rollouts and it just amazes me sometimes. I'd rather have what I have work than it not work and keep building on bad. Again, I'm not a great coder, but I want to fix what needs fixing, even if it means coming for help.
19 Oct, 2011, Kaz wrote in the 14th comment:
Votes: 0
arholly said:
I'd rather have what I have work than it not work and keep building on bad.


A noble attitude that is, unfortunately, very infrequently shared by managers and marketing.
19 Oct, 2011, Runter wrote in the 15th comment:
Votes: 0
Kaz said:
arholly said:
I'd rather have what I have work than it not work and keep building on bad.


A noble attitude that is, unfortunately, very infrequently shared by managers and marketing.


Actually, I think managing and marketing want both. :p
19 Oct, 2011, Rarva.Riendf wrote in the 16th comment:
Votes: 0
fast cheap reliable, choose two
19 Oct, 2011, arholly wrote in the 17th comment:
Votes: 0
No, it's usually choose the first two. They don't give an option of what two you want.
0.0/17