dabber's questions: vision to location

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
dabber
Posts: 464
Joined: April 2nd, 2014, 6:41 pm

Re: dabber's questions: object on unit

Post by dabber »

Many leaders are created in the side definitions. How do I set a variable in the scenario file and then use that variable to modify the leader in the side definition? Even if I set the variable in a prestart event, I get errors trying to access it in the side definition.
Pilauli
Posts: 115
Joined: August 18th, 2020, 12:56 pm

Re: dabber's questions: object on unit

Post by Pilauli »

If you figure it out, I'd love to know that, too! I can share a couple of workarounds I thought of, though:

- When you create the side, DON'T put a leader in it. Instead, write no_leader=yes. Then, in the prestart event, set your variable, then create your leader unit (making sure to write "canrecruit=yes" in its definition.)

- Since variables persist from one scenario to the next, you might be able to create a dummy scenario for setting variables that will be used in later scenarios.
User avatar
WhiteWolf
Forum Moderator
Posts: 769
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: dabber's questions: object on unit

Post by WhiteWolf »

I'm not sure I understand the question entirely, but if you want to define a variable that is already accessed in a side definition, then I guess that's what a preload event is for, or equivalently, you could define it at the very end of the previous scenario.
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
User avatar
dabber
Posts: 464
Joined: April 2nd, 2014, 6:41 pm

Re: dabber's questions: object on unit

Post by dabber »

preload event doesn't work. A lua error shows up, and its definitely from using the variable. I am using 1.14.9 (which reminds me, I should upgrade to 14.14), so maybe that works in 1.15.x?
User avatar
Ravana
Forum Moderator
Posts: 2953
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: dabber's questions: object on unit

Post by Ravana »

Preload and variable should not be related. I doubt [side] supports variable evaluation.

So use case I would solve by setting objects during prestart.
User avatar
dabber
Posts: 464
Joined: April 2nd, 2014, 6:41 pm

Re: dabber's questions: object on unit

Post by dabber »

I solved the leader modification problem with a turn 1 event that does all the work. That is much easier long term, because now each scenario needs less editing. It also lets me work on any units spawned in the [side] definition automatically.
User avatar
dabber
Posts: 464
Joined: April 2nd, 2014, 6:41 pm

Re: dabber's questions: logging explanation

Post by dabber »

I solved my unit modification issue using a "unit placed" event.


Where in the documentation web pages is logging explained? Domains, levels, files, etc. I've pieced together enough knowledge to find my debug outputs in a file, but I have no understanding.
User avatar
dabber
Posts: 464
Joined: April 2nd, 2014, 6:41 pm

Re: dabber's questions: objective notes

Post by dabber »

Is there a way to append to the existing notes section of objectives? I want to make one macro/event for the whole campaign that adds information without having to modify every scenario. Can I read the objectives into a variable in some fashion and then modify?
User avatar
Lord-Knightmare
Discord Moderator
Posts: 2343
Joined: May 24th, 2010, 5:26 pm
Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
Contact:

Re: dabber's questions: objective notes

Post by Lord-Knightmare »

dabber wrote: July 11th, 2022, 11:41 am Is there a way to append to the existing notes section of objectives? I want to make one macro/event for the whole campaign that adds information without having to modify every scenario. Can I read the objectives into a variable in some fashion and then modify?
Yes

You can store the descriptions as text and then have them adding to objectives.

like:

Code: Select all

{VARIABLE win_condition "Defeat Delfador"}
{VARIABLE defeat_condition "Death of Konrad"}

{SCENARIO_OBJECTIVE ("$win_condition") ("$defeat_conditon")}
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
User avatar
dabber
Posts: 464
Joined: April 2nd, 2014, 6:41 pm

Re: dabber's questions: objective notes

Post by dabber »

Lord-Knightmare, thanks for the response, but that doesn't do what I'm after. Each scenario already sets objectives. I want to add the same note to every scenario objective, without having to modify each scenario file. I want to read the objective note previously set.

I tried {VARIABLE old_note $objective.note} but that didn't work.
User avatar
beetlenaut
Developer
Posts: 2814
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: dabber's questions: objective notes

Post by beetlenaut »

dabber wrote: July 11th, 2022, 1:38 pm I tried {VARIABLE old_note $objective.note} but that didn't work.
That's because "objective" is not a stored container variable, and there is no command to store it. You may be able to access the strings with lua, but you would still have to do it in each scenario file.

What I think you should do is use a program that allows you to search & replace across multiple files. Search your scenario folder for [/objectives] and replace it with

Code: Select all

    [note]
        # Your new note
    [/note]
[/objectives]
Notepad++ can apparently do this, and I know Kate can as well. I'm sure there are many more options no matter what system you are on. (Do back up your scenario folder before trying it the first time though. I know this from experience.)
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
dabber
Posts: 464
Joined: April 2nd, 2014, 6:41 pm

Re: dabber's questions: objective notes

Post by dabber »

Thanks beetlenaut. Search+replace is probably the best option. I wanted a more programmatical method. Maybe I can still create that, I just have to put using it into each scenario.
User avatar
dabber
Posts: 464
Joined: April 2nd, 2014, 6:41 pm

Re: dabber's questions: recruit cost

Post by dabber »

How can I find the cost to recruit a unit, inside a scenario? Once a leader has too little money to recruit, I want him to do something. When he has enough money, I want him to do something else. For that to happen, I need to figure out the cost of the one unit type he can recruit. But since I want this to work for different leaders with different recruit types, I need a way to programmatically figure out the recruit cost.
User avatar
Pentarctagon
Project Manager
Posts: 5533
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: dabber's questions: objective notes

Post by Pentarctagon »

You could use [store_unit_type] and check its cost.
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
dabber
Posts: 464
Joined: April 2nd, 2014, 6:41 pm

Re: dabber's questions: recruit cost

Post by dabber »

Thanks! Certainly that was a function I didn't realize existed. I think that means the critical code is basically this, and it works!

Code: Select all

[store_side]
    side={SIDE}
    variable=this_side
[/store_side]
[store_unit_type]
    type=$this_side.recruit
    variable=recruit_option
[/store_unit_type]
{VARIABLE min_gold $recruit_option.cost}
For anyone interested, this is the code I'm really using:

Code: Select all

#define RECRUIT_COST_MIN SIDE
## returns gold_min_to_recruit
    [store_side]
        side={SIDE}
        variable=this_side
    [/store_side]
    [store_unit_type]
        type=$this_side.recruit
        variable=recruit_option
    [/store_unit_type]
    {VARIABLE gold_min_to_recruit 10000}
    [foreach]
        array=recruit_option
        [do]
            {ERROR "Recruit_Cost_Min : index $i cost $this_item.cost"}
            [if]
                [variable]
                    name=this_item.cost
                    less_than=$gold_min_to_recruit
                [/variable]
                [then]
                    {VARIABLE gold_min_to_recruit $this_item.cost.cost}
                    {ERROR "Recruit_Cost_Min : gold_min_to_recruit = $gold_min_to_recruit"}
                [/then]
            [/if]
        [/do]
    [/foreach]
    {CLEAR_VARIABLE this_side,recruit_option}
#enddef
Last edited by dabber on September 1st, 2023, 3:19 pm, edited 1 time in total.
Post Reply