Jump to content

What' wrong with this code ?


Recommended Posts

Posted (edited)

I'm trying to create a spell that removes summoning spells from a kit. I'm using this code to find out if we're on IWDEE or if IWDEE spells are installed. But it writes" SPELL_RE" as the resource to delete. What's wrong?

OUTER_SET spell_num = IDS_OF_SYMBOL (~spell~ ~CLERIC_GIANT_INSECT~)
	ACTION_IF (spell_num >= 0) THEN BEGIN
	   LAF RES_NAME_OF_SPELL_NUM INT_VAR spell_num RET spell_res END
	   ACTION_IF FILE_EXISTS_IN_GAME "%spell_res%.spl" BEGIN
	   COPY_EXISTING  ~pxdelm0.spl~  ~override~    LPF ADD_SPELL_CFEFFECT INT_VAR opcode = 172 target = 1  STR_VAR resource = %spell_res% END
	   END
	END

Edited by deratiseur
Posted

The truncation is, of course, because resource names are capped at eight characters. But what's really going on here is that you have a "failed to evaluate variable" error.

And looking at the WeiDU documentation ... %% are mentioned as a valid string delimiter in the section on the .D format. I suspect that's also true in the broader language. So when you say "STR_VAR resource = %spell_res%" and the parser sees %spell_res% where it expects a string, the %% are interpreted as string delimiters and the literal string "spell_res" is passed to the function.

To fix it, add string delimiters around that %spell_res": "STR_VAR resource = ~%spell_res%~" should work.

Posted
55 minutes ago, jmerry said:

To fix it, add string delimiters around that %spell_res": "STR_VAR resource = ~%spell_res%~" should work.

You'll also have to add the EVAL keyword (unless the mod uses the AUTO_EVAL_STRINGS directive.)

OUTER_SET spell_num = IDS_OF_SYMBOL (~spell~ ~CLERIC_GIANT_INSECT~)
ACTION_IF (spell_num >= 0) THEN BEGIN
  LAF RES_NAME_OF_SPELL_NUM INT_VAR spell_num RET spell_res END
  ACTION_IF FILE_EXISTS_IN_GAME "%spell_res%.spl" BEGIN
    COPY_EXISTING  ~pxdelm0.spl~  ~override~
      LPF ADD_SPELL_CFEFFECT
        INT_VAR opcode = 172 target = 1
        STR_VAR resource = EVAL "%spell_res%"
      END
  END
END

 

Posted

Yeah. AUTO_EVAL_STRINGS is something I pretty much always use, to the point it "goes without saying" ... but it shouldn't. It, or the EVAL, needs to be said.

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...