How can I use a checkbox in options?

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

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
Enderlook
Posts: 38
Joined: January 22nd, 2018, 12:23 am

How can I use a checkbox in options?

Post by Enderlook » January 22nd, 2018, 10:23 pm

I've already made a checkbox in options -id=NE_MEDIC-, but I am not sure how can I use the value of the checkbox -yes/no-.
Here I have my code, with the checkbox and an attempt of how use the checkbox's value inside a conditional block and a variable tag.
Spoiler:
P.S: Do you know what means "require_modification=no"? I wrote that line because I found it in several mods.

User avatar
beetlenaut
Developer
Posts: 2260
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: How can I use a checkbox in options?

Post by beetlenaut » January 23rd, 2018, 2:08 am

The id is "NE_MEDIC", so that is the variable name too. You used "NE_MEDIC.value", which is incorrect. Also, you should use [then] and not [else]. (The [else] tag activates if all the conditional tags are false.)
the wiki wrote:require_modification: a boolean value; if set to yes, all players have to have this modification installed to join the game. Default no.
You probably want "yes".
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide

Enderlook
Posts: 38
Joined: January 22nd, 2018, 12:23 am

Re: How can I use a checkbox in options?

Post by Enderlook » January 23rd, 2018, 2:51 am

Thank you. I hadn't noticed that I wrote [else] instead of [then] :). Also I delete the ".value", but it isn't working.
If I do this doesn't work:

Code: Select all

		[if]
			[variable]
				name=NE_MEDIC
				boolean_equals=yes
			[/variable]
			[then]
				{HEALER_MENU}
			[/then]
		[/if]
But if instead I only do {HEALER_MENU} and then inside it I do this it works:

Code: Select all

#define HEALER_MENU
	[event]
		name=start
		[if]
			[variable]
				name=NE_MEDIC
				boolean_equals=yes
			[/variable]
			[then]
				......
			[/then]
		[/if]
	[/event]
#enddef
Do you know why?

User avatar
beetlenaut
Developer
Posts: 2260
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: How can I use a checkbox in options?

Post by beetlenaut » January 23rd, 2018, 3:13 am

If you put an [event] inside an [if], the event is created when the [if] is true, but it is not fired then. If you create a start event after the start of the scenario, it will never fire.

I don't know where your [if] tag is, but it's probably in the wrong place. Try using [set_menu_item] in the start event, and use the [show_if] tag inside it. Then you don't need an [if] tag anywhere.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide

Enderlook
Posts: 38
Joined: January 22nd, 2018, 12:23 am

Re: How can I use a checkbox in options?

Post by Enderlook » January 23rd, 2018, 3:38 am

I've two files.
The first "modifications.cfg" (the first code I posted above) -now without the [if]- and the second "healer.cfg" which contains HEALER_MENU (and the [if] inside that event). Is fine the location of the [if] tag?
I was thinking in put the [if] tag inside the event, and the [set_menu_item] inside the [if] -not the if as [show_if] because if the menu won't be used, why make it in first place? Or I shall make it anyway? It's the first time I make this so I am not sure what to do :(. (Also, I've already [show_if] but with another conditions (check if there is any healer in order to make visible that button)). Please, enlighten me :eng:.

User avatar
beetlenaut
Developer
Posts: 2260
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: How can I use a checkbox in options?

Post by beetlenaut » January 23rd, 2018, 4:18 am

Ah. I think I understand what you are doing now. Yeah, that sounds fine. Does it work like you want now?

(I suppose it doesn't matter if you make the menu and never show it, or don't make the menu in the first place. It doesn't look any different to the player. You are the programmer, so can decide which one you like better.)
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide

Enderlook
Posts: 38
Joined: January 22nd, 2018, 12:23 am

Re: How can I use a checkbox in options?

Post by Enderlook » January 23rd, 2018, 2:19 pm

Yes, you have right. The code is already working so it's fine. Thanks you.

Post Reply