vultraz's lua questions

Discussion of Lua and LuaWML support, development, and ideas.

Moderator: Forum Moderators

Post Reply
User avatar
vultraz
Developer
Posts: 959
Joined: February 7th, 2011, 12:51 pm
Location: Dodging Daleks

vultraz's lua questions

Post by vultraz »

I have a few lua questions, but since I'm really new to it, these might be a little noobish. Ok here goes.

I have this huge pile of shop code dumped across multiple files that uses hundreds of variables, and I was hoping to find a way to simplify it with lua. SAMPLE:

Code: Select all

#define CATEGORY_ENHANCEMENTS 
[option]
    message={MENU_IMG_TXT (icons/enhancements/enhancements.png) ( _ "<span color='#e1e119' weight='bold'>Enhancements</span>
<span size='smaller'>Important primary Upgrades</span>")}
    [command]
        {VARIABLE finished_sub no}
        [while]
            {SXCON finished_sub equals no}
            [do]
                [store_gold]
                    side=$side_number
                    variable=gold
                [/store_gold]
                {VARIABLE_OP moveleft value $move_left_$side_number}

                {VARIABLE_OP melee_dam value $shop[$side_number|].enhance.melee.damage|}
                {VARIABLE_OP melee_dam divide $shop[$side_number|].base.damage|}
                {VARIABLE_OP melee_dam add 39}
                {VARIABLE_OP range_dam value $shop[$side_number|].enhance.range.damage|}
                {VARIABLE_OP range_dam divide $shop[$side_number|].base.damage|}
                {VARIABLE_OP range_dam add 39}
                {VARIABLE_OP both_dam value $shop[$side_number|].enhance.both.damage|}
                {VARIABLE_OP both_dam divide $shop[$side_number|].base.damage|}
                {VARIABLE_OP both_dam add 59}

                {IF_VAR shop[$side_number|].devel.class equals rouge (
                    [then]
                        {VARIABLE_OP both_dam add -5}
                    [/then]
                )}

                {VARIABLE_OP melee_str value $shop[$side_number|].enhance.melee.strikes|}
                {VARIABLE_OP melee_str multiply $shop[$side_number|].base.strike|}
                {VARIABLE_OP melee_str add 150}
                {VARIABLE_OP range_str value $shop[$side_number|].enhance.range.strikes|}
                {VARIABLE_OP range_str multiply $shop[$side_number|].base.strike|}
                {VARIABLE_OP range_str add 150}
                {VARIABLE_OP both_str value $shop[$side_number|].enhance.both.strikes|}
                {VARIABLE_OP both_str multiply $shop[$side_number|].base.strike|}
                {VARIABLE_OP both_str add 240}

                {IF_VAR shop[$side_number|].devel.class equals rouge (
                    [then]
                        {VARIABLE_OP both_str add -40}
                    [/then]
                )}

                {VARIABLE_OP move_cost value $movement_bought_$side_number}
                {VARIABLE_OP move_cost multiply $shop[$side_number|].enhance.moveinc}
                {VARIABLE_OP move_cost add $shop[$side_number|].base.moves|}

                {VARIABLE_OP combo_range value $range_dam}
                {VARIABLE_OP combo_range multiply 4}
                {VARIABLE_OP combo_range add $range_str}
                {VARIABLE_OP combo_range add -$shop[$side_number|].enhance.discount}

                {VARIABLE_OP combo_melee value $melee_dam}
                {VARIABLE_OP combo_melee multiply 4}
                {VARIABLE_OP combo_melee add $melee_str}
                {VARIABLE_OP combo_melee add -$shop[$side_number|].enhance.discount}

                {VARIABLE_OP combo_both value $both_dam}
                {VARIABLE_OP combo_both multiply 4}
                {VARIABLE_OP combo_both add $both_str}
                {VARIABLE_OP combo_both add -$shop[$side_number|].enhance.discount}

                [message]
                    speaker=narrator
                    image=portraits/elves/transparent/shyde.png
                    message= _ "<span color='#e1e119' weight='bold'>Gold: $gold|</span>
<span color='#00ff00' weight='bold'>Movement left: $moveleft| </span>"

                    [option]
                        message={MENU_IMG_TXT ("misc/check2.png") ( _ "<span color='#14c8fa' weight='bold'>Done</span>")}
			[command]
			    {VARIABLE finished_sub yes}
			[/command]
  		    [/option]

		    [option]
			message={MENU_IMG_TXT ("misc/enhancement_icons/lightdam.png") ( _ "<span weight='bold'>$combo_both| gold: +4 Melee/Ranged Damage, +1 Melee/Ranged Strike</span>
                        <span color='#00fa00' size='smaller'><small>Discount: $shop[$side_number|].enhance.discount| Gold</small></span>")}
                        [show_if]
                            [variable]
                                name=shop[$side_number|].devel.class
                                equals=rouge
                            [/variable]
                        [/show_if]

                        [command]
                            [if]
                                {SXCON gold greater_than_equal_to $comb_both}
                                [then]
                                    [gold]
                                        side=$side_number|
                                        amount=-$combo_both|
                                    [/gold]

                                    {VARIABLE_OP shop[$side_number|].enhance.hitpoints_bought add 290}
                                    {VARIABLE_OP shop[$side_number|].enhance.melee.damage add 4}
                                    {VARIABLE_OP shop[$side_number|].enhance.range.damage add 4}
                                    {VARIABLE_OP shop[$side_number|].enhance.both.damage  add 4}
                                    {VARIABLE_OP shop[$side_number|].enhance.melee.strikes add 1}
                                    {VARIABLE_OP shop[$side_number|].enhance.range.strikes add 1}
                                    {VARIABLE_OP shop[$side_number|].enhance.both.strikes add 1}

                                    [object]
                                        silent=yes
                                        [effect]
                                            apply_to=attack
                                            increase_damage=4
                                        [/effect]
                                        [effect]
                                            apply_to=attack
                                            increase_attacks=1
                                        [/effect]
                                    [/object]
                                [/then]
                            [/if]
                        [/command]
                    [/option]
(sorry for the bad indenting, wmlindent was messing with me :P )

OK, so I was trying to figure out how to reduce that and its similarly complicated and inelegant brethren code with lua. I thought about reducing the [option] code, BUT here's the snag I ran into: If you can use wesnoth.fire or wesnoth.wml_actions to deal with a WML tag, how do you deal with a sub-tag of that tag? Eg:

Code: Select all

function wesnoth.wml_actions.shop_option(cfg)
	wesnoth.wml_actions.("option", {
How can I affect things like the [show_if] and [command], as well as any sub-tags they might have? If it's not possible, any suggestions on how I could prune the code? I'm especially hoping the number of vars can be cut down. I already have approximately 183 vars set up in an array for each of the five players, and I think that number is still going to grow.

This is going to be used in multiplayer, BTW. Does that make any difference?

Please excuse me if I'm not being clear; I'm still not up on the terminology yet. :lol2:

Thank you for ya help. :)
Creator of Shadows of Deception (for 1.12) and co-creator of the Era of Chaos (for 1.12/1.13).
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
Anonymissimus
Inactive Developer
Posts: 2460
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: vultraz's lua questions

Post by Anonymissimus »

Well, you seem to have some general misunderstanding. You can't "call" [option] since it's not a wml action tag. You need to call the base tag which it is an argument to, [message] in this case, and pass [option] included in a wml table argument to that [message] call.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: vultraz's lua questions

Post by Sapient »

If you really need to track all that information then I don't see how you should reduce the number of variables being used. Every separate thing being tracked really deserves its own variable, and attempting to compress them into a single variable would needlessly complicate the code. If you don't need the information then why track it though?

The amount of typing to code each option can however be reduced by using functions to generate the code for gold management and class-related checks, etc. You don't necessarily need lua to do that. An alternative to [show_if] is to conditionally store options in a variable then use [insert_tag] to insert the appropriate options.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
vultraz
Developer
Posts: 959
Joined: February 7th, 2011, 12:51 pm
Location: Dodging Daleks

Re: vultraz's lua questions

Post by vultraz »

Anonymissimus wrote: You can't "call" [option] since it's not a wml action tag. You need to call the base tag which it is an argument to, [message] in this case, and pass [option] included in a wml table argument to that [message] call.
mmk I'll figure that out how to do that.
Sapient wrote: If you really need to track all that information then I don't see how you should reduce the number of variables being used. Every separate thing being tracked really deserves its own variable, and attempting to compress them into a single variable would needlessly complicate the code. If you don't need the information then why track it though?
The fact is I don't fully understand the purpose of every variable I'm working with (the shop code is mostly from SXRPG, and I'm just editing it). I want to do a rewrite of the entire thing, so as to only use the variables that are very necessary and shrink the code (plus it's easier to work with something you understand XD ). I know lua can't reduce the number of something that you need (eg vars); just was hoping it might be able to handle it more efficiently. ;)
Sapient wrote: The amount of typing to code each option can however be reduced by using functions to generate the code for gold management and class-related checks, etc. You don't necessarily need lua to do that. An alternative to [show_if] is to conditionally store options in a variable then use [insert_tag] to insert the appropriate options.
I'd like to use lua for some major sections of the code (besides and maybe including the options), as they probably could be done much more simply (I hope). I'll also look at those WML possibilities, just see what works best.

So...I'll just get started...and see where I go. If I have any problems I'll post them here. First up-The [set_menu_item] bit.
Thanks for the suggestions and help. :D
Creator of Shadows of Deception (for 1.12) and co-creator of the Era of Chaos (for 1.12/1.13).
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
User avatar
Elvish_Hunter
Forum Moderator
Posts: 1446
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: vultraz's lua questions

Post by Elvish_Hunter »

Anonymissimus wrote:You can't "call" [option] since it's not a wml action tag.
Just for completeness, there is a way to call non-action WML tags: helper.set_wml_tag_metatable
Current maintainer of these add-ons:
1.14: The Sojournings of Grog, A Rough Life, The White Troll (co-author), Wesnoth Lua Pack
1.12: Children of Dragons
Anonymissimus
Inactive Developer
Posts: 2460
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: vultraz's lua questions

Post by Anonymissimus »

Elvish_Hunter wrote:
Anonymissimus wrote:You can't "call" [option] since it's not a wml action tag.
Just for completeness, there is a way to call non-action WML tags: helper.set_wml_tag_metatable
Why do you call that a "call" ? It just expands to the syntax of a wml table, it doesn't call any call stack or function associated with the execution of the tag since it has none.
For what it's worth, I always found these set_something_metatable functions confusing since they hide the underlying syntax a wml table requires; I'd have had an easier time learning it without them.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
Luther
Posts: 115
Joined: July 28th, 2007, 5:19 pm
Location: USA

Re: vultraz's lua questions

Post by Luther »

Anonymissimus wrote: For what it's worth, I always found these set_something_metatable functions confusing since they hide the underlying syntax a wml table requires; I'd have had an easier time learning it without them.
For that matter, functions and WML macros always hide their underlying power, but we have to use them to keep our code clean and consistent. Using set_wml_tag_metatable saves a lot of typing and makes the code much easier to read. If you use it consistently, you don't even need to understand the structure of a WML table beyond what you need to be able to write WML. You just need to know that "T.tag_name{ <tag content> }" returns a tag. I put Luther's Lua Pack / Lua Globals on the add-on server mainly to encourage that kind of habitual usage. (Though I don't know if anyone's using it....)
User avatar
vultraz
Developer
Posts: 959
Joined: February 7th, 2011, 12:51 pm
Location: Dodging Daleks

Re: vultraz's lua questions

Post by vultraz »

Ok I decided to take a shot at my unit death code for practice and then move to the shop...but I have a problem.

WML version:

Code: Select all

[if]
            [have_unit]
                side=6
                canrecruit=yes
            [/have_unit]
            [then]
                {VARIABLE_OP total_bosses_present add 1}
                {VARIABLE_OP current_bosses_present add 1}
                {VARIABLE boss_6_present yes}
                [store_starting_location]
                    side=6
                    variable=boss_location_6
                [/store_starting_location]
            [/then]
            [else]
                {CLEAR_VARIABLE boss_6_present}
            [/else]
        [/if]

        [if]
            [have_unit]
                side=7
                canrecruit=yes
            [/have_unit]
            [then]
                {VARIABLE_OP total_bosses_present add 1}
                {VARIABLE_OP current_bosses_present add 1}
                {VARIABLE boss_7_present yes}
                [store_starting_location]
                    side=7
                    variable=boss_location_7
                [/store_starting_location]
            [/then]
            [else]
                {CLEAR_VARIABLE boss_7_present}
            [/else]
        [/if]

        [if]
            [have_unit]
                side=8
                canrecruit=yes
            [/have_unit]
            [then]
                {VARIABLE_OP total_bosses_present add 1}
                {VARIABLE_OP current_bosses_present add 1}
                {VARIABLE boss_8_present yes}
                [store_starting_location]
                    side=8
                    variable=boss_location_8
                [/store_starting_location]
            [/then]
            [else]
                {CLEAR_VARIABLE boss_8_present}
            [/else]
        [/if]

        [if]
            [have_unit]
                side=9
                canrecruit=yes
            [/have_unit]
            [then]
                {VARIABLE_OP total_bosses_present add 1}
                {VARIABLE_OP current_bosses_present add 1}
                {VARIABLE boss_9_present yes}
                [store_starting_location]
                    side=9
                    variable=boss_location_9
                [/store_starting_location]
            [/then]
            [else]
                {CLEAR_VARIABLE boss_9_present}
            [/else]
        [/if]
How far I've gotten in the lua:

Code: Select all

[lua]
	    code = << 
		boss_side = 6
		total_bosses = 0
		current_bosses = 0
		yes = yes
		while boss_side ~= 10 do
			if assert(unit.canrecruit, unit.side == wesnoth.match_unit(unit, { canrecruit = "true", side = boss_side })) then
				total_bosses = total_bosses + 1
				current_bosses = current_bosses + 1 
					wesnoth.wml_actions.store_starting_location( { side = "boss_side", variable = "boss_location_" .. boss_side } )
					wesnoth.set_variable( "boss_" .. boss_side .. "_present", yes )
				boss_side = boss_side + 1
			end
			if boss_side == 10 then break end
		end
		wesnoth.set_variable( "total_bosses_present", total_bosses )
		wesnoth.set_variable( "current_bosses_present", current_bosses )
		boss_side = nil
		total_bosses = nil
		current_bosses = nil
		yes = nil
	    >>
	[/lua]
I'm sure it could be more elegant...but for now the problem is that' i'm getting errors about 'unit' being a nil variable. I know there;s something wrong with the way it's checking for a unit that matches, but I can't put my finger on it....it shouldn't be 'unit'...I guess....can someone help? Sorry but I'm lost, and I'm quite new to lua, so.... :mrgreen:
Creator of Shadows of Deception (for 1.12) and co-creator of the Era of Chaos (for 1.12/1.13).
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
Anonymissimus
Inactive Developer
Posts: 2460
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: vultraz's lua questions

Post by Anonymissimus »

Well, I don't like to look through code to maybe spot errors. But:
- First you should probably put the lua code into a pure lua file which you load with wesnoth.dofile from within the [lua][/lua] tag, since you do not need the startscreen-F5-load-scenario cycle then, and you can syntax-check the lua code without wesnoth. (When I edit lua it's matter of a second to reload from a right-lick menu some changed code and execute it.)
- And then learn to debug, with wesnoth.message(tostring(some_var)) for instance. Just like {DEBUG_MGS ...} in wml.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
User avatar
8680
Moderator Emeritus
Posts: 742
Joined: March 20th, 2011, 11:45 pm
Location: The past

Re: vultraz's lua questions

Post by 8680 »

My analysis:

Code: Select all

[lua]
    code = <<
        -- these are currently global variables, which means they exist until the end of the scenario
        -- by the way you use them, I think you want them to be local variables
        -- you can make them local by putting 'local' in front of their names when you initialize them here
        -- http://www.lua.org/manual/5.1/manual.html#2.4.7
        -- http://www.lua.org/manual/5.1/manual.html#2.6
        -- http://lua-users.org/wiki/ScopeTutorial
        boss_side = 6
        total_bosses = 0
        current_bosses = 0
        -- what's the point of this?
        -- you're assigning 'yes' (which doesn't exist yet) to itself
        yes = yes
        -- to fix the problem with 'unit', add this here:
        -- unit = wesnoth.get_variable "unit"
        -- instead of 'x = 6 ... while x ~= 10 do ... x = x+1 end'
        -- you can use 'for x = 6, 10 do ... end'
        -- http://www.lua.org/manual/5.1/manual.html#2.4.4
        -- http://www.lua.org/manual/5.1/manual.html#2.4.5
        -- http://lua-users.org/wiki/ControlStructureTutorial
        while boss_side ~= 10 do
            -- the problem with 'unit' is that you haven't requested it from the engine yet
            -- the automatic variables are not automatically copied into Lua.
            if assert(unit.canrecruit, unit.side == wesnoth.match_unit(unit, { canrecruit = "true", side = boss_side })) then
                total_bosses = total_bosses + 1
                current_bosses = current_bosses + 1
                wesnoth.wml_actions.store_starting_location( { side = "boss_side", variable = "boss_location_" .. boss_side } )
                -- use 'true', not 'yes'
                wesnoth.set_variable( "boss_" .. boss_side .. "_present", yes )
                boss_side = boss_side + 1
            end
            -- this is pointless, the loop will already stop when boss_side == 10
            -- because of the loop conditional ('while boss_side ~= 10').
            if boss_side == 10 then break end
        end
        wesnoth.set_variable( "total_bosses_present", total_bosses )
        wesnoth.set_variable( "current_bosses_present", current_bosses )
        -- these are global variables, so assigning nil to them won't delete them (I think)
        boss_side = nil
        total_bosses = nil
        current_bosses = nil
        -- 'yes' has always been nil
        yes = nil
    >>
[/lua]
User avatar
vultraz
Developer
Posts: 959
Joined: February 7th, 2011, 12:51 pm
Location: Dodging Daleks

Re: vultraz's lua questions

Post by vultraz »

Thanks for the help! But unfortunately it still seems to be chucking that error :(

Code: Select all

[lua]
	    code = << 
		local total_bosses = 0
		local current_bosses = 0
		unit = wesnoth.get_variable "unit"
		for boss_side = 6, 10 do
			if assert(unit.canrecruit, unit.side == wesnoth.match_unit(unit, { canrecruit = "true", side = boss_side })) then
				total_bosses = total_bosses + 1
				current_bosses = current_bosses + 1 
					wesnoth.wml_actions.store_starting_location( { side = "boss_side", variable = "boss_location_" .. boss_side } )
					wesnoth.set_variable( "boss_" .. boss_side .. "_present", true )
			end
		end
		wesnoth.set_variable( "total_bosses_present", total_bosses )
		wesnoth.set_variable( "current_bosses_present", current_bosses )
		boss_side = nil
		total_bosses = nil
		current_bosses = nil
	    >>
	[/lua]
I hope I haven't missed something obvious...I followed 8680's excellent instructions...but yeah...

Screenshot:
error
error
Creator of Shadows of Deception (for 1.12) and co-creator of the Era of Chaos (for 1.12/1.13).
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
User avatar
8680
Moderator Emeritus
Posts: 742
Joined: March 20th, 2011, 11:45 pm
Location: The past

Re: vultraz's lua questions

Post by 8680 »

Well, here's some more annotations.

Code: Select all

[lua]
        code = << 
        local total_bosses = 0
        local current_bosses = 0
        -- try making unit local
        unit = wesnoth.get_variable "unit"
        for boss_side = 6, 10 do
            -- I don't understand what you're trying to do with this assert()
            -- what you're currently doing is this:
            --    if ([unit] is a leader) then
            --        return true
            --    else
            --        -- this merits further annotation
            --        -- (unit.canrecruit == "true") will always be false, as they are a boolean and a string
            --        -- and the whole thing is always false, as you're ultimately comparing a number and a boolean
            --        if ([unit]'s side number) == ( (unit.canrecruit == "true") and ([unit] is on side [boss_side]) ) then
            --            print("true")
            --        else
            --            print("false")
            --        end
            --    end
            -- this message will be "true" if:
            if assert(unit.canrecruit, unit.side == wesnoth.match_unit(unit, { canrecruit = "true", side = boss_side })) then
                total_bosses = total_bosses + 1
                current_bosses = current_bosses + 1
                -- 'side' needs to be a number; "boss_side" is a string
                -- if you want to assign the value of 'boss_side' to 'side', remove the quotes
                wesnoth.wml_actions.store_starting_location( { side = "boss_side", variable = "boss_location_" .. boss_side } )
                wesnoth.set_variable( "boss_" .. boss_side .. "_present", true )
            end
        end
        wesnoth.set_variable( "total_bosses_present", total_bosses )
        wesnoth.set_variable( "current_bosses_present", current_bosses )
        -- boss_side was local to the for loop and was deleted when it ended
        boss_side = nil
        -- these are locals and will be deleted when the [lua] tag is exited; don't bother setting them to nil
        total_bosses = nil
        current_bosses = nil
        >>
[/lua]
Luther
Posts: 115
Joined: July 28th, 2007, 5:19 pm
Location: USA

Re: vultraz's lua questions

Post by Luther »

What is the value of the 'name=' key in your [event] tag? The error you're getting suggests to me that you're using a type of event which doesn't define a 'unit' variable. Maybe you could post your whole [event] tag?
User avatar
Elvish_Hunter
Forum Moderator
Posts: 1446
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: vultraz's lua questions

Post by Elvish_Hunter »

About your error: what does it say?

Code: Select all

6: attempt to index global 'unit' (a nil value)
And what do we have at line 6?

Code: Select all

if assert(unit.canrecruit, unit.side == wesnoth.match_unit(unit, { canrecruit = "true", side = boss_side })) then
First of all, you can avoid getting units from a variable, because we have a Lua function designed to "store" (perhaps not the proper term) in Lua all matching units: wesnoth.get_units.
At this point, you can iterate through all acquired unit with a line like

Code: Select all

for index, unit in ipairs( wesnoth.get_units ( { side = 1 } ) ) do
You may want to avoid using assert, as any non-matching unit will crash your code:

Code: Select all

Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> a=1
> assert(a==9)
stdin:1: assertion failed!
stack traceback:
	[C]: in function 'assert'
	stdin:1: in main chunk
	[C]: ?
An if/then/else cycle is enough.Finally, this line

Code: Select all

wesnoth.set_variable( "boss_" .. boss_side .. "_present", true )
can be written also by using string.format:

Code: Select all

wesnoth.set_variable( string.format( "boss_%d_present", boss_side), true )
Depending on what do you want to do (check if a unit exists?), an alternative may be using wesnoth.eval_conditional.
Current maintainer of these add-ons:
1.14: The Sojournings of Grog, A Rough Life, The White Troll (co-author), Wesnoth Lua Pack
1.12: Children of Dragons
User avatar
vultraz
Developer
Posts: 959
Joined: February 7th, 2011, 12:51 pm
Location: Dodging Daleks

Re: vultraz's lua questions

Post by vultraz »

I got it working! :D :D :D

Code: Select all

	[lua]
	    code = <<
		local total_bosses = 0
		local current_bosses = 0
		for boss_side = 6, 10 do
			local result = wesnoth.eval_conditional { 
				{ "have_unit", { canrecruit = "true", side = boss_side } } 
			}
			if result == true then
				total_bosses = total_bosses + 1
				current_bosses = current_bosses + 1
					wesnoth.wml_actions.store_starting_location( { side = "boss_side", variable = "boss_location_" .. boss_side } )
					wesnoth.set_variable( string.format( "boss_%d_present", boss_side), true )
			end
		end
		wesnoth.set_variable( "total_bosses_present", total_bosses )
		wesnoth.set_variable( "current_bosses_present", current_bosses )
	    >>
	[/lua]
Thanks for the help Elvish Hunter! Now...to continue...MORE LUA!! :mrgreen:
Creator of Shadows of Deception (for 1.12) and co-creator of the Era of Chaos (for 1.12/1.13).
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
Post Reply