(This topic is archived. Please do not edit this page!)
I didn't know how to ask this, but I think you'll get what I'm speaking about with a simple example:
{{RaceIcon|<<race>>|<<gender>>}}
As you see, this template has some folders that make the template show different things depending on the value they have.
My question is: How do I write the code for defining those folders?
What I want to make is an userbox that, depending on the number you put, changes a word in the text and shows a different image. I could make different templates for each case, but they are many and I think this could be a better option, and also easier to understand by the users.
I suspect it's related with the type of coding; if I'm right, just translate me the ways of putting "if"s and the basic commands. I know enough programming to get the code idea, but I don't know anything about the language.
It's something I always wanted to know, and I think this could be the perfect chance to get to know how to, and be able to build better ones in the future .--Lon-ami (talk) 19:46, October 11, 2009 (UTC)
Switching with values between two numbers[]
Ok, so I got to understand this, more or less.
Now, I only don't know how to, instead of this:
- {{#switch:{{lc:{{{1}}}}}
- |1=AAA
- |2=AAA
- |3=AAA
- |4=AAA
- |5=BBB
- |6=BBB
- |7=BBB
- |8=BBB}}
Make something like this (rough):
- {{#switch:{{lc:{{{1}}}}}
- |1 to 4=AAA
- |5 to 8=BBB}}
I want to work with high values (1-50, 50-100, 100-250, 250-500, 500-1000, 1000-2500...) and I don't know how to build those ranges :S. I'm sure it's pretty simple, but I fail to find the solution.
I need it for 2 things:
- Display a text depending on number range.
- Display a image depending on number range (I don't know if images need a special code or something for working properly).
Thanks!--Lon-ami (talk) 18:44, October 26, 2009 (UTC)
- You may want to use #ifexpr rather than #switch in this case. Or maybe you can combine the two, but I've never done it. -- Fandyllic (talk · contr) 10:33 PM PST 26 Oct 2009
- I think I'll just go for "nested" (dunno if it's well said) ifs, something like this:
- {{#ifexpr: X > 0 | {{#ifexpr: Y > 0 | both x and y are bigger than 0 | only x is biger than 0}} | x isn't bigger than 0}}
- I suspect #ifexpr is not supported on WoWWiki. I tried to get it to work on a test template, but it kept giving me an error. I also noticed our version of ParserFunctions is 1.1.1, but the one running on mediawiki.org is 1.3.0.
- You could try using:
{{#ifeq: {{#expr: expression }} | 0 | value if false | value if true }}
- It is supposed to be the equivalent. I made a test range checking template at User:Fandyllic/rangetest as an example to try out some range checking.
{{:User:Fandyllic/rangetest|0}}
- Output: Number is 0 or negative
{{:User:Fandyllic/rangetest|3}}
- Output: Number is 1 to 5
{{:User:Fandyllic/rangetest|8}}
- Output: Number is 6 to 10
{{:User:Fandyllic/rangetest|15}}
- Output: Number is greater than 10
- -- Fandyllic (talk · contr) 6:01 AM PST 1 Nov 2009
- WHoA, thanks a lot. So it was that, damn, and me trying and trying with the damn ifexpr. It doesn't matter, it works now, an d that's what matters :P.
- Anyway, just as a curiosity, what is that | 0 | for?
- That's all. I'm gonna check if it works properly with images now, and will return else to show the finished template or more doubts .--Lon-ami (talk) 15:28, November 3, 2009 (UTC)
- Yeah, it seems the true and false folders switch between them. Anyway, implemented it with anything (guess it reads as default 1) and everything worked fine. This was just an experiment to try these functions, but I'm definitely going to apply these anywhere I see it can be applied :
This user is ranked Elune with 5826 posts at Scrolls of Lore! |