Can story tags contain internal actions?

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.

Can story tags contain internal actions?

Postby MiddleTwin » September 9th, 2017, 6:23 pm

The wiki mentioned that story tags can contain if/then/else, and use variables, so i was wondering if you could set variables and so run loops to do things like automatically run through an array of map points to plot. I wrote a macro to do this, which appears to do nothing. I'm guessing this means that you can't, but if so is there some sort of workaround? I don't want to make dozens of calls to {OLD_FOO} in every single scenario.

The macro i wrote is included, but probably irrelevant
Code: Select all
#define STORY_SO_FAR
  #Start by setting the background map
  [part]
    [background_layer]
        image=maps/wesnoth.png
        scale_vertically=yes
        scale_horizontally=no
        keep_aspect_ratio=yes
    [/background_layer]
    #Now loop through past journey points
    [set_variable]
      name=index
      value=1#effectively 1-indexed, as first entry in journey array is a placeholder
    [/set_variable]
    [while]
      [variable]
        name=index
        less_than_equal_to=$journey_index|#journey_index is the size of the journey array
      [/variable]
      [do]
        [set_variable]
          name=current_row
          to_variable=$journey_array[$index]|
        [/set_variable]
        [switch]
          variable=current_row.type
          [case]
            value="journey"
            {OLD_JOURNEY $current_row.x| $current_row.y|}
          [/case]
          [case]
            value="rest"
            {OLD_REST $current_row.x| $current_row.y|}
          [/case]
          [case]
            value="battle"
            {OLD_BATTLE $current_row.x| $current_row.y|}
          [/case]
        [/switch]
        [set_variable]
          name=index
          add=1
        [/set_variable]
      [/do]
    [/while]
    [clear_variable]
      name=index,current_row
    [/clear_variable]
  [/part]
#enddef

It was intended to be used with things like this one to automate path generation
Code: Select all
#define ADD_JOURNEY X Y
  {NEW_JOURNEY {X} {Y}}
  [set_variable]
    name=journey_index
    add=1
  [/set_variable]
  [set_variables]
    name=journey_array
    mode=append
    [value]
      x={X}
      y={Y}
      type="journey"
    [/value]
  [/set_variables]
#enddef
Currently writing The Goblin Rebellion, an sp campaign for version 1.12 and up.
User avatar
MiddleTwin
 
Posts: 13
Joined: September 9th, 2017, 5:51 pm

Re: Can story tags contain internal actions?

Postby zookeeper » September 9th, 2017, 6:43 pm

No, you can't run any ActionWML there. You can only use it to conditionally display different [part]s.

However, you can still do what you want, because [insert_tag] works in [story]. That is, at the previous scenario's end, you can construct your [part] tag(s) in whatever way you want and store them in a variable/container, and then in the next scenario's story screen use [insert_tag] to, well, insert it. Of course [insert_tag] is not for the faint of heart, but if you can handle [set_variables] then you can probably figure it out with some experimentation.
User avatar
zookeeper
WML Wizard
 
Posts: 9603
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Can story tags contain internal actions?

Postby MiddleTwin » September 9th, 2017, 7:29 pm

Thanks, zoo. Tag insertion looks like it should do the trick. One more quick question: how does [insert_tag] handle macros? Would something like
Code: Select all
[set_variable]
  name=temp.part
  value={OLD_JOURNEY $x| $y|}
[set_variable]
[insert_tag]
    name=story
    value=temp
[insert_tag]

result in a story tag with the expanded macro, or will i need to look up the macro definitions and manually fill them in?
Currently writing The Goblin Rebellion, an sp campaign for version 1.12 and up.
User avatar
MiddleTwin
 
Posts: 13
Joined: September 9th, 2017, 5:51 pm

Re: Can story tags contain internal actions?

Postby Ravana » September 9th, 2017, 8:03 pm

[insert_tag] knows nothing about macros, it is evaluated during runtime.

It will work for you.
User avatar
Ravana
Moderator
 
Posts: 1448
Joined: January 29th, 2012, 12:49 am
Location: Estonia

Re: Can story tags contain internal actions?

Postby Pentarctagon » September 9th, 2017, 8:20 pm

No tags know anything about macros, in fact, since macros are read by the preprocessor and expanded before any tags are evaluated.

If you know where Wesnoth's cache is, you can check there for what your add-on's WML looks like after all macros have been expanded.
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
Pentarctagon
Forum Administrator
 
Posts: 2920
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: Can story tags contain internal actions?

Postby MiddleTwin » September 9th, 2017, 8:57 pm

Cool. Thanks!
Currently writing The Goblin Rebellion, an sp campaign for version 1.12 and up.
User avatar
MiddleTwin
 
Posts: 13
Joined: September 9th, 2017, 5:51 pm

Re: Can story tags contain internal actions?

Postby MiddleTwin » September 10th, 2017, 1:54 am

Just wanted to say that I got stuff working properly. If anyone wanders into this thread looking for a workaround, I guess this can be an example.
Code: Select all
#define STORY_SO_FAR
[part]
  [background_layer]
    image=maps/wesnoth.png
    scale_vertically=yes
    scale_horizontally=no
    keep_aspect_ratio=yes
  [/background_layer]
  [insert_tag]
    name=image
    variable=journey_array
  [/insert_tag]
[/part]
#enddef

#define ADD_JOURNEY X Y
  [set_variables]
    name=journey_array
    mode=append
    [value]#expanded OLD_JOURNEY macro, without the image tags
      centered=yes
      file="misc/dot-white.png"
      x={X}
      y={Y}
    [/value]
  [/set_variables]
#enddef

#define ADD_BATTLE X Y
[set_variables]
  name=journey_array
  mode=append
  [value]#expanded OLD_BATTLE macro, without the image tags
    x,y={X},{Y}
    file=misc/cross-white.png
    centered=yes
  [/value]
[/set_variables]
#enddef

#define ADD_REST X Y
[set_variables]
  name=journey_array
  mode=append
  [value]#expanded OLD_REST macro, without the image tags
    x,y={X},{Y}
    file=misc/flag-white.png
    centered=yes
  [/value]
[/set_variables]
#enddef

All you have to do is embed a call to STORY_SO_FAR in the beginning of a story block, and call the appropriate ADD macros in any one-time event in a scenario to make them appear as old journey points in every following scenario's STORY_SO_FAR.
Currently writing The Goblin Rebellion, an sp campaign for version 1.12 and up.
User avatar
MiddleTwin
 
Posts: 13
Joined: September 9th, 2017, 5:51 pm


Return to WML Workshop

Who is online

Users browsing this forum: Google [Bot] and 3 guests