Silence's WML Questions

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.
User avatar
8680
Moderator Emeritus
Posts: 742
Joined: March 20th, 2011, 11:45 pm
Location: The past

Re: Silence's WML Problems/Questions

Post by 8680 »

Silence wrote:I'm trying to make a Wolf spawn on a random coordinate every 4 turns.
I would use something like this:

Code: Select all

[event]
    name=spawn_wolf
    first_time_only=no
    ## Spawn a Wolf at a random location:
    {VARIABLE_OP rand_x rand <min>..<max>}
    {VARIABLE_OP rand_y rand <min>..<max>}
    {GENERIC_UNIT <side> Wolf $rand_x $rand_y}
    ## Four turns from now, run this again:
    [event]
        name="turn $($turn_number + 4)"
        [fire_event]
            name=spawn_wolf
        [/fire_event]
    [/event]
[/event]

[event]
    name=turn 4
    ## Start up the wolf-spawner.
    [fire_event]
        name=spawn_wolf
    [/fire_event]
[/event]
User avatar
Silence
Posts: 40
Joined: September 3rd, 2011, 1:13 am

Re: Silence's WML Questions

Post by Silence »

Both work for spawning a on a player side, thanks! (Currently using the recursion one for now.)

Building on that : I'm currently trying to make a third 'creep' side that multiple (opposing) players on a map have to fight, and currently have the side set up as this. (Also put a start location on the map, if that is needed.)

Code: Select all

    [side]
      side=5
      canrecruit=no
      allow_player=no
      team_name=Wolves
      user_team_name= _ "Wolves"
      controller=ai
      income=-2
      no_leader=yes
      fog=yes
      [ai]
        aggression=0.6
        caution=0.6
      [/ai]
    [/side]
However when I attempt to spawn a Wolf for this side using the previous function it does not appear. Is there something I'm missing?
User avatar
Elvish_Hunter
Posts: 1600
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: Silence's WML Questions

Post by Elvish_Hunter »

I don't see anything wrong in your [side] tag. Can you post the code of your spawning event?
Also, a way to improve 8680's code will be by using [store_locations]. By choosing a random x and y, you may end up choosing a location that is already busy, or an impassable terrain. So, I'd use this (untested):

Code: Select all

[event]
    name=spawn wolf
    first_time_only=no

    [store_locations]
        variable=wolf_locs
        # exclude non-empty hexes
        [not]
            [filter]
            [/filter]
        [/not]
        # exclude unwanted terrains
        [not]
            terrain= # put a list of terrain codes here
        [/not]
    [/store_locations]

    {RANDOM "0..$($wolf_locs.length-1)"} # choose an element of the array; arrays start from 0

    {GENERIC_UNIT <side> Wolf $wolf_locs[$random].x $wolf_locs[$random].y}
    {CLEAR_VARIABLE wolf_locs,random}
[/event]
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
User avatar
Silence
Posts: 40
Joined: September 3rd, 2011, 1:13 am

Re: Silence's WML Questions

Post by Silence »

Sure! (I'll try experimenting with [store_locations] once I've figured out what was wrong with this.)

For the moment, I'm using what 8680 posted, since it seemed to be the cleanest way to do it:

Code: Select all

    [event]
        name=spawn_wolf
        first_time_only=no
        ## Spawn a Wolf at a random location:
		##Future reference : spawn central to 20,18
        {VARIABLE_OP rand_x rand 17..23}
        {VARIABLE_OP rand_y rand 16..20}
        {GENERIC_UNIT 5 Wolf $rand_x $rand_y}
        ## Four turns from now, run this again:
        [event]
            name="turn $($turn_number + 4)"
            [fire_event]
                name=spawn_wolf
            [/fire_event]
        [/event]
    [/event]

    [event]
        name=turn 4
        ## Start up the wolf-spawner.
        [fire_event]
            name=spawn_wolf
        [/fire_event]
    [/event]
EDIT : I also tried putting the following in my prestart event:

Code: Select all

 {GENERIC_UNIT 1 Wolf 12 18}
and

Code: Select all

	[unit]
		type=Spearman
		side=1
		x=10
		y=10
	[/unit]
work, but for some reason

Code: Select all

 {GENERIC_UNIT 5 Wolf 12 18}
and

Code: Select all

	[unit]
		type=Spearman
		side=5
		x=10
		y=10
	[/unit]
does not - the wolf (or other unit) simply does not spawn.
User avatar
8680
Moderator Emeritus
Posts: 742
Joined: March 20th, 2011, 11:45 pm
Location: The past

Re: Silence's WML Questions

Post by 8680 »

Silence wrote:However when I attempt to spawn a Wolf for this side using the previous function it does not appear. Is there something I'm missing?
The only anomaly I see in your SideWML is that you specify both canrecruit=no and no_leader=yes. canrecruit is a SingleUnitWML attribute, not a SideWML attribute. SingleUnitWML is allowed to be included in a [side] tag to specify the properties of the side’s leader unit, but you specify that the side has no_leader. I don’t know whether this is the cause of your problem, though.
User avatar
Silence
Posts: 40
Joined: September 3rd, 2011, 1:13 am

Re: Silence's WML Questions

Post by Silence »

Little gaff on my part, thank you. ^^

I removed canrecruit=no but the error is still there.

EDIT : Out of curiosity I quickly grafted the relevant wolf code (Side included) into A Simple Campaign and switched the map to my map and got the following error:
Error:
Error reading the WML : invalid side number.
Does that have anything to do with it?
User avatar
Astoria
Inactive Developer
Posts: 1007
Joined: March 20th, 2008, 5:54 pm
Location: Netherlands

Re: Silence's WML Questions

Post by Astoria »

Can you post the entire scenario .cfg?
Formerly known as the creator of Era of Chaos and maintainer of The Aragwaithi and the Era of Myths.
User avatar
Silence
Posts: 40
Joined: September 3rd, 2011, 1:13 am

Re: Silence's WML Questions

Post by Silence »

bumbadadabum wrote:Can you post the entire scenario .cfg?
Sure.

Code: Select all

# textdomain CREEPMAP
[multiplayer]
  id=2p_Wolf_Den
  name= _ "2p - Wolf Den"
  description = _ "A simple combat map with hostile wolves in between both players."
# map data
  map_data="{~add-ons/CreepMap/maps/2p_Wolf_Den.map}"  
  turns=-1
  experience_modifier=70

# Day cycle definition    

    {DEFAULT_SCHEDULE}

# mus
    {DEFAULT_MUSIC_PLAYLIST}

    random_start_time=yes

  [event]
    name=prestart
# Objectives definition    

    [objectives]
      side=1
      [objective]
        description= _ "Defeat Enemy Leader"
        condition=win
      [/objective]
      [objective]
        description= _ "Death of your Leader"
        condition=lose
      [/objective]
	  [note]
        description= _ "Wolves will spawn from time to time."
	  [/note]
    [/objectives]

    [objectives]
      side=2
      [objective]
        description= _ "Defeat Enemy Leader"
        condition=win
      [/objective]
      [objective]
        description= _ "Death of your Leader"
        condition=lose
      [/objective]
	  [note]
        description= _ "Wolves will spawn from time to time."
	  [/note]   
    [/objectives] 
	
	##indicator of wolf spawn area
	[item]
		x,y=20,18
		image="scenery/dwarven-doors-closed.png"
	[/item]
	{SET_LABEL 20 18 "<span color='blue'>Wolf's Den</span>"}
   [/event]	

# Side definition 
    [side]
        side=1
        canrecruit=yes
        team_name=Team1
        user_team_name= _ "Team 1"
        controller=human
        save_id=Player1
        village_gold=2
        gold=150
        income=0
        fog=yes
        [ai]
           aggression=0.0
           caution=0.6
        [/ai]
    [/side]

    [side]
        side=2
        canrecruit=yes
        team_name=Team2
        user_team_name= _ "Team 2"
        controller=human
        save_id=Player2
        village_gold=2
        gold=150
        income=0
        fog=yes
        [ai]
           aggression=0.0
           caution=0.6
        [/ai]
    [/side]

    [side]
      side=5
      allow_player=no
      team_name=Wolves
      user_team_name= _ "Wolves"
      controller=ai
      income=-2
      no_leader=yes
      fog=yes
      [ai]
        aggression=0.6
        caution=0.6
      [/ai]
    [/side]

# Set up events

# Once every four turns, spawn two wolves.
    [event]
        name=spawn_wolf
        first_time_only=no
        ## Spawn a Wolf at a random location:
		##Future reference : spawn central to 20,18
        {VARIABLE_OP rand_x rand 17..23}
        {VARIABLE_OP rand_y rand 16..20}
        {GENERIC_UNIT 5 Wolf $rand_x $rand_y}
        ## Four turns from now, run this again:
        [event]
            name="turn $($turn_number + 4)"
            [fire_event]
                name=spawn_wolf
            [/fire_event]
        [/event]
    [/event]

    [event]
        name=turn 4
        ## Start up the wolf-spawner.
        [fire_event]
            name=spawn_wolf
        [/fire_event]
    [/event]
# End of setup events

[/multiplayer]
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Silence's WML Questions

Post by mattsc »

Code: Select all

        # Side definition
        [side]
            side=1
            ...
        [/side]

        [side]
            side=2
            ...
        [/side]

        [side]
          side=5
          ...
        [/side]
Side numbers in [side] definitions need to be consecutive.
User avatar
Silence
Posts: 40
Joined: September 3rd, 2011, 1:13 am

Re: Silence's WML Questions

Post by Silence »

Ah. My bad, and thanks. Onward with coding I go then. ^^;
User avatar
Silence
Posts: 40
Joined: September 3rd, 2011, 1:13 am

Re: Silence's WML Questions

Post by Silence »

I was trying out the map I've been with a friend with 8680's function, but the wolf only spawned once on turn 4 and didn't spawn on any subsequent turns. That leaves me with two questions:

Code: Select all

        ## Four turns from now, run this again:
        [event]
            name="turn $($turn_number + 4)"
            [fire_event]
                name=spawn_wolf
            [/fire_event]
        [/event]
What is wrong with this recursion event?
Elvish_Hunter wrote:I don't see anything wrong in your [side] tag. Can you post the code of your spawning event?
Also, a way to improve 8680's code will be by using [store_locations]. By choosing a random x and y, you may end up choosing a location that is already busy, or an impassable terrain. So, I'd use this (untested):

Code: Select all

[event]
    name=spawn wolf
    first_time_only=no

    [store_locations]
        variable=wolf_locs
        # exclude non-empty hexes
        [not]
            [filter]
            [/filter]
        [/not]
        # exclude unwanted terrains
        [not]
            terrain= # put a list of terrain codes here
        [/not]
    [/store_locations]

    {RANDOM "0..$($wolf_locs.length-1)"} # choose an element of the array; arrays start from 0

    {GENERIC_UNIT <side> Wolf $wolf_locs[$random].x $wolf_locs[$random].y}
    {CLEAR_VARIABLE wolf_locs,random}
[/event]
In addition, could you explain how this function causes itself to repeat, or do I need to add that in myself?
User avatar
iceiceice
Posts: 1056
Joined: August 23rd, 2013, 2:10 am

Re: Silence's WML Questions

Post by iceiceice »

So I don't know for sure but I can offer some advice anyways.

The idea of the event is that it registers a custom event "spawn_wolf" which fires at a specific turn. The code at the very end of this event registers a new event for four turns later which fires the wolf again, which is why it should recur indefinitely.

If it launches once but never again then most likely there is a typo which causes the event not to launch its copy.

Some things you could try:

-Insert some debugging output i.e., insert [chat] [/chat] tags at start when the event should fire. If the second event is starting but not finishing then you know where to look.
Also [chat] the result of "$($turn_number +4)", so you can see if something fishy is happening there. If the second event is not starting then that's likely the problem.
-If it's really confusing, uncompress a save file and use a text editor to search for "name=spawn_wolf" to see what kinds of events are spawning in practice.
-Maybe try adding delimiters to the strings, e.g. make it "$($turn_number| + 4)". WML is a bit confusing about when you have to do this imo, once I got burned and wasted alot of time so now I tend to do this as soon as something doesn't work. There's no downside to doing this afaik.
User avatar
Silence
Posts: 40
Joined: September 3rd, 2011, 1:13 am

Re: Silence's WML Questions

Post by Silence »

I tried modifying the event to this:

Code: Select all

        [event]
            name="turn $($turn_number| + 4)"
			[chat]
			   message=_"Repeat event"
			[/chat]
            [fire_event]
                name=spawn_wolf
            [/fire_event]
			[chat]
			   message=_"turn $($turn_number| + 4)"
			[/chat]
        [/event]
Neither message was shown: from that, I assume that something is wrong with name="turn $($turn_number| + 4)" but I don't know what it is.

I tried having Wesnoth save uncompressed saves of a 'debugged' game at turns 1,3,4,7, and 8, but all I see is the event code w/decompressed macros. I'm not quite sure where to look from there.
User avatar
iceiceice
Posts: 1056
Joined: August 23rd, 2013, 2:10 am

Re: Silence's WML Questions

Post by iceiceice »

Maybe try

Code: Select all

name = "turn " + $($turn_number|+4)
?

This is similar to some code I got to work in RBY.

Also,

Code: Select all

name = "turn " $($turn_number|+4)
might even work, that's similar to some other code in RBY...

Wish I could be more authoritative, I find wml string manipulations to be somewhat counterintuitive... at least it works differently from all of C++, java, basic, and unix shell.

Also if none of those chats are showing, try putting a chat at exactly the line in 8680's code where he commented

Code: Select all

        ## Four turns from now, run this again:
If you don't see that chat then you aren't even making it to the recursion code. If you see that one but none of the others then its definitely a problem with $($turn_number|+4).
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Silence's WML Questions

Post by Sapient »

This is just a quick note to say that $($turn_number + 4) in an unquoted string will definitely not work, for reasons explained on the SyntaxWML page of the wiki. Namely, the + symbol in an unquoted string will be interpreted as a concatenation by the CFG parser. So it would concatenate as $($turn_number4), which is definitely wrong.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
Post Reply