Difference between revisions of "User:Renegade"

From LGPedia
Jump to: navigation, search
(Added some common tag groups and code snippets so I don't have to reconstruct them on each new template.)
(Generic way to safeguard an expression: Improved version)
Line 104: Line 104:
 
===Generic way to safeguard an expression===
 
===Generic way to safeguard an expression===
 
This code can be used to protect parameters in mathematical templates, to make sure the input is either numerical or a valid expression.
 
This code can be used to protect parameters in mathematical templates, to make sure the input is either numerical or a valid expression.
<pre>{{#ifeq: {{#ifexpr: {{{1}}} |true}} | true | Is expression | Is not an expression}}</pre>
+
<pre>{{#ifeq: {{#ifexpr: {{{1}}} |true|true}} | true | Is expression | Is not an expression}}</pre>
If <nowiki>{{{1}}}</nowiki> is not an expression, ifexpr returns an error, the error unequals "true", and thus the false part of ifeq is executed; otherwise, ifexpr returns true, ifeq determines that "true" == "true", and executes its true part. Only caveat is that the false part is also triggered when the expression itself is false, because no error is generated (as the expression is valid), but "" (non-existent false of ifexpr) unequals "true".
+
This code works by having ifeq determine whether the output of ifexpr is the string "true", and determining the output based on the outcome. ifexpr always returns "true" if <nowiki>{{{1}}}</nowiki> is a valid expression, no matter if said expression itself is true or false. If the expression is ''not'' valid, ifexpr generates an error string, which unequals "true" and thus triggers ifeq's false part.
  
 
===Logical AND, OR, XOR===
 
===Logical AND, OR, XOR===

Revision as of 16:18, 6 December 2007

Linklist

Just for my personal convenience.

Fonts

Lonelygirl15: Giza ThreeFive
Hymn Of One: Bickham Script

Episode Page Framework

{{Blog
| name        = {{PAGENAME}}
| number      = 
| image       = 
| caption     = 
| blogger     = 
| date        = {{subst:CURRENTMONTHNAME}} {{subst:CURRENTDAY}}, {{subst:CURRENTYEAR}}
| url         = {{lg15|}}
| forumid     = 
| length      = 
| description = 
| location    = 
| tags        = {{tags|}}

<!-- Production Credits leave blank after "=" if data is not available -->


| execprod    =
| coexecprod  =
| assocprod   =
| serprod     =
| producers   =
| lineprod    =
| supprod     =
| directors   = 
| camera      =
| vidplay     =
| headwriter  =
| story       =
| editor      =
| pm          =
| ps          =
| pa          =
| pr          =
| ipa         =
| animation   =
| prodserv    =
| music supervisor =

| song = 
| cast = {{VidChar|}}

| Previous = 
| Next = 

| PreviousB = 
| NextB = 
| PreviousC = 
| NextC = 
}}
{{EpHeader|}}

==Transcript==
{{transcript incomplete}}

==Notes==

Portal New Vid Template

{{Vid
|name         = 
|number       = 
|image        = 
|description  = 
|blogger      = 
|date         = {{subst:CURRENTMONTHNAME}} {{subst:CURRENTDAY}}, {{subst:CURRENTYEAR}}
|url          = {{lg15|}}
|forumurl     = 
|new          = yes
}}

Snippets

Common sets of tags

  • Primary group: {{tags|lonelygirl15|lg15|danielbeast|daniel|jonas|jonastko|soccerstar|hymnofone|order}}
  • {{tags|lonelygirl15|LG15|daniel|danielbeast|jonas|jonastko|emma|bree|train|serum|trait|positive|negative}}
  • {{tags|lonelygirl15|bree|danielbeast|daniel|jonastko|jonas|lg15|hymn|of|one|order}}
Variant: {{tags|lonelygirl15|lg15|bree|daniel|danielbeast|jonas|jonastko|hymn|of|one|order}}
  • {{tags|lonelygirl15|lg15|danielbeast|daniel|jonastko|jonas|soccerstar|hymnofone|theorder|bree}}
Subset: {{tags|daniel|danielbeast|jonas|jonastko|lg15|lonelygirl15|soccerstar}}
  • {{tags|lonelygirl15|lg15|bree|danielbeast|daniel|jonastko|jonas|soccerstar4ever}}
Variant: {{tags|lonelygirl15|LG15|daniel|danielbeast|jonas|jonastko|soccerstar4ever|bree}}
  • With Sonia: {{tags|lonelygirl15|lg15|daniel|beast|jonastko|sonia|order|hymn|of|one}}

Generic way to safeguard an expression

This code can be used to protect parameters in mathematical templates, to make sure the input is either numerical or a valid expression.

{{#ifeq: {{#ifexpr: {{{1}}} |true|true}} | true | Is expression | Is not an expression}}

This code works by having ifeq determine whether the output of ifexpr is the string "true", and determining the output based on the outcome. ifexpr always returns "true" if {{{1}}} is a valid expression, no matter if said expression itself is true or false. If the expression is not valid, ifexpr generates an error string, which unequals "true" and thus triggers ifeq's false part.

Logical AND, OR, XOR

For the moment, the only way to create logical ANDs, ORs or XORs seems to be nested ifs and ifeqs inside an ifexpr. In this technique, we are outputting 1s and 0s depending on the state of our parameters, and thereby create a normal expression solvable by ifexpr. All examples can be combined, subgroups can be created through parenthesis, and parameter names and control values can be replaced, as long as it happens consistently throughout the entire expression.

Pieces

  • {{ #ifeq: {{{1}}} | CONTROL VALUE | 1 | 0 }}
  • {{ #if: {{{1|}}} | 1 | 0 }}
  • {{ #ifexpr: EXPRESSION | TRUE | FALSE }}

Test on state

  • Logical AND: {{ #ifexpr: {{ #if: {{{1|}}} | 1 | 0 }} and {{ #if: {{{2|}}} | 1 | 0 }} | TRUE | FALSE }}
Returns TRUE if both {{{1}}} and {{{2}}} are defined.
  • Logical OR: {{ #ifexpr: {{ #if: {{{1|}}} | 1 | 0 }} or {{ #if: {{{2|}}} | 1 | 0 }} | TRUE | FALSE }}
Returns TRUE if either {{{1}}} or {{{2}}} or both are defined.
  • Logical XOR: {{ #ifexpr: {{ #if: {{{1|}}} | 1 | 0 }} != {{ #if: {{{2|}}} | 1 | 0 }} | TRUE | FALSE }}
Returns TRUE if either {{{1}}} or {{{2}}} but not both are defined.

Test on control value

In this example, the control value is "yes".

  • Logical AND: {{ #ifexpr: {{ #ifeq: {{{1}}} | yes | 1 | 0 }} and {{ #ifeq: {{{2}}} | yes | 1 | 0 }} | TRUE | FALSE }}
Returns TRUE if both {{{1}}} and {{{2}}} are set to "yes".
  • Logical OR: {{ #ifexpr: {{ #ifeq: {{{1}}} | yes | 1 | 0 }} or {{ #ifeq: {{{2}}} | yes | 1 | 0 }} | TRUE | FALSE }}
Returns TRUE if either {{{1}}} or {{{2}}} or both are set to "yes".
  • Logical XOR: {{ #ifexpr: {{ #ifeq: {{{1}}} | yes | 1 | 0 }} != {{ #ifeq: {{{2}}} | yes | 1 | 0 }} | TRUE | FALSE }}
Returns TRUE if either {{{1}}} or {{{2}}} but not both are set to "yes".