Post new topic    
Liquid Metal Slime
Send private message
NPC at spot - Problem with code 
 PostSat Oct 12, 2013 8:12 am
Send private message Reply with quote
I am having an issue with the following code:

Code:

While (NPC direction (0) == north) do(      
     xNPC := NPC X (0)
     yNPC := NPC Y (0)
     If ((read zone (10, xNPC, yNPC--1) == true) || ((NPC at spot (xNPC, yNPC--1) == true)))  then(
          break
     )
     else (
     create NPC (1, xNPC, yNPC--1, north)
     )
wait (1)
)


I want the code to do the following:

While NPC 0 is facing north, find NPC 0's x and y position. Now check to see if zone 10 exists one tile to the north or if any NPC exists at one tile to the north. If so break the loop, otherwise create NPC 1 one tile to the north.

Problem:

If zone 10 exists one tile to the north the loop will break, this is what I want. On the other hand if an NPC, lets say NPC 5, exists one tile to the north the code will NOT break...

Is this an improper use of the NPC at spot command? Is there some command I can alternatively use to check if any NPC's exist at a given (x,y) at a given time?
⊕ 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
Metal King Slime
Send private message
 
 PostSat Oct 12, 2013 10:23 am
Send private message Reply with quote
"npc at spot" doesn't return a true/false value; it returns an NPC reference (for the first NPC on that tile, though it takes an optional argument to deal with stacked NPCs), or 0 if there's no NPC there.

So you should instead write "NPC at spot (xNPC, yNPC -- 1) <> 0" (which is actually equivalent to "NPC at spot (xNPC, yNPC -- 1)", as nonzero values count as true)
Liquid Metal Slime
Send private message
 
 PostSun Oct 13, 2013 9:05 am
Send private message Reply with quote
Thanks this helped so much,
⊕ 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
Display posts from previous: