Jump to content

Last question (for this component): checking if a spell exists


subtledoctor

Recommended Posts

Okay, I have a list of spell IDS names in an array, and I'm performing a RES_NUM_OF_SPELL_NAME on them inside the ACTION_PHP_EACH block. But, RES_NUM_OF_SPELL_NAME doesn't fail gracefully or skip a non-existent spell; if it runs on an IDS name of a spell that doesn't exists (say, CLERIC_WALL_OF_MOONLIGHT in BG2EE), then the mod installer throws an error and craps out.

 

Simple fix: run a check inside that PHP_EACH block to make sure the spell is present in the game's spell.ids file. I have some code that should get this done, but I want to run it by people here to make sure I'm not using crazy code. I originally used it to check for settings in baldur.ini, so maybe it's crazy to use the same thing on a file like spell.ids.

 

Here's what I have now:

 

ACTION_PHP_EACH spellsphere AS spl => sph BEGIN
 
   COPY_EXISTING - ~spell.ids~ ~mod/backup~
      COUNT_REGEXP_INSTANCES ~%spl%~ spell_exists
 
   ACTION_IF (spell_exists) THEN BEGIN
 
      ( yadda yadda weidu stuff )
 
   END
END

 

My only question is, is that a nutty way to do that?? Is there a preferred way?

Link to comment

@Ardanis spell.ids is read because if I add a spurious item to my array, like

CLERIC_GIVE_COOTIES , 3 => 10 / add to "Affliction" sphere
...then the only way to find the .spl filename for the EXISTS_IN_GAME check, is to run RES_NUM_OF etc. But that function won't run on an item that doesn't exist in spell.ids. So it's a chicken & egg problem unless/until I read from spell.ids to confirm the existence of the item.

 

@Mike thanks, that's exactly what I was looking for. (My hackery works... but it is complete hackery by contrast.)

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...