Silence's WML Questions
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.
Re: Silence's WML Problems/Questions
I would use something like this:Silence wrote:I'm trying to make a Wolf spawn on a random coordinate every 4 turns.
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]
Re: Silence's WML Questions
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.)
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?
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]
- Elvish_Hunter
- Posts: 1600
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: Silence's WML Questions
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):
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)
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
Re: Silence's WML Questions
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:
EDIT : I also tried putting the following in my prestart event:
and
work, but for some reason
and
does not - the wolf (or other unit) simply does not spawn.
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]
Code: Select all
{GENERIC_UNIT 1 Wolf 12 18}
Code: Select all
[unit]
type=Spearman
side=1
x=10
y=10
[/unit]
Code: Select all
{GENERIC_UNIT 5 Wolf 12 18}
Code: Select all
[unit]
type=Spearman
side=5
x=10
y=10
[/unit]
Re: Silence's WML Questions
The only anomaly I see in your SideWML is that you specify bothSilence 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?
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.Re: Silence's WML Questions
Little gaff on my part, thank you. ^^
I removed
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:
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:
Does that have anything to do with it?Error:
Error reading the WML : invalid side number.
Re: Silence's WML Questions
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.
Re: Silence's WML Questions
Sure.bumbadadabum wrote:Can you post the entire scenario .cfg?
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]
Re: Silence's WML Questions
Code: Select all
# Side definition
[side]
side=1
...
[/side]
[side]
side=2
...
[/side]
[side]
side=5
...
[/side]
SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
Re: Silence's WML Questions
Ah. My bad, and thanks. Onward with coding I go then. ^^;
Re: Silence's WML Questions
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:
What is wrong with this recursion event?
Code: Select all
## Four turns from now, run this again:
[event]
name="turn $($turn_number + 4)"
[fire_event]
name=spawn_wolf
[/fire_event]
[/event]
In addition, could you explain how this function causes itself to repeat, or do I need to add that in myself?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]
Re: Silence's WML Questions
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.
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.
Re: Silence's WML Questions
I tried modifying the event to this:
Neither message was shown: from that, I assume that something is wrong with
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.
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]
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.
Re: Silence's WML Questions
Maybe try
?
This is similar to some code I got to work in RBY.
Also,
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
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).
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)
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:
Re: Silence's WML Questions
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."