Converting ROM snipper to FUSS

Posted by Mopop on Fri 16 Dec 2005 01:09 PM — 38 posts, 125,564 views.

#0
Hello! I quite recently took the task of adding a ROM snippet to my FUSS mud. Everything is going well, though there are a few errors. I managed to fix a few errors on my own (woo-hoo). But some of the errors coming up on my compile, im not familiar with.

act_obj.c: In function `do_shoot':
act_obj.c:3348: parse error before '(' token
act_obj.c:3349: parse error before '||' token
act_obj.c:3378: warning: implicit declaration of function `check_improve'
act_obj.c:3302: warning: statement with no effect
act_obj.c:3348: warning: statement with no effect
act_obj.c: At top level:
act_obj.c:3429: parse error before '}' token
act_obj.c: In function `do_reload':
act_obj.c:3443: too many arguments to function `get_obj_carry'

Now I looked in the code, and found this piece here and edited it. I may not of edited right.

if( can_use_skill( ch, number_percent(  ), gsn_clip ) ) && IS_OBJ_STAT(gun,GUN_CLIP);
        ||( can_use_skill( ch, number_percent(  ), gsn_energy ) ) && IS_OBJ_STAT(gun,GUN_ENERGY)
        ||( can_use_skill( ch, number_percent(  ), gsn_shell ) ) && IS_OBJ_STAT(gun,GUN_SHELL)
        ||( can_use_skill( ch, number_percent(  ), gsn_fuel ) ) && IS_OBJ_STAT(gun,GUN_FUEL)
        ||( can_use_skill( ch, number_percent(  ), gsn_rocket ) ) && IS_OBJ_STAT(gun,GUN_ROCKET)

those are lines 3348-3352

here are 3429

if (recoil == 1)
        {
        send_to_char ("The recoil slows you down a bit.\n\r", ch);
        WAIT_STATE(ch,1 * PULSE_VIOLENCE);
        }
        if (recoil == 2)
        {
        send_to_char ("The recoil sends throws you off balance.\n\r", ch);
        WAIT_STATE(ch,2 * PULSE_VIOLENCE);
        }
        if (recoil == 3)
        {
        send_to_char ("The strong recoil almost numbs your arm.\n\r", ch);
        WAIT_STATE(ch,3 * PULSE_VIOLENCE);
        }
        if (recoil == 4)
        {
        send_to_char ("The recoil almost shatters your hand.\n\r", ch);
        WAIT_STATE(ch,4 * PULSE_VIOLENCE);
        }

        }
        }
}

I removed the double brackets near the bottom thinking that was the error and It only caused more errors! So Im not sure whats wrong with that part.

There are alot more errors but I want to tackle one at a time. Mainly alot of "implicit declaration of function" errors which I never had to tackle before. Also a few piecies of the snippet I'm not quite sure since its ROM. Thanks in advance, as always :)

Amended on Fri 16 Dec 2005 01:18 PM by Mopop
USA #1
if( can_use_skill( ch, number_percent(  ), gsn_clip ) ) && IS_OBJ_STAT(gun,GUN_CLIP);

Remove that semi-colon at the end. I have no idea why it's there, I don't think you can do that in an ifcheck. Also, does Smaug have IS_OBJ_STAT? I forget.
#2
It was used at IS_WEAPON_STAT and came up as an error. I checked the code for similar and saw IS_OBJ_STAT. Removed the ; and got

act_obj.c: In function `do_shoot':
act_obj.c:3348: parse error before '(' token
act_obj.c:3350: warning: suggest parentheses around && within ||
act_obj.c:3351: warning: suggest parentheses around && within ||
act_obj.c:3352: warning: suggest parentheses around && within ||
act_obj.c:3353: warning: suggest parentheses around && within ||
act_obj.c:3353: parse error before '{' token
act_obj.c:3378: warning: implicit declaration of function `check_improve'
act_obj.c:3302: warning: statement with no effect
act_obj.c: At top level:
act_obj.c:3429: parse error before '}' token

What do you mean it cant be done tho? Its suppose to check if they can use that type of gun. Im not sure how else to write it.
USA #3
I mean, I don't think you can use a semi-colon in an ifcheck.

Get rid of the first ) in the first line. It's closing the whole ifcheck.
Amended on Fri 16 Dec 2005 04:05 PM by Zeno
#4
Should I get rid of it in every line?
bleh I hate all this ( ) stuff =P It seemed to cause more bugs tho -_- so weird.

i changed it to this

if( can_use_skill( ch, number_percent, gsn_clip ) ) && IS_OBJ_STAT(gun,GUN_CLIP)


and got this

act_obj.c:3348: warning: passing arg 2 of `can_use_skill' makes integer from pointer without a cast
act_obj.c:3348: parse error before '(' token
act_obj.c:3350: warning: suggest parentheses around && within ||
act_obj.c:3351: warning: suggest parentheses around && within ||
act_obj.c:3352: warning: suggest parentheses around && within ||
act_obj.c:3353: warning: suggest parentheses around && within ||
act_obj.c:3353: parse error before '{' token

So yeah, I dunno :P
USA #5
Just paste that whole block of code.

Seems like it's using can_use_skill wrong.
#6

 /* Do the character know how to handle a gun ? */
    for(number = 0 ; number < shots ; number = number + 1)
        {
        if( can_use_skill( ch, number_percent, gsn_clip ) ) && IS_OBJ_STAT(gun,GUN_CLIP)
        ||( can_use_skill( ch, number_percent(  ), gsn_energy ) ) && IS_OBJ_STAT(gun,GUN_ENERGY)
        ||( can_use_skill( ch, number_percent(  ), gsn_shell ) ) && IS_OBJ_STAT(gun,GUN_SHELL)
        ||( can_use_skill( ch, number_percent(  ), gsn_fuel ) ) && IS_OBJ_STAT(gun,GUN_FUEL)
        ||( can_use_skill( ch, number_percent(  ), gsn_rocket ) ) && IS_OBJ_STAT(gun,GUN_ROCKET)
        {
            obj_cast_spell( gun->value[3], gun->value[0], ch, victim, obj );
USA #7
Is that the original code? I don't even think that would compile anywhere. It closes the ifcheck off in the first line...
#8
Well no thats just the section for the check to see if they have that weapon skill, the rest is pretty long. Remember this is ROM and Im not really familiar with ROM and my Smaug skills arent as good, so its been tough trying to get the differences.
USA #9
Well yes I know it's Rom, but that doesn't matter. This is basic programming logic:
        if( can_use_skill( ch, number_percent, gsn_clip ) ) && IS_OBJ_STAT(gun,GUN_CLIP)

I highlighted where the two brackets are. As you can tell, it closes off the ifcheck. So then using && will cause an error.

It's really long? Are you saying that the bracket is closing off something else somewhere in the code?
#10
I thought you meant the whole snippet, Im not really good with the bracket and ( ) stuff, heh. So just remove the ( )?
USA #11
Simply put, you need a close bracket for each open bracket, and each function needs two brakcets (even if it has no parameters). The if check should look like this:

if(( can_use_skill( ch, number_percent(  ), gsn_clip ) && IS_OBJ_STAT(gun,GUN_CLIP))
        ||( can_use_skill( ch, number_percent(  ),gsn_energy ) && IS_OBJ_STAT(gun,GUN_ENERGY))
        ||( can_use_skill( ch, number_percent(  ), gsn_shell ) && IS_OBJ_STAT(gun,GUN_SHELL))
        ||( can_use_skill( ch, number_percent(  ), gsn_fuel ) && IS_OBJ_STAT(gun,GUN_FUEL))
        ||( can_use_skill( ch, number_percent(  ), gsn_rocket ) && IS_OBJ_STAT(gun,GUN_ROCKET)))

Thats also using the compilers suggestion of paren's around the vital parts.

Note the form. There is exactly one close paren for each open paren, and the last line has three closes, one which corrosponds to the if's open paren. You can use paren's to override precedence (like in algebra), which often makes things a little less confusing and avoids warnings with the compiler.
Amended on Fri 16 Dec 2005 07:04 PM by Nick Cash
#12
Well i fixed all the brackets like you showed me, and some reason it compiles more errors. This is so confusing -.-

act_obj.c: In function `do_shoot':
act_obj.c:3353: parse error before '{' token
act_obj.c:3373: parse error before "else"
act_obj.c:3378: warning: implicit declaration of function `check_improve'
act_obj.c:3262: warning: unused variable `recoil'
act_obj.c:3302: warning: statement with no effect
act_obj.c: At top level:
act_obj.c:3384: parse error before "if"
act_obj.c:3408: parse error before '->' token
act_obj.c:3413: parse error before '->' token
act_obj.c:3418: parse error before '->' token
act_obj.c:3423: parse error before '->' token
USA #13
Looks like you missed something like a bracket closing in the past. Check and make sure every bracket has a matching end bracket.
#14

||( can_use_skill( ch, number_percent( ), gsn_energy ) && IS_OBJ_STAT(gun,GUN_ENERGY)
        ||( can_use_skill( ch, number_percent( ), gsn_shell ) && IS_OBJ_STAT(gun,GUN_SHELL)
        ||( can_use_skill( ch, number_percent( ), gsn_fuel ) && IS_OBJ_STAT(gun,GUN_FUEL)
        ||( can_use_skill( ch, number_percent( ), gsn_rocket ) && IS_OBJ_STAT(gun,GUN_ROCKET)


I had a question, exactly what does the || do? because I dont see any mis placed things :-\
USA #15
|| is a logical or. && is a logical and.

I'm not just talking about that part. Any part in the code, pretty much before it.
#16
Well I didnt edit anything before It, Im really crappy with the looking for this stuff cause I dont know very much about it.


    /* Do the character know how to handle a gun ? */
    for(number = 0 ; number < shots ; number = number + 1)
        {
        if( can_use_skill( ch, number_percent( ), gsn_clip ) && IS_OBJ_STAT(gun,GUN_CLIP)
        ||( can_use_skill( ch, number_percent( ), gsn_energy ) && IS_OBJ_STAT(gun,GUN_ENERGY)
        ||( can_use_skill( ch, number_percent( ), gsn_shell ) && IS_OBJ_STAT(gun,GUN_SHELL)
        ||( can_use_skill( ch, number_percent( ), gsn_fuel ) && IS_OBJ_STAT(gun,GUN_FUEL)
        ||( can_use_skill( ch, number_percent( ), gsn_rocket ) && IS_OBJ_STAT(gun,GUN_ROCKET)
        }
            obj_cast_spell( gun->value[3], gun->value[0], ch, victim, obj );

You see any error in this?
USA #17
You're missing a lot of closing parenthesis. As I said, make sure they're all closed off. Every ( after the or isn't closed.
#18
LoL could you give me an example, I kept trying to close it off, but it would compile parse errors. x_x;;;
USA #19
This should fix that part:
    /* Do the character know how to handle a gun ? */
    for(number = 0 ; number < shots ; number = number + 1)
        {
        if( can_use_skill( ch, number_percent( ), gsn_clip ) && IS_OBJ_STAT(gun,GUN_CLIP)
        ||( can_use_skill( ch, number_percent( ), gsn_energy ) && IS_OBJ_STAT(gun,GUN_ENERGY))
        ||( can_use_skill( ch, number_percent( ), gsn_shell ) && IS_OBJ_STAT(gun,GUN_SHELL))
        ||( can_use_skill( ch, number_percent( ), gsn_fuel ) && IS_OBJ_STAT(gun,GUN_FUEL))
        ||( can_use_skill( ch, number_percent( ), gsn_rocket ) && IS_OBJ_STAT(gun,GUN_ROCKET)))
        }
            obj_cast_spell( gun->value[3], gun->value[0], ch, victim, obj );


Do you see why/how?
#20
Oh! at the end... lol

if( can_use_skill( ch, number_percent( ), gsn_clip
I was only looking here...I thought the && was independant from the rest.
#21
act_obj.c:3350: warning: suggest parentheses around && within ||
act_obj.c:3378: warning: implicit declaration of function `check_improve'

What does the implicit declaration mean?

victim->fighting;
It also says this statement has no effect?
Australia Forum Administrator #22

If you paste the problem piece of code into the inbuilt notepad in MUSHclient, you can put the cursor on a bracket, and then do Edit -> Select to Matching Brace. This highlights up to the matching brace (skipping nested ones), like this:

example

Now if you move back to just after the "if" and do it, nothing is selected, which shows there is a bracket missing somewhere.

Other editors do this too.

Now you count left/right bracket pairs to see why it can't find the closing bracket.

Amended on Fri 16 Dec 2005 09:52 PM by Nick Gammon
USA #23
Do you have the function check_improve somewhere in the code?

And yes, victim->fighting does nothing.
#24
I assume check_improve is roms version of
learn_from_failure( ch, sn );

also what would be better to use than victim->fighting?
USA #25
Better than victim->fighting? What exactly do you intend to be doing..?

If check_improve is the learn_from, make sure you have a check for both success and failure.
#26
obj = NULL;
if ( arg2[0] == '\0' )
{
if ( ch->fighting != NULL )
{
victim->fighting;
}
else
{
send_to_char( "Shoot whom or what?\n\r", ch );
return;
}

Thats the whole code, I dont know why its checking to see if someone is fighting?
USA #27
That makes no sense. From what I've seen, this is a really bad snippet... If they wanted to do a null statement, they could have just used ;
#28
LoL Its the best I could find =( im not even sure why you need to check to see if someone is fighting for that...
USA #29
It looks to me like it is suppose to set your target to who you're fighting. But that's not what it does.
#30
Well I got the error to go away.

act_obj.c:3343: warning: suggest parentheses around && within ||

Now what the heck does that mean and Ill be happy ;-)
USA #31
Can you paste that code block?
#32
/* Do the character know how to handle a gun ? */
for(number = 0 ; number < shots ; number = number + 1)
{
if( can_use_skill( ch, number_percent( ), gsn_clip ) && IS_OBJ_STAT(gun,GUN_CLIP)
||( can_use_skill( ch, number_percent( ), gsn_energy ) && IS_OBJ_STAT(gun,GUN_ENERGY))
||( can_use_skill( ch, number_percent( ), gsn_shell ) && IS_OBJ_STAT(gun,GUN_SHELL))
||( can_use_skill( ch, number_percent( ), gsn_fuel ) && IS_OBJ_STAT(gun,GUN_FUEL))
||( can_use_skill( ch, number_percent( ), gsn_rocket ) && IS_OBJ_STAT(gun,GUN_ROCKET)))
{

Its this same damn block x_x
USA #33
Change the line to:
if(( can_use_skill( ch, number_percent( ), gsn_clip ) && IS_OBJ_STAT(gun,GUN_CLIP))

I think.
#34
heh didnt work

     ||( can_use_skill( ch, number_percent( ), gsn_shell ) && IS_OBJ_STAT(gun,GUN_SHELL))
is the line, line 3343
USA #35
Might be a tad more informative if you would actually explain 'how' it didn't work, not just "heh, didn't work". That doesn't help anyone to solve your problem.

For starters, are you still getting the same error message as before? Can you post the code you are using now and what the current error message associated with it is, line numbers and all?

Maybe with that info people can be of more help?

#36
Yeah I was replying to Zeno, Its over anways.
USA #37
Meh. Looked like a forum response to me, but what do I know?

At any rate, maybe you can share what the problem was in case others have issues with the same snippet? Seems only fair.