Hey guys. I'm having trouble getting an NPC to move in the background of my room. I've tried some code from some other posts, but none of it worked. Can anyone help a guy out? Thanks.
EDIT:
Okay now this is more of an issue of some code not being cooperative. I saw that someone else had asked more or less the same exact question I'm having earlier, and someone replied with some code! Here it is:
if (cPopper.Moving)
{
if (cPopper.x == 409 && cPopper.y == 153) cPopper.Walk (218, 157);
else cPopper.Walk (181, 349);
}
only problem is that the "if" at the beginning of the code is coming up as a parse error. Saying it's unexpected? What's a wallaby to do now? Thanks again.
By the way, I'm putting this in the room script. Is that fine, or do I need to put it somewhere else?
Please tell some details about your room, does it have walkable areas, is the NPC standing on the walkable area?
What is your goal exactly, making it walk from point A to point B, or keep walking along some path, or walk between two places repeatedly? anything else?
Please post the code you are using, it's difficult to tell something without it.
Quote from: Crimson Wizard on Wed 26/04/2023 01:39:05Please tell some details about your room, does it have walkable areas, is the NPC standing on the walkable area?
What is your goal exactly, making it walk from point A to point B, or keep walking along some path, or walk between two places repeatedly? anything else?
Please post the code you are using, it's difficult to tell something without it.
Sure.
if (cPopper.Moving)
{
if (cPopper.x == 409 && cPopper.y == 153) cPopper.Walk (218, 157);
else cPopper.Walk (181, 349);
}
Granted it isn't mine, I took it from an earlier post. I edited the post to futher describe the issue I'm now having. Also yes, the NPC is in a walkable area. I'm thinking that walking from point A to B would be easiest, but I'd like it if the NPC would walk to random locations in the area he's standing in.
Please tell, where exactly did you put this code: which script, and which function?
EDIT: after checking your edits in the first post, which kind of a problem do you actually have: your script does not compile, or it runs but nothing happens in game?
It's a compiling issue. The output reads "Error (line 77): Parse error: unexpected 'if'".
Sorry for not being specific enough, I don't know why I didn't think to put that in my first post lol
Quote from: winterspray on Wed 26/04/2023 03:04:46It's a compiling issue. The output reads "Error (line 77): Parse error: unexpected 'if'".
This likely means that you put this code outside of any function.
All the script commands in AGS must be inside some function to compile and work.
Normally, for the repeated actions, the function "repeatedly execute" is used. In rooms you need to register a function for corresponding event, events are marked on this screenshot:
https://adventuregamestudio.github.io/ags-manual/images/acintro3_05.png
Press ... button to let the editor create a function and link to event for you, the put this code inside.
By the way, I just realized that the script is wrong, condition should say
"if (!cPopper.Moving)"
instead, as the NPC should start Walking into new destination only after it finished previous walk.
EDIT: I found another forum thread which contained this code: https://www.adventuregamestudio.co.uk/forums/beginners-technical-questions/making-a-npc-walk-form-one-spot-to-another/msg636654915/#msg636654915
it's only few days old.
Perhaps moderators could merge these two threads together?
yeah that's where I got the code from. I tried making it work with what I had, and it didn't seem like anyone would bother anyway. But thanks! I'll give it a try!
You might want to check these coordinates though; this code will make the NPC move twice, then never again.
// inside room_RepExec
if (!cPopper.Moving)
{
if (cPopper.x == 409 && cPopper.y == 153) cPopper.Walk (218, 157);
else cPopper.Walk (181, 349);
}
Provided that the NPC starts the game at 409,153 (or is sent there in a some other function), this code will kick in and send them to 218, 157. As soon as they reach that point, the code will kick in again and send them to 181, 349. As soon as they reach those coordinates, the code will keep sending the NPC to 181, 349 where they already are.
If you want the NPC to walk back and forth, you need to send them to the original coords in the else clause.