How to check the palette of an npc

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

Moderators: marionline, SDHawk

Post Reply
User avatar
Seamus Moore
Slime
Posts: 19
Joined: Mon Mar 16, 2020 9:39 pm
Location: Seamus Moore's House

How to check the palette of an npc

Post by Seamus Moore »

I need an if function that can check if a certain npc has the palette id of 2.
I tried using read npc, but it never properly returns as true.
dQw4w9WgXcQ
User avatar
Bird
Slime Knight
Posts: 227
Joined: Thu Jan 26, 2012 2:19 pm
Location: Germany

Post by Bird »

There must be a critical typo in your code!
Look, this line should do it.

Code: Select all

if (read NPC (9,NPCstat:palette) == 2) then (...) else (...)
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7658
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Yes, Bird's approach is correct.

One caveat is that it won't help if your NPCs are using the default palette -1

If that is the case, then "read NPC" will just return -1 instead of reporting whatever default palette is actually being used.

Here is a slice-based workaround that solves that situation

Add this script to your script file:

Code: Select all

script, check npc palette, npc, begin
  variable(sl, pal)
  sl := get npc sprite(npc)
  pal := get sprite palette(sl)
  if(pal == -1) then(
    pal := get sprite default pal(sl)
  )
  exit returning(pal)
end
then you can use it like this:

Code: Select all

if (check npc palette (9) == 2) then (...) else (...)
Post Reply