Need some help moving NPCs in 9verbs format. SOLVED!!

Started by BigHairyEyeball, Sat 19/08/2017 23:19:51

Previous topic - Next topic

BigHairyEyeball

... And it was solved by ignoring the 9verbs coding format and just doing things the old-fashioned way. Still works, so I can't complain!

Sorry it took so long to get this updated, but thanks for all the help you guys gave, even if I just went with "cCharacter.Walk" in the end. :D

_____

Hello again!

I've been trying to crank out my game for this deadline, but I could use some pointers on scripting animation. As the title says, I'm using the 9Verbs style to build my game, but I'm having a little trouble understanding how to get an NPC to move from one place to another. I'm obviously doing something wrong, so I was hoping someone could give me some advice.

The code I've been using comes straight from the 9Verbs tutorial document. Here's the code as it exists there:

Code: ags

int NPCGoToCharacter(Character*charidwhogoes, Character*charidtogoto,
eDirection dir, bool NPCfacesplayer, int blocking);


I'm using it on a character with an ID of 7 (character name cBodyguard) who needs to walk to the main player (cMonk, with an ID of 0), but can't seem to make it work. The code I've actually typed in last looks like this:

Code: ags

7 NPCGoToCharacter(cBodyguard*7, cMonk*0, 4, true, eBlock);


I'm obviously doing something wrong here. Can anyone help me? Or is there a workaround?

Thanks in advance!

- BigHairyEyeball

Snarky

#1
Try this:

Code: ags

NPCGoToCharacter(cBodyguard, cMonk, 4, true, eBlock); // Though instead of "4" I would use one of the named enum values that should pop up when you type it in


It's important to understand the format of a function and what the different parts of the definition means.

So for example, when the code says int NPCGoToCharacter(...), that doesn't mean you should put a number before the function when calling it. It means that it's a function that returns a number, so that you could write, for example:

Code: ags
 int returnval = NPCGoToCharacter(cBodyguard, cMonk, 4, true, eBlock); // The returnval int will be set to the value returned by NPCGoToCharacter()


You have to look in the documentation to see what this number means.

Similarly, Character*charidsomething means that this argument is of type Character*, and charidsomething is just a name that is meant to help describe what it represents. So you have to fill it in with a Character* â€" which is what the character script names (e.g. cBodyguard, cMonk) are. In this case it's a little confusing since the argument names use "charid", wrongly suggesting that you should use the character ID, but if you just focus on the variable type you won't get confused.

BigHairyEyeball

Thanks! I'll give it a shot later tonight, after I get this puzzle coded in. If nothing else, you've pointed me in the right direction; the documentation gave me the format, but for me it's always better to see a live example and extrapolate from that. I owe you a blue cup of whiskey!

BigHairyEyeball

Dang. It doesn't work. I don't get an error for the code, and the AGS builder says everything's valid (and suggests, as usual, what to put where), but my NPC still isn't moving. Any suggestions?

Khris

My first suggestion would be to describe what exactly you tried, including the code you've used... (roll)

BigHairyEyeball

Not a problem. Here's the code as it stands now.

Code: ags

function room_FirstLoad() {
    MovePlayer(73, 125);
    cBodyguard.Say("No, wait! Don't let the--");
    aGemdoor3.Play();
    object[0].Visible = true;
    cBodyguard.Say("-- door close.");
    Wait(15);
    NPCGoToCharacter(cBodyguard, cMonk, 4, eDirectionRight, eBlock);
    cBodyguard.Say("Great. Now we're BOTH trapped in here.");
    
}


Still not sure what I'm doing wrong, but this is my first attempt at building a game AND serious coding, so I don't doubt I'm missing something extremely simple.

Khris

So everything else plays as supposed to, but the NPC doesn't move in between the bodyguard's lines?
Just to be sure, is the NPC standing on a walkable area?

BigHairyEyeball

Sorry, got swamped with work over the past few days, so I haven't been able to get back to this or the game for a while - but yeah, everything else is working fine. All the .SAY lines go off, the object swaps visibility, and the bodyguard's on a walkable area - it's just the bodyguard doesn't move an inch. I'm having no problems moving the main character (cMonk), either; MovePlayer works just fine for him. It's getting the NPCs to move that seems to be the issue. No idea what's going on.

Khris

I don't know if that'll fix it but the parameters are still off. Try
Code: ags
  NPCGoToCharacter(cBodyguard, cMonk, eDirectionRight, true, eBlock);

BigHairyEyeball

Awesome. As soon as I get back from the office, I'll give it a shot. If this doesn't work, I'm going to have to get creative with my story - next time I make a game in AGS, I'm sticking to Sierra Style and that's that. I appreciate all the help, man. ;-D;-D;-D

BigHairyEyeball

Ugh. Didn't work. Thanks anyways. I'll start plumbing through the 9Verbs master document again later tomorrow night and see if I'm missing anything; if I don't solve it by Monday, I'll just rework my narrative/story and code around it. Appreciate the help!

SMF spam blocked by CleanTalk