Welcome to the Builder Academy

Question What am i missing ?

More
23 Dec 2016 19:14 - 23 Dec 2016 19:51 #6447 by JTP
What am i missing ? was created by JTP
Code:
if (where == WEAR_WIELD || where == WEAR_SHIELD || where == WEAR_LIGHT || where == WEAR_HOLD) { if (free_hands(ch) < 1 && !OBJ_FLAGGED(obj, ITEM_TWO_HANDED)) { send_to_char(ch, "Your hands are full!\r\n"); return; } if (free_hands(ch) < 2 && OBJ_FLAGGED(obj, ITEM_TWO_HANDED)) { send_to_char(ch, "Your hands are full!\r\n"); return; } }
Code:
gcc -g -O2 -Wall -c -o act.item.o act.item.c act.item.c: In function ‘perform_wear’: act.item.c:1312: error: too few arguments to function ‘free_hands’ act.item.c:1316: error: too few arguments to function ‘free_hands’ make[1]: *** [act.item.o] Error 1



And is if (OBJ_FLAGGED(obj, ITEM_TWO_HANDED)) {
enough to replace IS_OBJ_STAT....... ?
Code:
/* circlemud code */ int free_hands(struct char_data *ch) { int used = 2; if(GET_EQ(ch, WEAR_HOLD)) { used -= 1; } if(GET_EQ(ch, WEAR_LIGHT)) { used -= 1; } if(GET_EQ(ch, WEAR_SHIELD)) { used -= 1; } if(GET_EQ(ch, WEAR_OFFHAND)) { used -= 1; } if(GET_EQ(ch, WEAR_WIELD)) { if(IS_OBJ_STAT(GET_EQ(ch, WEAR_WIELD), ITEM_TWO_HANDED)) { used -= 2; } else { used -= 1; } } return used; }
Last edit: 23 Dec 2016 19:51 by JTP.

Please Log in or Create an account to join the conversation.

More
23 Dec 2016 23:29 #6450 by thomas
Replied by thomas on topic What am i missing ?
This code looks ok to me. What's before the checks in the first bit?

Please Log in or Create an account to join the conversation.

More
23 Dec 2016 23:35 #6451 by JTP
Replied by JTP on topic What am i missing ?
Original circlemud snippet, seems the IS_OBJ_STAT dont Work with tba
Code:
Open act.item.c. Before the perform_put() function add: int free_hands(struct char_data *ch) { int used = 2; if(GET_EQ(ch, WEAR_HOLD)) { used -= 1; } if(GET_EQ(ch, WEAR_LIGHT)) { used -= 1; } if(GET_EQ(ch, WEAR_SHIELD)) { used -= 1; } if(GET_EQ(ch, WEAR_OFFHAND)) { used -= 1; } if(GET_EQ(ch, WEAR_WIELD)) { if(IS_OBJ_STAT(GET_EQ(ch, WEAR_WIELD), ITEM_TWO_HANDED)) { used -= 2; } else { used -= 1; } } return used; } Further down in act.item.c in the: void perform_wear(struct char_data * ch, struct obj_data * obj, int where) { function, look for this: if (GET_EQ(ch, where)) { send_to_char(already_wearing[where], ch); return; } Directly below that chunk of code add: if(where == WEAR_WIELD || where == WEAR_SHIELD || where == WEAR_LIGHT || where == WEAR_HOLD) { if(free_hands(ch) < 1 && !IS_OBJ_STAT(obj, ITEM_TWO_HANDED)) { send_to_char("You hands are full!\r\n", ch); return; } if(free_hands(ch) < 2 && IS_OBJ_STAT(obj, ITEM_TWO_HANDED)) { send_to_char("Your hands are full!\r\n", ch); return; } } Save the file and exit.

Please Log in or Create an account to join the conversation.

More
23 Dec 2016 23:55 #6452 by JTP
Replied by JTP on topic What am i missing ?
If i put it in as snippet says, still the 2 errors with too few arguments + the IS_OBJ_STAT

act.item.c: In function ‘free_hands’:
act.item.c:57: warning: implicit declaration of function ‘IS_OBJ_STAT’
act.item.c: In function ‘perform_wear’:
act.item.c:1312: error: too few arguments to function ‘free_hands’
act.item.c:1316: error: too few arguments to function ‘free_hands’
make[1]: *** [act.item.o] Error 1

Please Log in or Create an account to join the conversation.

More
24 Dec 2016 00:05 #6453 by thomas
Replied by thomas on topic What am i missing ?
When in doubt, refactor.

You are right, instead of IS_OBJ_STAT, we now use OBJ_FLAGGED. So far so good.
Code:
if (where == WEAR_WIELD || where == WEAR_SHIELD || where == WEAR_LIGHT || where == WEAR_HOLD) { int hands = free_hands(ch); if (hands < 1 && !OBJ_FLAGGED(obj, ITEM_TWO_HANDED)) { send_to_char(ch, "Your hands are full!\r\n"); return; } if (hands < 2 && OBJ_FLAGGED(obj, ITEM_TWO_HANDED)) { send_to_char(ch, "Your hands are full!\r\n"); return; } }
Apart from the obvious change from two calls to the free_hands function to one call, does this alter your result?

Please Log in or Create an account to join the conversation.

More
24 Dec 2016 00:06 #6454 by thomas
Replied by thomas on topic What am i missing ?
Also, you might want to alter the free_hands function declaration slightly:
Code:
- int free_hands(struct char_data *ch) { + static int free_hands(struct char_data *ch) {

Please Log in or Create an account to join the conversation.

Time to create page: 0.216 seconds