NPC walkabout picture is being unexpectedly altered?

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

Post Reply
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

NPC walkabout picture is being unexpectedly altered?

Post by sheamkennedy »

I have a scenario in my game which is changing one of my NPC's walkabout picture into another. I think the problem somehow boils down to my LOS script.

In my game I have 2 types of "guards," one is a TURRET, the other is a SPIDER. Both of which share the same LOS script. If they "see" you then they will alter their behaviour.

If the TURRET see's you it will alter NPC picture to (51) followed by (50) to represent that it shot you. Also a textbox will be displayed.

If the SPIDER see's you it will alter NPC palette and it will also be set to chase the hero.

The problem: Occasionally when the hero is seen by a TURRET it will cause one of the SPIDER'S to be altered to NPC picture (50).

Here's a snippet of the LOS so you can see what's going on:

Code: Select all

          xNPC := NPC X (guardNumber) 
	      yNPC := NPC Y (guardNumber)
	      xMe := hero x (find hero (0)) 
	      yMe := hero y (find hero (0))   
	      
	# Checks to see if sight is blocked or hero is found
	if &#40;&#40;read zone &#40;21, xNPC, yNPC+1&#41; == true&#41; || &#40;&#40;NPC at spot &#40;xNPC, yNPC+1&#41; <> 0&#41;&#41;&#41; then&#40;continue&#41; 
	else if &#40;&#40;xMe == xNPC&#41; && &#40;yMe == yNPC+1&#41;&#41; then&#40;
	
	  # Change the guard to chase-mode or make turret shoot
	  if&#40;&#40;guardNumber == 7&#41;||&#40;guardNumber == 8&#41;||&#40;guardNumber == 9&#41;&#41; then&#40;
	    if&#40;current text box == -1&#41; then&#40;
	      Alter NPC &#40;guardNumber,NPCstat&#58;picture,51&#41;
	      suspend NPCs
	      show text box &#40;6&#41;
	      wait for textbox
	      Alter NPC &#40;guardNumber,NPCstat&#58;picture,50&#41;
	    &#41; 
	  &#41; else &#40;
	    Alter NPC &#40;guardNumber, NPCstat&#58;move type, NPCmovetype&#58;chaseyoupathfinding&#41;
	    Alter NPC &#40;guardNumber, NPCstat&#58;activation, NPCactivation&#58;touch&#41;
	    Alter NPC &#40;guardNumber,NPCstat&#58;palette,1&#41;
	  &#41;
	  break
	&#41;
This code cycles through all the guards on my map which are numbered (guardNumber 4 to 14) which correspond to NPC #4 to #14 on my map. Notice that only guardNumber 7 to 9 are TURRET'S and therefore part of the LOS script checks for these guardNumbers and issues a different set of commands to them which results in their NPC picture becoming (50). I can't seem to figure out how NPC #14 could become picture (50) since there is a check in place to make sure only NPC #7 - 9 can do so.

I'm wondering if maybe I'm applying the LOS script to too many NPC's and somehow the script is being overloaded somehow causing this strange result. What makes me suspect this is because it is only happening to NPC #14 (the last NPC to be cycled to) and none of the other NPC's.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Yes, it looks like the script couldn't possibly do that. But it is, so some other assumption is wrong. So guardNumber is the NPC id? Looping from 4 to 14? And I assume it's not a global variable.
Try adding showvalue or tracevalue above "Alter NPC (guardNumber,NPCstat:picture,50) " to print the value of guardnumber at the moment everything goes wrong, to check what it actually is. It certainly can't be 14. Try using NPC debug mode (F6) to check the IDs of NPCs on the map are as expected.

Also, "hero x (find hero (0))" is wrong, since herox expects a caterpillar party slot and findhero returns a party slot. If you want to refer to the party leader, write "hero x(0)". See http://rpg.hamsterrepublic.com/ohrrpgce ... n_a_script
Last edited by TMC on Sat Sep 16, 2017 1:17 pm, edited 1 time in total.
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

I think I do want my LOS script to search for hero in party position 0. This is because I pulled my LOS script from another game that checked through all positions in my caterpillar. I want my script to be expandable just in case I decide to utilize the caterpillar party. Perhaps I may have a mission in which you must help someone out and therefore must consider that enemies can see them as well as yourself.

Thank you, I did end up using show value and confirmed that guard number was occasionally equal to 14. I still haven't understood why this is the case though. LOS is only called each-step since I am doing a rougelike game. When I step in front of the turret it shoots me , displays a text box and show value returns 7. However if I am being hasty and hold down the spacebar while walking past the turret's LOS it seems to display the text for about 1 tick and then show value returns 14 as my hero proceeds to the next tile.

At first I thought maybe I was skipping the textbox too fast so I added a wait(20) to the text to give it time to display. This didn't work. There was a 20 tick delay but still if I was holding spacebar while trying to walk past the turret, show value would still return 14.

Therefore I think it has something to with how textboxes work. I never really got to the bottom of this but decided I'd swap the textbox out for a menu since menu's have a bitset which can disallow scripts, suspend player, etc... By switching to a menu the problem has been solved. I am still completely puzzled though, I tried so many things before deciding to just go with a menu.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

So is guardNumber a global variable? Without see the whole script (with the showvalue) I can't understand what was happening.
I think I do want my LOS script to search for hero in party position 0.
I'm not clear on what you're saying, are you trying to argue that that line of code I pointed out is actually right? It's definitely wrong regardless of what you wanted to do, and it doesn't "search for hero in party position 0" anyway.
Last edited by TMC on Sun Sep 17, 2017 2:27 pm, edited 4 times in total.
Post Reply