Jump to content

RES_NUM_OF_SPELL_NAME frustration


Recommended Posts

Whoops - forgot an EVAL.  Sorry, nothing to see here, move along.  (Well, I mean, I still sort of think the point holds... but whatever.)

Spoiler

 

I have an array of mixed spell IDS names and filenames:


CLERIC_COMMAND => go
CLERIC_HOLD_PERSON => jump
WIZARD_CONFUSION => in
SPWI506 => a_lake

I need to perform some operations on each spell that is found in the game:


ACTION_PHP_EACH d5_array AS spell => act BEGIN 
	ACTION_IF (FILE_CONTAINS_EVALUATED (~SPELL.IDS~ ~[ %TAB%]%spell%[ %TAB%%LNL%%MNL%%WNL%]~)) BEGIN
		LAF RES_NUM_OF_SPELL_NAME STR_VAR spell_name = ~%spell%~ RET spell_res END
		ACTION_IF (FILE_EXISTS_IN_GAME ~%spell_res%.spl~) BEGIN
			OUTER_SPRINT spl ~%spell_res%~
		END
	END
	ACTION_IF (FILE_EXISTS_IN_GAME ~%spell%.spl~) BEGIN
		OUTER_SPRINT spl ~%spell%~
	END
	ACTION_IF !(FILE_CONTAINS_EVALUATED (~SPELL.IDS~ ~[ %TAB%]%spell%[ %TAB%%LNL%%MNL%%WNL%]~)) && !(FILE_EXISTS_IN_GAME ~%spell%.spl~) BEGIN
		OUTER_SPRINT spl ~bleh~
	END
	ACTION_IF (FILE_EXISTS_IN_GAME ~%spl%.spl~) BEGIN  
		COPY_EXISTING ~%spl%.spl~ ~override~ 	
			PATCH_IF (~%act%~ STRING_EQUAL_CASE ~jump~) BEGIN 
			...
			END
			PATCH_IF (~%act%~ STRING_EQUAL_CASE ~a_lake~) BEGIN 
			...
			END
		BUT_ONLY
	END
END

I feel like I have enough conditions in there that it should smoothly omit any nonexistent spells.  But I'm getting the dreaded "Invalid spell number: -1" error, meaning RES_NUM_OF_SPELL_NAME failed.

Why does it have to be so ornery??  Why must it stop the entire installation?  If it doesn't find a valid IDS reference, why not just skip the function and move on?

Suggestions?  Is this function anywhere where I can modify it and use the altered version?  Is @Wisp around to consider changing it to fail a bit more gracefully?  Like, if the conditions aren't sound, just set the returned variables to "invalid" or "-1" or something.  Then let the modder add a sanity check to make sure the result it usable.  I cannot for the life of my see the value in shutting down a whole installation for this kind of failure.

 

 

Edited by subtledoctor
Link to comment
Quote

DEFINE_ACTION_FUNCTION RES_NUM_OF_SPELL_NAME_SAFE STR_VAR spell_name="" RET spell_num spell_res success

BEGIN

        ACTION_IF IDS_OF_SYMBOL (spell "%spell_name%")>=0 BEGIN

                 LAF RES_NUM_OF_SPELL_NAME STR_VAR spell_name RET spell_num spell_res END

                 OUTER_SET success=1

        END ELSE BEGIN

                 OUTER_SET spell_num="-1"

                 OUTER_SPRINT spell_res "%spell_name%"

                 OUTER_SET success=0

        END

END

 

 

(Not tested.)

Link to comment

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...