*if in *stats


#1

I’m working on my stats-screen at the moment.

I would like to have a stat screen where the information changes, while you are playing the game.
That means that I do not only want to add your name not until you wrote your name but I want to stay the variable *name to stay hidden.

So, I thought I could write an *if function like that
*stat_chart .....*if (knowname) ..........text name .....text strength .....text whatever

but it looks like you can’t write *if in *stat_chart…
any ideas?

(how can I write the code in the forum s.t. it’s all in one box… and not each line in another box?)


#2

It’s not possible (AFAIK); you’ll need to use separate *stat_chart (s), as you can only hide or show the entire chart.


*if (condition)
 *stat_chart
*if (condition2)
 *stat_chart

You can however just write plain old text as normal, for e.g.:


*if (name)
 [b]Name:[/b] ${character_name}

Would that not suit your purposes?


#3

Oh, yes… very simple, very smart.
Thank you.


#4

My personal preferred method of this is to put the *ifs above the stat chart, where one after another they *goto each other to check if they are true and then eventually hit the stat chart.

`
*if (condition)
*set stat “true”
*goto statChart
*else
*set stat “false”
*goto statChart

*label statChart
*stat_chart
text stat
`

You can of course add more *ifs, you just have to put them under the label and make a new label for going to the stat chart.


#5

This problem has been bugging me as well. The problem with multiple stat chats is that the bars don’t line up. I’d like to display a bar stat if it isn’t zero. So, as the game progresses, more and more bars show as the MC learns skills. But, if I do multiple charts, the bars don’t line up.


#6

@Lucid Multiple charts line up just fine for me, the code is nothing more than this (same indentation):

`
*stat_chart
percent Leadership

*stat_chart
percent Leadership

*stat_chart
percent Leadership
`

That’ll give you three identical inline bars, each below the last, and each able to be hidden by its own *if.


#7

The problem is in the length of the labeled words, try this:

*stat_chart

…percent SuperDuperLongWord

*stat_chart

…percent ShortWord


#8

@Lucid - That’s true, it might be worth reporting that.


#9

@CJW Ah, I always forget that most authors here are aiming to get their games hosted by CoG - yeah, if that’s the case then it definitely wouldn’t work.


#10

Don’t think that’s a bug - there is a function “stat_chart” which includes bars that line up.
If you write “*stat_chart” twice you run two functions that both do the same with the variables each of them include.

I don’t think that it would be very easy to change the function so that it checks if there are other *stat_charts, then include the variables of those into the line up of the new variables…

Much easier to me sounds include the possibility of “if” for the list of variables.


#11

@loelet - It’s not a bug, it’s what you might call an oversight.
It doesn’t break anything but it would be MORE convenient if we could either *if items in a stat list or keep all stats lists aligned the same (and *if entire charts).

I could it do something myself but if it’s not an official solution, CoG probably won’t port it.


#12

This is off the top of my head, but could you “band-aid” it by adding to style.css:

.leftStatName {width:200px;}
  • replacing “200px” with some width equal to or longer than the width of your longest stat name? I think that’d line up the left edges of all the stat bars across charts.

However doing that wouldn’t be officially supported by CoG, and you’d have to go back and change it if you made any of the stat names longer. So I don’t know if I’d recommend it unless you’re comfortable with CSS…


#13

@aetheria The reason you shouldn’t do it is because if CoG want to patch something, they patch all their games (for obvious reasons) - if you’ve got a tailored style.css or similar file, when they patch it - it’ll be overwritten with the vanilla one and start breaking stuff. They don’t have the time to individually patch games with modifications - the only thing they could do here is make the author responsible for all patches, but that has its own set of problems.


#14

I’ve a problem with the *if in the stats, my game have perks player could acquire if perk are true well I cant stop all perks read true for instance nocturnal true in my stats I have:
*if nocturnal
--------*stat_chart
----------------text nocturnal Nocturnal


#15

@MaraJade

That should work.

Are all the perks defined in mygame and set to false?


#16

yes they are defined that way and work fine without errors. the only problem is the people see the true word in the stats text and I don’t want that.


#17

That’s very odd as long as you only mention true in the if line it should work try putting ( ) around the variable see if that works?


#18

still the same true text maybe I left that way like a joke of some sort is really funny


#19

Why do you want to use “*stat_chart” for that?

Just write:
*if nocturnal
----Nocturnal

What you describe is absolutely normal.
“stat_chart” lists the values of the variables. If you ask for the value of “nocturnal” it gives you:

Nocturnal TRUE”
like
Nocturnal 43”

…that’s exactly what it should do.


#20

“text x y” in stat_chart is just another way of writing:

y ${x}

… by the way.
The reason why “text …” is cooler than the second thing is that also not even “text x” means
x ${x}

which is much shorter but also “text IwRiTeSomEthInGHEre” would mean
IwRiTeSomEthInGHEre ${iwritesomethinghere}.

So in your example there is no need to write an extra “Nocturnal” with a large “N”… (or an extra nocturnal with a small one) - since CS knows that Nocturnal, nocturnal, NoCtUrNaL all refer to the same variable “nocturnal”. So, “text Nocturnal” is all you need to get
Nocturnal true”