variable visibility/access

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
SFault
Posts: 483
Joined: November 10th, 2009, 2:21 pm
Location: Esbo, Finland

variable visibility/access

Post by SFault »

Sorry for clogging the workshop but I just got really lost with the WML structure. I guess that I'm confused because I can write variable inside one scenario's event and that variable can be accessed inside another scenario's event but not inside same scenario's value input.

My plan is to have a color value for player and opponent. I would like to save it in variable and then access it inside [side] and [story]. So the team would have the defined color and on bigmap I would recolor the icons based on that color. I have scenario called intro that gives me chance to write these variables and then on the next scenario I'm planning to use them. But as far as I can manage (so far tried this for about 5 hours) I cannot refer to the variable inside mentioned tags. Is there some alternative way of doing this with WML? Can I do workaround with LUA?

I knew that I would face problems when I decided to do dynamically advancing campaign but I really didn't dream of having so much difficulties with getting visual stuff into right color. :augh:

edit: I guess for the bigmap I could just show image inside event-tag, but for side I still would like to get ideas
Last edited by SFault on October 11th, 2017, 3:48 pm, edited 1 time in total.
segmentation fault
EBfW, GtR, Art, Old art
User avatar
Pentarctagon
Project Manager
Posts: 5533
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: variable visibility/access

Post by Pentarctagon »

Code examples would help quite a bit, just in general when asking a WML question. One thing you could try as a last resort though is [insert_tag], like in this thread.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
User avatar
SFault
Posts: 483
Joined: November 10th, 2009, 2:21 pm
Location: Esbo, Finland

Re: variable visibility/access

Post by SFault »

Well. Basically I would like to define the color like this:

Code: Select all

[set_variable]
    name=player_color
    value=blue
[/set_variable]
and then apply it on the side like this:

Code: Select all

[side]
    type=rulerking
    id=Gweddyn
    name= _ "Gweddyn"
    side=1
    color=$player_color  ### HERE'S THE PROBLEM ###
    canrecruit=yes
    gender=male
    controller=human
    recruit=
    gold=0
    income=-2
    team_name=gweddyn
    user_team_name=_"Gweddyn"
    role=ruler
    x,y=21,8
    village_gold=0
[/side]
But this doesn't seem to work. I think the problem is that the [set_variable] needs to be inside [event] e.g. prestart but the side is just inside the [scenario]. I assume that the interpreter cannot recognize the $ symbol inside the [side] although the variable is stored globally inside the campaign.

I guess I can just use static color themes but it's bit sad that I need to do two scenarios just to have two different opponent variations. (The color is just for starters. Later on there would be like Orcish team or Elven team to fight at. At that point it would be nice to have the team values in array and then just read the variables from that array into the [side].)

Got to check out the story part. I think I could have the map shown in prestart-event to get access to variables (and that for-statement).
segmentation fault
EBfW, GtR, Art, Old art
User avatar
SFault
Posts: 483
Joined: November 10th, 2009, 2:21 pm
Location: Esbo, Finland

Re: variable visibility/access

Post by SFault »

Wait. I can access the color value with [modify_side] inside [event]. Stupid me! :doh:

edit: This does the trick inside prestart

Code: Select all

[modify_side]
   side=1
   color=$player_color
[/modify_side]
edit2: I tried that [insert_tag] thing. It works! Now I only have to figure out how to cooperate that with [for]. :D
segmentation fault
EBfW, GtR, Art, Old art
User avatar
SFault
Posts: 483
Joined: November 10th, 2009, 2:21 pm
Location: Esbo, Finland

Re: variable visibility/access

Post by SFault »

So I got it working with the [insert_tag]. Thank you very much!

In event I have

Code: Select all

[for]
   variable=i
   start=0
   end=5
   step=1
   [do]
	
   	  [set_variables]
	    name=label_$i
	    mode=append
	    [value]

	     x=$counties[$i].iconX
	     y=$counties[$i].iconY
         file=misc/$counties[$i].label|.png
         centered=yes

	    [/value]
	  [/set_variables]
	  [set_variables]
	    name=border_$i
	    mode=append
	    [value]

	     x=$counties[$i].iconX
	     y=$counties[$i].iconY
         file=misc/border.png~RC(magenta>$$counties[$i].owner|_color|)
         centered=yes

	    [/value]
	  [/set_variables]
   [/do]
[/for]
And then I can have these guys in story (not showing the 2...5)

Code: Select all

[insert_tag]
	name=image
	variable=label_0
[/insert_tag]
[insert_tag]
	name=image
	variable=border_0
[/insert_tag]
[insert_tag]
	name=image
	variable=label_1
[/insert_tag]
[insert_tag]
	name=image
	variable=border_1
[/insert_tag]
What this does is go through the counties-array, pick the coordinates and place two images there. The latter image is the TC-frame based on the owner color (defined elsewhere) which can now be changed by changing the owner attribute in the array. Me very happy! Result:
Attachments
From this
From this
To this
To this
segmentation fault
EBfW, GtR, Art, Old art
Post Reply