Picking your own team color

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
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Picking your own team color

Post by Helmet »

I want the player to pick his own team color. In the "team-colors.cfg", the colors are listed. There are the usual colors: Red, Blue, Green, Purple, Black, Brown, Orange, White, and Teal. But there is also Light Red, Dark Red, Light Blue, Bright Green, Bright Orange, and Gold.

I want the player to pick from a list of five or six colors, and I'd like the list to include a few of the unusual colors. I'm reserving a few colors for my enemy units, such as purple.

I thought the code was going to be a piece of cake. Nope. Once again I'm back to my usual method of trying random things, hoping I'll stumble upon the solution. Of all my failures to make the code work, here's the bit of code that I'm pretty sure is the most likely to be least wrong.

Any help would be appreciated.

Code: Select all

[message]
     	speaker=narrator
	 message= _ "Pick a team color."
    	 [option]
    	 	message= _ "Gold."
    	 	[command]
        		[set_variable]
				name=my_color
    				value=gold				
        		[/set_variable]			
		[/command]
	[/option]
    	[option]
    	 	message= _ "Light blue."
    	 	[command]
        		[set_variable]
		        	name=my_color
    				value=light blue				
        		[/set_variable]			
		[/command]
	[/option]
[/message]
[modify_side]
	side=1 # 			side 1 is default, but just in case...
	[set_variable]
        	name=color
    		to_variable=my_color					
        [/set_variable]
[/modify_side]

Last edited by Helmet on October 22nd, 2020, 1:39 am, edited 2 times in total.
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
User avatar
octalot
General Code Maintainer
Posts: 786
Joined: July 17th, 2010, 7:40 pm
Location: Austria

Re: Picking your own team color

Post by octalot »

I haven't tested this, but think it should be:

Code: Select all

[modify_side]
    side=1
    color=$my_color
[/modify_side]
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: Picking your own team color

Post by Helmet »

That was actually the first or second thing I tried, and it didn't work. Thanks, though. I don't know why it doesn't work. It makes sense.

After all, this changes the color to blue.

Code: Select all

[modify_side]
    side=1
    color=blue
[/modify_side]
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: Picking your own team color

Post by Helmet »

I think the problem is the variable "color". I tried another method of making "color" accept the value of "my_color", but it didn't work either.

Code: Select all

[modify_side]
	[filter]
		side=1
	[/filter]			
	[set_variable]
       		name=color
    		to_variable=my_color					
       	[/set_variable]
[/modify_side]
EDIT: Hmm. Maybe this is one of those times when you need change the variable in an array...

EDIT: Maybe [store_side] is involved somehow. Evidently [store_side] can be used to capture the value of a side's color...
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: Picking your own team color

Post by Helmet »

I solved the problem. This was my main error: I was doing my tests with the new colors, but I was using the wrong id for those colors. For example, the id for Bright Red is not Bright Red or even bright red, Bright Red is brightred.

I changed the value of color directly within the [option] tag.

Functional code example:

Code: Select all

[message]
     	speaker=narrator
	 message= _ "Pick a team color."
    	 [option]
    		message= _ "Dark red."
    	 	[command]
    	 		[modify_side]
    	 			color=darkred
    	 		[/modify_side]		
		[/command]
	[/option]
    	[option]
    		message= _ "Bright green."
    		[command]
    	 		[modify_side]
    				color=brightgreen
    			[/modify_side]		
    		[/command]
	[/option]
Note to self: when writing code, check to make sure the id is correct.
octalot wrote: October 22nd, 2020, 1:22 am I haven't tested this, but think it should be:

Code: Select all

[modify_side]
    side=1
    color=$my_color
[/modify_side]
Thanks, octalot, your solution would've worked after all, if I hadn't used the wrong id for the colors.
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Post Reply