How to add fields with spaces to all tiddlers with a certain tag (Solved)

One of the problems I have run into is with adding extra fields to tiddlers with a certain tag.

For the weapons I have solved it with the method of creating a tiddlers with all the new fields, then cloning that one and transporting the data of the old tiddler to the new one.

This was because I already had a number of tiddlers with the text, but not the 20 or so fields, as I made several example weapons with only the text describing them.

I tried using a button to add fields and that did work, but unfortunately the field names contained spaces, and the add fields function saw that as separate field names.

Now my question is, is it possible to add fields to all tiddlers with a certain tag that contain spaces?

\procedure newWeapon()
  <$action-sendmessage
    $message="tm-new-tiddler"
    title="I-"
    tags="I-Weapon"
    Legal=""
    Defense=""
    To Hit=""
    Damage Type 1=""
    Damage 1=""
    Damage Type 2=""
    Damage 2=""
    Damage Type 3=""
    Damage 3=""
    Min Might=""
    Min Talent=""
    Weapon Reach=""
    Melee Range=""
    Weapon Speed=""
    Short Range=""
    Long Range=""
    Ammo=""
    Weight=""
    Cost=""
    Breaks Into=""
    Description=""
       />
\end

<$button actions=<<newWeapon>>>
  New Weapon
</$button>

This gives field names such as 1, Weapon, Range, etc, while i wanted Damage Type 1, Weapon Reach, Melee Range, etc.

Off course I saw the excellent advice on Grok tiddly wiki on using only lower case field names after already using them…

I may switch to renaming them, but it would be nice if there was a way to avoid it as damagetype1 or weaponspeed just aren’t as clear.

On

the code above should work.

no need to copy it, the tiddler Make Weapon that contains it exists.

Thanks in advance for any help.

Give this a try:

\procedure newWeapon()
  <$let fieldlist="I-Weapon Legal Defense [[To Hit]]
    [[Damage Type 1]] [[Damage 1]]
    [[Damage Type 2]] [[Damage 2]]
    [[Damage Type 3]] [[Damage 3]]
    [[Min Might]] [[Min Talent]] [[Weapon Reach]] [[Melee Range]] [[Weapon Speed]]
    [[Short Range]] [[Long Range]] Ammo Weight Cost [[Breaks Into]] Description">
  <$action-setmultiplefields $tiddler="I-" $fields=<<fieldlist>> $values=""/>
  <$action-sendmessage $message="tm-edit-tiddler" $param="I-" />
  </$let>
\end

<$button actions=<<newWeapon>>>New Weapon</$button>

Notes:

  • $action-setmultiplefields creates the tiddler “I-” and sets all the named fields to blank
  • Note how the fieldlist uses doubled square brackets around field names that contain spaces
  • After creating the “I-” tiddler, the <<newWeapon>> procedure then uses tm-edit-tiddler to open the “I-” tiddler for futher editing.

enjoy,
-e

1 Like

Almost perfect, and already a big improvement. Thank you Already.

The Fieldnanes are generated with spaces, exactly as I wanted.

The tag I-Weapon doesn’t show up though. Not a big problem as the final version for monsters, spells, songs, etc, etc would use that tag to decide which tiddlers need to be affected.

The last step would be to change all tiddlers with a certain tag to have the fields.

For example, this lists all spells, and gives a link to the tiddler, while removing the S- prefix.

<style>
table, th, td {border: 3px solid; color: blue; text-align: center;
 }
</style>

<div style= "overflow-x: auto;">
<table>
 <tr>
     <th>Spell Name</th>
      <th>Description</th>
  </tr>
<$list filter= "[tag[Spell]]">
 <tr>
<td><$link><$text text={{{ [{!!title}removeprefix[S-]] }}}/></$link></td><td>{{!!description}}</td>
</tr>
</$list>
</table>
</div>

The only thing left is replacing $tiddler=“I-” with a list of tiddlers that tag spell.

\procedure newSpell()
  <$let fieldlist="[[Mp Cost]] [[Spell Grade]] Duration Range">

  <$action-setmultiplefields $tiddler="I-" $fields=<<fieldlist>> $values=""/>
  <$action-sendmessage $message="tm-edit-tiddler" $param="I-" 
/>
  </$let>
\end

<$button actions=<<newWeapon>>>New Weapon</$button>

Perhaps another $let statement? or can I use the $list function?

\procedure newSpell()
  <$let fieldlist="[[Mp Cost]] [[Spell Grade]] Duration Range">
  <$list filter="[tag[spell]]">
    <$action-setmultiplefields $fields=<<fieldlist>> $values=""/>
  </$list>
  </$let>
\end

<$button actions=<<newSpell>>>create spell fields</$button>

Works like a charm. Thanks again, now I know how to handle making changes to multiple tiddlers at once.