Displaying objectives conditionally

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
Cheradenine
Posts: 31
Joined: December 8th, 2008, 12:24 am

Displaying objectives conditionally

Post by Cheradenine »

I'm working on a scenario with a total of 5 victory objectives. I'd like to be able to display just the objectives that haven't yet been met, but using [if] within an [objectives] tag doesn't work.

Is there any way to cause an objective to display only if a variable has a certain value?

(The alternative I see is to use 32 [if]s to cover all the possible sets of active objectives. For some reason, I'm not enthusiastic about that option.)
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Displaying objectives conditionally

Post by zookeeper »

Cheradenine wrote:I'm working on a scenario with a total of 5 victory objectives. I'd like to be able to display just the objectives that haven't yet been met, but using [if] within an [objectives] tag doesn't work.

Is there any way to cause an objective to display only if a variable has a certain value?
No.
Cheradenine wrote:(The alternative I see is to use 32 [if]s to cover all the possible sets of active objectives. For some reason, I'm not enthusiastic about that option.)
There's another alternative, but it'd be somewhat complicated and you'd have to figure out how to do it: use a single multi-line string to list several objectives (like, all the victory objectives in one string) and construct those strings before displaying the objectives using a bunch of [if]s.

Pseudocode:

Code: Select all

if obj1 then {VARIABLE victory_objectives_string _"Mike moves to the signpost"}
if obj2 then {VARIABLE_OP victory_objectives_string "$victory_objectives_string
@Defeat all enemy leaders"}
if obj3 then {VARIABLE_OP victory_objectives_string "$victory_objectives_string
@Survive until end of turns"}
etc.

[objectives]
    [objective]
        description=$victory_objectives_string
        condition=win
opensourcejunkie
Posts: 547
Joined: August 11th, 2008, 3:19 pm

Re: Displaying objectives conditionally

Post by opensourcejunkie »

yeah, this is something I'd like to see changed myself; I had a similar difficulty, but since there were only two conditions, I only had a set of four objectives to write.
--OSJ

Edit: here was a forum post in the ideas forum concerning the same thing. It had an interesting idea about using [insert_tag] as well.
what if the Bible's claims about Christ depicted accurate, verifiable history? given some research, you might be surprised at the evidence...
Cheradenine
Posts: 31
Joined: December 8th, 2008, 12:24 am

Re: Displaying objectives conditionally

Post by Cheradenine »

Thanks! I couldn't quite get it working (I could build the string, but only the first line would appear green in the objectives window) but it suggested another kludgey approach that was still better than the "32 if statements" option. (I built an array of the appropriate objectives and then formatted the objectives window based on the length of the array. So it took 5 if statements instead of 32.)
opensourcejunkie
Posts: 547
Joined: August 11th, 2008, 3:19 pm

Re: Displaying objectives conditionally

Post by opensourcejunkie »

much nicer :)
--OSJ
what if the Bible's claims about Christ depicted accurate, verifiable history? given some research, you might be surprised at the evidence...
Post Reply