This Forum has been archived

Visit the new Forums
Forums: Index Support Requests Need help with infobox code
Fandom's forums are a place for the community to help other members.
To contact staff directly or to report bugs, please use Special:Contact.

50px-Replacement filing cabinet.svg

Note: This topic has been unedited for 1889 days. It is considered archived - the discussion is over. Do not add to unless it really needs a response.

Anyone an idea how I add an switch inside in repeat in an infobox?

this: {{#switch:{{{Hpstar}}}|0,5= Very low|1= Very low|1,5= Very low|2= Very low|2,5= Very low|3= Low|3,5= Low|4= Low|4,5= Low }}

Inside this: {{#if:{{{Hp1|}}}{{{Hp2|}}}{{{Hp3|}}}{{{Hp4|}}}{{{Hp5|}}}{{{Atk|}}}{{{Def|}}}{{{Speed|}}}{{{Crt|}}}{{{Spec|}}}|! colspan="4" style="background-color:{{#switch:{{lc:{{{Summoned}}}}}|yes=#FFFF00|no=#FF0000|#FF0000}}; color:#000000" {{!}} '''Stats''' {{!}}-}} {{#if:{{{Hp1|}}}{{{Hp2|}}}{{{Hp3|}}}{{{Hp4|}}}{{{Hp5|}}}|{{!}} colspan="2" {{!}} '''Hitpoints''' {{!}} colspan="2" {{!}}{{ #replace: {{ padleft: | {{ #expr: abs( {{{Hpstar}}} ) }} }} | 0 | [[File:Gold-star-graphic.png|15px|link=Stats|Very low: {{{Hp1}}} (T1) ; {{{Hp2}}} (T2) ; {{{Hp3}}} (T3) ; {{{Hp4}}} (T4) ; {{{Hp5}}} (T5)]] }} {{!}}-}}

--- Currently I get no error inside the code but will it result just into an empty space. So I think this will not support. Any idea how to fix it?

I used the source of the repeat template for this: {{ #replace: {{ padleft: | {{ #expr: abs( {{{2}}} ) }} }} | 0 | {{{1}}} }}

--Jens Ingels 22:13, June 11, 2012 (UTC)

It would almost certainly be helpful if you could more fully explain what you're trying to accomplish, and if you could provide a link to the template you're trying to create. I'm at a loss as to what you mean by "the repeat template", as there is no template named "repeat" in the code you've provided. There are certainly things I wouldn't do in the code you've provided — like using the raw HTML command <font color = "red"> —  but without having a better grasp of what you're trying to do, I can't really advise you.
In general, though, I will say that it's easy to nest a #switch inside an #if statement. However, #if statements are binary. They say, "If the condition of this ONE variable is something, then do this thing over here. If not, then do this other thing."
Your #if statement is beyond confusing. You're saying, "#if 10 variables exist — {{{Hp1}}} through {{{Spec}}} — then output this Stats thing." That's just not going to work. You need to focus on the condition of one variable only (or an #expr derived from a mathematical formula using several variables, but that doesn't apply here). Just looking at the code you've presented, I'd say that you wouldn't get an error, nor would you get results. Nothing will satisfy your #if statement, so the template has no choice but to produce no results.
How do you fix it? Probably quite easily — but we need you to explain your goals more clearly. czechout@fandom    fly tardis  <span style="">23:01: Wed 13 Jun 2012 

Here's the link of the template [1]. I thought that the codes that I wrote down where enouge. The infobox exist out 2 tables. 1 nav table and 1 infobox. Here's an result example [2].

The infobox is in fact an infobox inside an infobox:

{| style="clear:both;margin:0.5em auto; text-align:center; width:100%"
{| class="wikitable" style="clear:both;margin:0.5em auto; text-align:center; width:100%"

I in fact only need an solution how to let to work this: {{#switch:{{{Hpstar}}}|0,5= Very low|1= Very low|1,5= Very low|2= Very low|2,5= Very low|3= Low|3,5= Low|4= Low|4,5= Low }}

In the place of this: Very low. Btw I colored it red to point out what needed to replaced. The font code it not from the template itself.

--Jens Ingels 12:01, June 14, 2012 (UTC)

The switch above does work assuming that {{{hpstar}}} exists and is between 0,5 and 4,5. You can provide a 'not found' return and a return for when the parameter is empty. You can also combine those with like returns as well...
{{#switch: {{{Hpstar|empty}}}
  |0,5|1|1,5|2|2,5 = Very low
  |3|3,5|4|4,5 = Low 
  |empty = {{{Hpstar}}} was empty
  |#default = (what to show if {{{Hpstar}}} is not a number from 0,5 -> 4,5)
Rappy 12:32, June 14, 2012 (UTC)

It works, thx

However after adding these things, I got back an error when I put {{{hpstar}}} to 8,9 or 10. The error is not from the template but from the string: "Error: String exceeds 1,000 character limit"

{{#switch: {{{Hpstar|empty}}}
  |0,5|1|1,5|2|2,5 = Very low
  |3|3,5|4|4,5 = Low 
  |5|5,5|6|6,5 = Mid 
  |7|7,5|8|8,5 = High
  |9|9,5|10 = Very high
  |empty = 
  |#default = - Error - Category:Bugged templates

EDIT: Error example here: [3] --Jens Ingels 13:37, June 14, 2012 (UTC)

That's because your #replace is over 1,000 characters. What are you trying to do with that section? You should never have to have over 1,000 characters inside a #replace. What should show up in the HitPoints section? Rappy 19:30, June 14, 2012 (UTC)

Aw that can be an problem sinds I need al this information. Any idea how to split the repeat in two repeats so that when {{{Hpstar}}} is higher than 5 repeat 2 will automatic get activated? I think it's possible with #ifexpr. But than there need to be an limiet on {{{Hpstar}}}. Or does someone has another idea.

The hitpoints bar was en test but I don't really like it.

--Jens Ingels 20:14, June 14, 2012 (UTC)

You can always do a {{#ifexpr: {{{hpstar|0}}} > 5|<br/>{{repeat|*|{{#expr: {{{hpstar|0}}} - 5}} }} }} to separate the two and add the next row of stars. Rappy 00:06, June 15, 2012 (UTC)