Owl's WML (Currently: Solved)

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
UnwiseOwl
Posts: 510
Joined: April 9th, 2010, 4:58 am

Re: Owl's WML (Currently: Solved)

Post by UnwiseOwl »

Code: Select all

#define FOS_ESCAPE
	[set_variable]
		name=rando
		rand=0..8
	[/set_variable]
	[set_variables]
		name=civescape
		[literal]
			value=_"On to safety."
		[/literal]
		[literal]
			value=_"I'm getting out of here!"
		[/literal]
		[literal]
			value=_"Thank the Imperator!"
		[/literal]
		[literal]
			value=_"Still alive."
		[/literal]
		[literal]
			value=_"Come on, let's go!"
		[/literal]
		[literal]
			value=_"Good luck, Caius Regilius."
		[/literal]
		[literal]
			value=_"Thank you for your protection"
		[/literal]
		[literal]
			value=_"I hate Marauders..."
		[/literal]
		[literal]
			value=_"What about my precious things? Tribune, go get them for me."
		[/literal]
	[/set_variables]
#enddef
I have the above code which picks from the list of options to have characters say things on a regular basis in a campaign, but it is currently stuck with each character saying the same thing. What do I am to caused it to re-randomise each time that the event is fired?
Maintainer of the Imperial Era and the campaigns Dreams of Urduk, Epic of Vaniyera, Up from Slavery, Fall of Silvium, Alfhelm the Wise and Gali's Contract.
But perhaps 'maintainer' is too strong a word.
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Owl's WML (Currently: Re-using [set_variable])

Post by Ravana »

Each time call [set_variable] with rand.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Owl's WML (Currently: Re-using [set_variable])

Post by zookeeper »

That code doesn't pick anything. It just sets a random variable, and creates an array. If you want the string pointed to by the variable rando, then $civescape[$rando].value is what you need.
User avatar
UnwiseOwl
Posts: 510
Joined: April 9th, 2010, 4:58 am

Re: Owl's WML (Currently: Re-using [set_variable])

Post by UnwiseOwl »

Thank you guys.

Yes, zookeeper, I'm using message=$civescape[$rando].value in an event, but I'm still stuck with how to get it to set a new value for rando each time:)
Maintainer of the Imperial Era and the campaigns Dreams of Urduk, Epic of Vaniyera, Up from Slavery, Fall of Silvium, Alfhelm the Wise and Gali's Contract.
But perhaps 'maintainer' is too strong a word.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Owl's WML (Currently: Re-using [set_variable])

Post by zookeeper »

UnwiseOwl wrote:Yes, zookeeper, I'm using message=$civescape[$rando].value in an event, but I'm still stuck with how to get it to set a new value for rando each time:)
I don't see what the problem is then, as the [set_variable] you have there sets rando to a random value between 0 and 8. If you want it to happen "each time", then just do it each time.
User avatar
UnwiseOwl
Posts: 510
Joined: April 9th, 2010, 4:58 am

Re: Owl's WML (Currently: Weapon Specials)

Post by UnwiseOwl »

The following code worked in 1.8 and 1.10 but doesn't in 1.12 and beyond.
Can anyone please advise what's gone wrong?

Code: Select all

#define WEAPON_SPECIAL_IE_INTERRUPT
            [knockback]
                id=ie_interrupt
                name= _ "interrupt-day only"
                description=_ "When a unit is hit with an interrupting attack, combat is immediately stopped. Works only during dawn and dusk and during the day, when the sun is in the sky."
            [/knockback]
        [/specials]
    [/attack]
    [event]
        name=defender hits
        first_time_only=no
        [filter_second_attack]
            special=interrupt
        [/filter_second_attack]
        [filter]
            [filter_location]
                time_of_day_id=dawn,morning,afternoon,dusk
            [/filter_location]
        [/filter]
        [if]
	    [then]
		[store_unit]
		    [filter]
			find_in=second_unit
		    [/filter]
		    variable=target
		    kill=yes
		[/store_unit]
            [/then]
        [/if]
    [/event]
    [event]
        name=attack end
        first_time_only=no
	[unstore_unit]
	    variable=target
	    text="interrupt"
	    {COLOR_HEAL}
	[/unstore_unit]
	{CLEAR_VARIABLE target}
    [/event]
    [+attack]
        [+specials]
#enddef
Maintainer of the Imperial Era and the campaigns Dreams of Urduk, Epic of Vaniyera, Up from Slavery, Fall of Silvium, Alfhelm the Wise and Gali's Contract.
But perhaps 'maintainer' is too strong a word.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Re: Owl's WML (Currently: Weapon Specials)

Post by zookeeper »

Of course it doesn't work, because those weapon special id's don't match. It wouldn't have worked in any version.

Also, that [if] is pointless because it doesn't have any conditions.
User avatar
UnwiseOwl
Posts: 510
Joined: April 9th, 2010, 4:58 am

Re: Re: Owl's WML (Currently: Weapon Specials)

Post by UnwiseOwl »

Those are both very good points, and the one about this never working raises its own interesting questions for me to ask myself, as I know that it did once upon a time and I could have sworn I've not touched this file in a VERY long time.

Thanks very much, Zookeeper.

It's now working as intended, but I'm still getting lua errors, any idea what might be causing these?

Code: Select all

20170414 22:50:31 error scripting/lua: game_error: creating unit with an empty type field
stack traceback:
	[C]: in field 'create_unit'
	lua/wml-tags.lua:1211: in local 'cmd'
	lua/wml-utils.lua:145: in field 'handle_event_commands'
	lua/wml-flow.lua:6: in function <lua/wml-flow.lua:5>
The corrected weapon special code:

Code: Select all

#define WEAPON_SPECIAL_IE_INTERRUPT
            [knockback]
                id=ie_interrupt
                name= _ "interrupt-day only"
                description=_ "When a unit is hit with an interrupting attack, combat is immediately stopped. Works only during dawn and dusk and during the day, when the sun is in the sky."
            [/knockback]
        [/specials]
    [/attack]
    [event]
        name=defender hits
        first_time_only=no
        [filter_second_attack]
            special=ie_interrupt
        [/filter_second_attack]
        [filter]
            [filter_location]
                time_of_day_id=dawn,morning,afternoon,dusk
            [/filter_location]
        [/filter]
		[store_unit]
		    [filter]
			find_in=second_unit
		    [/filter]
		    variable=target
		    kill=yes
		[/store_unit]
    [/event]
    [event]
        name=attack end
        first_time_only=no
	[unstore_unit]
	    variable=target
	    text="interrupt"
	    {COLOR_HEAL}
	[/unstore_unit]
	{CLEAR_VARIABLE target}
    [/event]
    [+attack]
        [+specials]
#enddef
Maintainer of the Imperial Era and the campaigns Dreams of Urduk, Epic of Vaniyera, Up from Slavery, Fall of Silvium, Alfhelm the Wise and Gali's Contract.
But perhaps 'maintainer' is too strong a word.
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Re: Owl's WML (Currently: Weapon Specials)

Post by Ravana »

Possibly from your unguarded attack end.


Edit: Wait what, ageless uses the same event. Why havent I seen the message...
User avatar
UnwiseOwl
Posts: 510
Joined: April 9th, 2010, 4:58 am

Re: Re: Owl's WML (Currently: Weapon Specials)

Post by UnwiseOwl »

You're certainly right, Ravana, but I am struggling to guard it in a way that retains the information that I need to unstore the secondary unit correctly. Can anyone suggest the right way to do this?
Maintainer of the Imperial Era and the campaigns Dreams of Urduk, Epic of Vaniyera, Up from Slavery, Fall of Silvium, Alfhelm the Wise and Gali's Contract.
But perhaps 'maintainer' is too strong a word.
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Re: Owl's WML (Currently: Weapon Specials)

Post by Ravana »

[event][filter_*]
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Re: Owl's WML (Currently: Weapon Specials)

Post by zookeeper »

You can add a [filter_condition] which one way or another checks (via [have_unit] or [variable], I guess) that there is actually a valid unit in the target variable. That way the event only fires when it should.
User avatar
UnwiseOwl
Posts: 510
Joined: April 9th, 2010, 4:58 am

Re: Re: Owl's WML (Currently: Weapon Specials)

Post by UnwiseOwl »

Thanks Zookeeper, that was exactly what I was needing.
I was trying to do the same thing with an [if] but this way is much neater and has the advantage of actually working.

Ended up looking like this:

Code: Select all

#define WEAPON_SPECIAL_IE_INTERRUPT
            [dummy]
                id=ie_interrupt
                name= _ "interrupt-day only"
                description=_ "When a unit is hit with an interrupting attack, combat is immediately stopped. Works only during dawn and dusk and during the day, when the sun is in the sky."
            [/dummy]
        [/specials]
    [/attack]
    [event]
		id=ie_interrupt_defender_hits
        name=defender hits
        first_time_only=no
        [filter_second_attack]
            special=ie_interrupt
        [/filter_second_attack]
        [filter]
            [filter_location]
                time_of_day_id=dawn,morning,afternoon,dusk
            [/filter_location]
        [/filter]
		[store_unit]
		    [filter]
			find_in=second_unit
		    [/filter]
		    variable=ie_interrupt_target
		    kill=yes
		[/store_unit]
		[event]
			id=ie_interrupt_attack_end
			name=attack end
			[unstore_unit]
				variable=ie_interrupt_target
				text="interrupt"
				{COLOR_HEAL}
			[/unstore_unit]
	{CLEAR_VARIABLE ie_interrupt_target}
			[/event]
    [/event]
Edit: Final version made in response to following comments (here and in discord)
Last edited by UnwiseOwl on April 15th, 2017, 7:09 pm, edited 3 times in total.
Maintainer of the Imperial Era and the campaigns Dreams of Urduk, Epic of Vaniyera, Up from Slavery, Fall of Silvium, Alfhelm the Wise and Gali's Contract.
But perhaps 'maintainer' is too strong a word.
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: Re: Owl's WML (Currently: Solved)

Post by gfgtdf »

while this will work it's still not optimal since it might spawn an infitinite number of events bloating up your savefile. Now that you changed it to an nested event you should remove the 'first_time_only=no' line.


EDIT: you might still need the '[filter_condition]' condiition tough since it's possible that tha attacker hits more than once.


EDIT2: yes with the second event now having an id the '[filter_condition]' is no longer needed.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
UnwiseOwl
Posts: 510
Joined: April 9th, 2010, 4:58 am

Re: Owl's WML (Currently: Off-centre unit sprites)

Post by UnwiseOwl »

Here's a long-standing issue that I've never been able to get to the bottom of.

Below is a picture showing the Samnis sprite from the IE. It's centred in the png file. It maps onto the hex fine, the sprite file is exactly 72x72, but in the unit information box in the sidebar it is always off-centre.

Image

Does anybody know what could cause this?

The contents of the relevant line of the unit.cfg file are "image="units/orcs-magni/samnis.png"
Maintainer of the Imperial Era and the campaigns Dreams of Urduk, Epic of Vaniyera, Up from Slavery, Fall of Silvium, Alfhelm the Wise and Gali's Contract.
But perhaps 'maintainer' is too strong a word.
Post Reply