Inserting predefined leader and units into side def
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.
Inserting predefined leader and units into side def
Hello,
As a sort of structured programming, I would like to predefine units apart (and much more, see below). This allows keeping a clean code structure and logic, instead of having it polluted by tons of lengthy definitions that should belong elsewhere, namely in corresponding modules. However, there are no keys such as "leader=id" or "unit=id", at least to my knowledge. (Since there is no list of keys, who knows?) Example:
Is there a simple way to do this, in WML? (I mean, no macros!)
Side-question: is it at all possible to define things, in the same file, after they are used or otherwise referenced? Again, this would allow showing the overall logic of scenarios, or other big pieces of code, unpolluted by big definitions.
Actually, I would love all tags (=blocks) to have an id, optional or not, and this id be usable instead of a block in a "block=id" key. Example:
Well, it may not the best illustration, but you see what I mean...
As a sort of structured programming, I would like to predefine units apart (and much more, see below). This allows keeping a clean code structure and logic, instead of having it polluted by tons of lengthy definitions that should belong elsewhere, namely in corresponding modules. However, there are no keys such as "leader=id" or "unit=id", at least to my knowledge. (Since there is no list of keys, who knows?) Example:
Code: Select all
[side]
id=heroes
...
leader=Turina
units=Malinu,Nipula,Sakilu
...
[/event]
Side-question: is it at all possible to define things, in the same file, after they are used or otherwise referenced? Again, this would allow showing the overall logic of scenarios, or other big pieces of code, unpolluted by big definitions.
Actually, I would love all tags (=blocks) to have an id, optional or not, and this id be usable instead of a block in a "block=id" key. Example:
Code: Select all
[event]
name=moveto
filter=cave_area
message=cave_speach
message=cave_answer
[/event]
Last edited by denispir on November 1st, 2019, 11:44 am, edited 1 time in total.
Re: Inserting predefined leader and units into side def
In terms of having other people understand (and maybe maintain) your code, it's probably best to use the same coding style as the most recently added campaigns (SotA and WoV). That sadly does mean using macros for defining all your heroes.
The
It's an interpreted language with all variables being global. If you have anis it at all possible to define things, in the same file, after they are used or otherwise referenced?
[event]
on line 200 that sets a variable then an [event]
on line 100 could read the variable (assuming that event fires after the one that sets the variable).The
cave_area
could be done like this (code copied from Sceptre_of_Fire/scenarios/2_Closing_the_Gates.cfg)Code: Select all
[event]
name=prestart
[set_variables]
name=glyphs
[value]
x,y=9,11
[/value]
[value]
x,y=14,3
[/value]
[/set_variables]
[/event]
Code: Select all
[event]
name=moveto
first_time_only=no
[filter]
side=1
[filter_location]
find_in=glyphs
[/filter_location]
[/filter]
...
Re: Inserting predefined leader and units into side def
Yes, I understand and actually support the fact of having a common coding style (I even have a language project that enforces that). However, this coding style sould be good, meaning clear, and the language must allow and encourage that... Which is not the case with WML: one cannot even have the simplest form of structured programming which is possible even with most ancient languages, or one must fight against the language to do so.
is it at all possible to define things, in the same file, after they are used or otherwise referenced?
All right! So, whenever it is not needed or whishable to export definitions into an external file, one still can structure the code and have definitions come after. I will try soon.
EDIT: Not possible with macros indeed... So it must be done with variables, and dealing with units in variable is all but easy. Why aren't id's variable names in WML? Why aren't there allonwing to replace sub-blocks (sub-tags) with an id?
Ah yes, did not think at using the "find_in" key, it is great for that!octalot wrote: ↑October 31st, 2019, 3:24 pm Thecave_area
could be done like this (code copied from Sceptre_of_Fire/scenarios/2_Closing_the_Gates.cfg)
Code: Select all
[event] name=prestart [set_variables] name=glyphs [value] x,y=9,11 [/value] [value] x,y=14,3 [/value] [/set_variables] [/event]
Code: Select all
[event] name=moveto first_time_only=no [filter] side=1 [filter_location] find_in=glyphs [/filter_location] [/filter] ...
Thank you, Octalot!
- Pentarctagon
- Project Manager
- Posts: 5564
- Joined: March 22nd, 2009, 10:50 pm
- Location: Earth (occasionally)
Re: Inserting predefined leader and units into side def
You could make extensive use of [insert_tag], I suppose. I don't really see the difference between labelling a block of code with an id and defining it as a macro though.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
take one down, patch it around
-2,147,483,648 little bugs in the code
Re: Inserting predefined leader and units into side def
Instead of using find in like that for so sure sinngle locations you can always define "speciual_locations" in the map.efitor give them an I'd and use that in your code filter.
Also if you really hate marcos I think your only option is to write your scenario completey in lua, maybe even use lua scenario_generation.
Also if you really hate marcos I think your only option is to write your scenario completey in lua, maybe even use lua scenario_generation.
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.
Re: Inserting predefined leader and units into side def
Well, things with ids are like ordinary variable in a real prog lang. We can access, modify, copy, etc... Actually, that's imo the main default of WML, and it has many , that not everything has an id...Pentarctagon wrote: ↑November 1st, 2019, 1:23 pm You could make extensive use of [insert_tag], I suppose. I don't really see the difference between labelling a block of code with an id and defining it as a macro though.
Re: Inserting predefined leader and units into side def
It's not that I hate macros, simply there are too many languages needed to define games, all mixed and totally incoherent:
- basic WML as data description language
- formulas
- the pseudo algorithmic sub-language (conditions, filters, loops...)
- the weird sub-language for variable handling (veeery obscure)
- the funny coding of image modifs
- the whole big, undecipherable mess of AI parameterizing and customizing
- macros used as code blocks
- macros used as pseudo-procedures (veeery dangerous, as many programmers know)
- Lua
- + Lua for (micro-)AIs, which is still different, due to the srtucture of (micro-)AIs
Re: Inserting predefined leader and units into side def
[fire_event] does what I think you are asking for. It is easier way to reuse actionWML than [insert_tag].
Re: Inserting predefined leader and units into side def
Yes, thank you Ravana. I start to use much more custom events for all kinds of structured programming needs: I realised that since all things interesting anyway happen in an event, we can code nearly everything in there! Actually, custom event is a misnomer: it's an action, or part of it, not an event in the Wesnoth sense. In other wordsn it's an effect, not a cause=>effect pair. There should be an [action_block] tag, instead of [event] with custom id name.
- Celtic_Minstrel
- Developer
- Posts: 2207
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Inserting predefined leader and units into side def
A better way to do this is with a time area.
Code: Select all
[time_area]
id=glyphs
x=9,14
y=11,3
[/time_area]
Code: Select all
[event]
name=moveto
first_time_only=no
[filter]
side=1
[filter_location]
area=glyphs
[/filter_location]
[/filter]
...
Re: Inserting predefined leader and units into side def
Great! An abvious case of "feature hijacking" however... But it proves that a feature such aas [area] should exist, no?Celtic_Minstrel wrote: ↑November 3rd, 2019, 4:18 pm A better way to do this is with a time area. [removed code, see above]
A minor downside of that is that the time area might need to duplicate the schedule…
- Celtic_Minstrel
- Developer
- Posts: 2207
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Inserting predefined leader and units into side def
I don't think so, since the logic of a defined area is pretty much identical to what the current tag does. However, I could support renaming
[time_area]
to [area]
and making sure it defaults to falling back on the scenario schedule if it doesn't contain any [time]
tags.