if ( true ? then : else) if (true ? then) || else
Hi everyone,--I took a few hours to create a new version 0.5.5 of tobibeer/setvars.Get the update from here:This allows the setvars widget to declare variables leveraging basic conditionals using either of...
- OR logic
this || that || another » takes the first value that is non-empty and then stops- IF clauses
IF( condition ? then-value : else-value ) » the condition is interpreted as true if it evaluates to non-empty
» you can use OR logic within any of the IF clause statementsBest wishes,Tobias.
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/01394670-dcf8-4700-85d6-f3300f9dcfc7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
What kind of uses could this development be put to?
; setvars
: <$setvars uuid="[id]" _id="[make[%uuid%]]"><<uuid>></$setvars>
; set
: <$set name="uuid" filter="[make[%uuid%]]"><<uuid>></$set>Setvars and evalThe idea could involve setvars and eval... what follows is largely dependant on my understanding of what setvars and eval could do.10) compare two "created fields" - set a variable20) take one away from another - eval30) if the result of eval is X, then make the TW do something, otherwise do something else
if(condition?then) || elseif(condition?then:else)This macro routes a link to tiddlywiki.com should there not be a local tiddler by that name while also allowing you to use a pretty title:
\define route(title,pretty) <$setvars _exists="[[$title$]is[tiddler]]" _not="[[$title$]!is[tiddler]]" title="if( \$pretty$\ ? \$pretty$\ ) || \$title$\" link=" if( [exists] ? \[[\title\|$title$]]\ ) || if( [not] ? \[ext[\title\|http://tiddlywiki.com#$title$]]\ )"> <<link>> </$setvars> \end
--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/85d4b6a3-5b96-4920-aae5-d30840efcb95%40googlegroups.com.
How to write CalsFromCarbs variable to a tiddler field
<$set name="CalsFromCarbs" filter="[[]eval[{{Carbo-needs!!kcal-per-day}}*{{Carbo-needs!!carbo-percent}}/100]]"><$button set="!!kcal-carbs" setTo=<<CalsFromCarbs>>>set ''kcal-carbs'' to <<CalsFromCarbs>></$button></$set>
; kcal-carbs: {{!!kcal-carbs}}title: Carbo-needs
kcal-per-day: 2500
carbs-percent: 45
kcal-carbs: <$eval>{{Carbo-needs!!kcal-per-day}}*{{Carbo-needs!!carbs-percent}}/100</$eval>
{{Carbo-needs!!kcal-carbs}}<$list filter="[[]eval{eval-Examples!!cubed}]"/>--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/67d6d372-6a87-455e-bfb9-f597390ab2a1%40googlegroups.com.
Do you think it would be worth creating a calcs tiddler with common calcs, such as squared, percent?
\define ++(val) <$eval>{{$val$}}+1</$eval>
<<++ !!myfield>>
kcal-carbs: <$eval>{{Carbo-needs!!kcal-per-day}}*{{Carbo-needs!!carbs-percent}}/100</$eval><$eval>{{Carbo-needs!!kcal-carbs}}*2</$eval>title: $://total-price
<$eval>({{!!price}} + {{!!shipping}}) * (1+{{$:/finance/tax-rates!!vat}}/100)</$eval>
title: Basket
total: {{||$://total-price}}
Much nicer syntax -- declare all your variables first -- then use them in your calculations \o/
@Jeremy, When and Why are we forcing field-names to be lowercase?
Also, if we are forcing fields to be all-lowercase,then tiddler.getFieldsString must always turn a requested field to lowercase first! => ticket?
Also, if we are forcing fields to be all-lowercase,then tiddler.getFieldsString must always turn a requested field to lowercase first! => ticket?
var trimmedName = name.toLowerCase().trim();If you request a change in the TW core API, I think, you should raise a new ticket. ... since the above one is a "question ticket"
[[$:/Some/System/Tiddler-With-A-Colon]]: the value for itexports.addField = function(tiddler,name,value) {
var trimmedName = name.toLowerCase().trim();
if(!$tw.utils.isValidFieldName(trimmedName)) {
if(!hadInvalidFieldName) {
alert($tw.language.getString(
"InvalidFieldName",
{variables:
{fieldName: trimmedName}
}
));
hadInvalidFieldName = true;
return;
}
} else {
if(!value && tiddler) {
value = tiddler.fields[trimmedName];
}
addition[trimmedName] = value || "";
}
return;
};