Problem with quotes

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
Nathnem
Kobold
Posts: 7
Joined: Sat May 27, 2017 3:12 pm

Problem with quotes

Post by Nathnem »

Can someone please help a noob and explain to me why:

Code: Select all

<input type="[DataType]">
works, but

Code: Select all

["<input type="" + DataType + "">"]
does not?

The code prints out correctly but is ignored by the html compiler and does not create the input field as soon and you use " (or anything but ").
Why? Also is there an escape character or another substitution, I've tried \", ", and "

I don't know if it matters but I'm using v1.4.0.5

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Problem with quotes

Post by aliasmask »

One is a quote and the other is an html entity representation of a quote and has two different meanings to the compiler. Also, if you don't use [r: ] then MT will put in extraneous characters in the html string. Using "&#34" does work in some instances like when creating a tooltip. I'm not sure if that is a compiler exception or not. I would try this:

Code: Select all

[r: '<input type="' + DataType + '">']
OR

Code: Select all

[r: strformat('<input type="%{DataType}">')]

Nathnem
Kobold
Posts: 7
Joined: Sat May 27, 2017 3:12 pm

Re: Problem with quotes

Post by Nathnem »

Thank you for your response, and I am aware the need for the [r: requirement (I forgot it in my example). To get around it I just wrote a simple function (that needs updating to support parameter by input type but works for now.)

Code: Select all

[h: InputInfo = macro.args]

<input type="[r: listGet (InputInfo, 0)]"

[r, switch(listCount(Inputinfo)), CODE:
case "1": {> };
case "2": { name="[r: listGet (InputInfo, 1)]"> };
case "3":
{
    name="[r: listGet (InputInfo, 1)]"
    value="[r: listGet (InputInfo, 2)]">
};
default: {> ERROR - Too many parameters.}]
I did not know that using a ' allows the use of " without errors, that will be very helpful and I'll take a close look at the strformat() function as I can see it'll be very useful. I haven't worked with tooltips yet.
Last edited by Nathnem on Sun May 28, 2017 10:29 pm, edited 1 time in total.

Nathnem
Kobold
Posts: 7
Joined: Sat May 27, 2017 3:12 pm

Re: Problem with quotes

Post by Nathnem »

The problem code snippet is:

Code: Select all

...
[h: bonusSkills = table(Species, (Breed * 10)+2)]
[h: tblData = ""]
[r, foreach(i, bonusSkills, "", "~"), CODE:
{ 
    [r: tblData  = tblData + "<tr><td>+" + listGet(i, 0) + " to " + listGet(i, 1) + "</td><td>"]
    [r, for (x, 3, listCount(i), +1, ""): tblData = tblData + "<input type="radio" name="" + listGet(i, 1) + "" value="" + listGet(i, 2) + ":" + listGet(i, x) + " " + listGet(listGet(Skills, listGet(i, 2), "~"), listGet(i, x)) + ""><br>"]
    [r: tblData = tblData + "</td></tr>"]
}]
-->

[bonusSkills]
<table border="1">
<tr><th colspan="2">Breed Skills</th></tr>
<tr><th>Bonus Skills</th><th>Options</th></tr>
[r: tblData]

</table>
...
Originally I didn't use the tblData var and had the foreach nested for loop directly in the table but added the var later trying to get it to work.

Post Reply

Return to “Macros”