Author Topic: Tricking WeiDU into allowing FOR/WHILE loops 'outside' of patch commands  (Read 5324 times)

Offline Wounded_Lion

  • Planewalker
  • *****
  • Posts: 208
  • Gender: Male
  • Dungeon Dweller
For a private, for-fun Nymph kit (that will not have a public release), I designed an innate ability called "Kiss of Death".  The ability creates a magical weapon that causes 4 damage per level of the Nymph with a save vs. breath for half.  I didn't want to create 40 items manually or by 40 seperate patch commands (call me lazy... or efficient  8) ).  I wanted to use a FOR loop to create the items for me.  But... WeiDU will not allow a FOR or WHILE loop outside of a patch-type command.  So... I created this workaround (which saves time and decreases tp2 size):

Quote

COPY ~Nymph/WLKISSD.ITM~ ~override/WLKISSD.ITM~
 FOR ( index = 1 ; index < 41 ; index = index + 1 ) BEGIN
  INNER_ACTION BEGIN
   COPY ~Nymph/WLKISSD.ITM~ ~override/WLKISS%index%.ITM~
    SAY NAME2 @3
    WRITE_LONG 0xAE ("%index%" * 2)
    WRITE_LONG 0xDE ("%index%" * 2)
  END // INNER_ACTION
 END // FOR


The first copy command is meaningless:  it simply copies the item template into the override directory.

Skilled modders can figure out the rest without a lengthy explanation from me.

Do I get bonus points from Japeth for finding a way to use INNER_ACTION BEGIN in my mod? ;D

a Wounded Lion

Offline the bigg

  • The Avatar of Fighter / Thieves
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
As I have just pointed out on G3, I can code OUTER_FOR, OUTER_SET, OUTER_SPRINT and OUTER_PATCH[_SAVE] for these types of needs.

And, if you want to keep to your workaround, you'd better use
COPY_EXISTING ~sw1h01.itm~ ~override~
  DO_YOUR_STUFF
BUT_ONLY_IF_IT_CHANGES
Author or Co-Author: WeiDU (http://j.mp/bLtjOn) - Widescreen (http://j.mp/aKAiqG) - Generalized Biffing (http://j.mp/aVgw3U) - Refinements (http://j.mp/bLHoCc) - TB#Tweaks (http://j.mp/ba02Eg) - IWD2Tweaks (http://j.mp/98OFYY) - TB#Characters (http://j.mp/ak8J55) - Traify Tool (http://j.mp/g1Ry9A) - Some mods that I won't mention in public
Maintainer: Semi-Multi Clerics (http://j.mp/9UeIwB) - Nalia Mod (http://j.mp/dng9l0) - Nvidia Fix (http://j.mp/aRWjjg)
Code dumps: Detect custom secondary types (http://j.mp/hVzzXG) - Stutter Investigator (http://j.mp/gdtBn8)

If possible, send diffs, translations and other contributions using Git (http://j.mp/aBZFrq).

Offline Wounded_Lion

  • Planewalker
  • *****
  • Posts: 208
  • Gender: Male
  • Dungeon Dweller
Can you link me to it?  I am not familiar with your post.  Nevermind.   ;)

Also, why copy the sword file instead of the item template?  It might save a *tiny* bit of space, I suppose.  I know that my code works because I have tested it repeatedly.

a W.L.

*edited*

Offline the bigg

  • The Avatar of Fighter / Thieves
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
Can you link me to it?  I am not familiar with your post.
http://forums.gibberlings3.net/index.php?showtopic=5076&view=getnewpost, if you haven't seen it by now (it was a direct reply to your thread there)

Quote
Also, why copy the sword file instead of the item template?  It might save a *tiny* bit of space, I suppose.  But I know that my code works because I have tested it repeatedly.
Because when doing this you should always copy a file that is in no way related to ones you're dealing with (accidental changes in one part of the code might have bad effects on subsequent parts, and so on.
Author or Co-Author: WeiDU (http://j.mp/bLtjOn) - Widescreen (http://j.mp/aKAiqG) - Generalized Biffing (http://j.mp/aVgw3U) - Refinements (http://j.mp/bLHoCc) - TB#Tweaks (http://j.mp/ba02Eg) - IWD2Tweaks (http://j.mp/98OFYY) - TB#Characters (http://j.mp/ak8J55) - Traify Tool (http://j.mp/g1Ry9A) - Some mods that I won't mention in public
Maintainer: Semi-Multi Clerics (http://j.mp/9UeIwB) - Nalia Mod (http://j.mp/dng9l0) - Nvidia Fix (http://j.mp/aRWjjg)
Code dumps: Detect custom secondary types (http://j.mp/hVzzXG) - Stutter Investigator (http://j.mp/gdtBn8)

If possible, send diffs, translations and other contributions using Git (http://j.mp/aBZFrq).

Offline Wounded_Lion

  • Planewalker
  • *****
  • Posts: 208
  • Gender: Male
  • Dungeon Dweller
Interesting.  I suppose you might be right.  Though no actual changes are made to the template...  Anyway, thank you for the advice.

In truth, my technique is useful in only a relatively small number of situations (usually kit components).  I thought I'd share just in case someone else needed just such a technique.

a W.L.

btw - I always visit PPG before G3.  So I hadn't seen your reply.   ;)

Offline the bigg

  • The Avatar of Fighter / Thieves
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
Interesting.  I suppose you might be right.  Though no actual changes are made to the template...  Anyway, thank you for the advice.
Since people will learn how to program while doing mods (I sure did), it's advisable to pick up on how many good habits is possible: for example, assuming that erroneous file changes might happen, so redirect them to a dummy file or whatever. (of course, making sure that no file changes happen would be better, but that isn't so easy in a 100,000 something project like it is in a 4000 lines tp2  :)

Quote
In truth, my technique is useful in only a relatively small number of situations (usually kit components).  I thought I'd share just in case someone else needed just such a technique.
There are a number of situations where this would be useful apart from that example, such as creating a variable which is destined to appear in a file name, etc. (for an example, see the \n workaround http://dev.gibberlings3.net/index.php/Common_Code#Emulating_.5Cn_in_WeiDU here (note: requires g3 forum login).
Author or Co-Author: WeiDU (http://j.mp/bLtjOn) - Widescreen (http://j.mp/aKAiqG) - Generalized Biffing (http://j.mp/aVgw3U) - Refinements (http://j.mp/bLHoCc) - TB#Tweaks (http://j.mp/ba02Eg) - IWD2Tweaks (http://j.mp/98OFYY) - TB#Characters (http://j.mp/ak8J55) - Traify Tool (http://j.mp/g1Ry9A) - Some mods that I won't mention in public
Maintainer: Semi-Multi Clerics (http://j.mp/9UeIwB) - Nalia Mod (http://j.mp/dng9l0) - Nvidia Fix (http://j.mp/aRWjjg)
Code dumps: Detect custom secondary types (http://j.mp/hVzzXG) - Stutter Investigator (http://j.mp/gdtBn8)

If possible, send diffs, translations and other contributions using Git (http://j.mp/aBZFrq).

Offline Ghreyfain

  • Moderator
  • Planewalker
  • *****
  • Posts: 4705
  • Gender: Male
    • Pocket Plane Group
Would the sword even get copied, with B_O_I_I_C in there?  Or does WeiDU consider the INNER_ACTION of another item getting patched a change?  Or does it run the INNER_ACTION, and then not bother copying the sword because it hasn't changed, but the I_A still gets run?
Earn Money Sleeping.

Offline the bigg

  • The Avatar of Fighter / Thieves
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
Would the sword even get copied, with B_O_I_I_C in there?  Or does WeiDU consider the INNER_ACTION of another item getting patched a change?  Or does it run the INNER_ACTION, and then not bother copying the sword because it hasn't changed, but the I_A still gets run?
B_O_I_I_C means that the sword item doesn't get copied because it isn't changed (to be precise, Weidu saves a copy of the loaded file and confronts it with the result of all patches).
Also,
Code: [Select]
COPY_EXISTING ~kit.ids~ ~override~
  INNER_ACTION BEGIN
  APPEND ~kit.ids~ ~a_string~
  END
the relevant part is the outer one, except in the one case that the outer part has B_O_I_I_C and the file didn't change, in which case the relevant part is the inner one.

in this example, the APPEND is not saved to the file.

BTW, I coded OUTER_FOR as an action containing actions, so this discussion is a bit moot  :)
Author or Co-Author: WeiDU (http://j.mp/bLtjOn) - Widescreen (http://j.mp/aKAiqG) - Generalized Biffing (http://j.mp/aVgw3U) - Refinements (http://j.mp/bLHoCc) - TB#Tweaks (http://j.mp/ba02Eg) - IWD2Tweaks (http://j.mp/98OFYY) - TB#Characters (http://j.mp/ak8J55) - Traify Tool (http://j.mp/g1Ry9A) - Some mods that I won't mention in public
Maintainer: Semi-Multi Clerics (http://j.mp/9UeIwB) - Nalia Mod (http://j.mp/dng9l0) - Nvidia Fix (http://j.mp/aRWjjg)
Code dumps: Detect custom secondary types (http://j.mp/hVzzXG) - Stutter Investigator (http://j.mp/gdtBn8)

If possible, send diffs, translations and other contributions using Git (http://j.mp/aBZFrq).

 

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Name: Email:
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:
What color is grass?:
What is the seventh word in this sentence?:
What is five minus two (use the full word)?: