spaces in names of containers
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.
-
- Posts: 876
- Joined: November 28th, 2008, 6:18 pm
spaces in names of containers
Wiki says:
The problem is I didn't find a way how to access a content of such a container directly, I mean by something like
I can access it only indirectly, by means of an auxiliary variable:
but it looks a space is considered an alphabetic character too: for example it is possible to use a container "Dwarvish Guardsman".Each variable is given a name. A given variable name may contain only alphabetic characters, digits, and underscores.
The problem is I didn't find a way how to access a content of such a container directly, I mean by something like
Code: Select all
$units."Dwarvish Guardsman".max_hitpoints
Code: Select all
[set_variables]
name=aux_var
to_variable=units.Dwarvish Guardsman
[/set_variables]
.... $aux_var.max_hitpoints ....
Last edited by SlowThinker on December 15th, 2010, 11:06 pm, edited 1 time in total.
I work on Conquest Minus • I use DFoolWide, Retro Terrain Package and the add-on 'High Contrast Water'
I moved to Nosebane's corner (Doc Paterson's signature); I am spending my time there, so PM me if I don't answer your post in forums
I moved to Nosebane's corner (Doc Paterson's signature); I am spending my time there, so PM me if I don't answer your post in forums
Re: spaces in names of containers
Have you tried loading a savefile of a scenario using variables with spaces in their names? The last time I checked (which was quite a long time ago) you'll get some (non-fatal) errors.
In any case I'm pretty sure it's not supported. It might still unintendedly work in some cases, but that's another story.
In any case I'm pretty sure it's not supported. It might still unintendedly work in some cases, but that's another story.
-
- Posts: 876
- Joined: November 28th, 2008, 6:18 pm
Re: spaces in names of containers
You are right. The containers with spaces were kicked.zookeeper wrote:Have you tried loading a savefile of a scenario using variables with spaces in their names? The last time I checked (which was quite a long time ago) you'll get some (non-fatal) errors.
Do you have an idea how I can implement a list of unit types, which
- can be scanned/searched
- and simultaneously their elements can be directly accessed
I planned to use
Code: Select all
[Spearman]
heal_cost="25"
...
[/Spearman]
[item]
name="Spearman"
[/item]
[Dwarvish Guardsman]
heal_cost="45"
...
[/Dwarvish Guardsman]
[item]
name="Dwarvish Guardsman"
[/item]
I could replace spaces by underscores and return them back, but does WML allow to manipulate chars in strings?
Last edited by SlowThinker on December 16th, 2010, 12:59 am, edited 1 time in total.
I work on Conquest Minus • I use DFoolWide, Retro Terrain Package and the add-on 'High Contrast Water'
I moved to Nosebane's corner (Doc Paterson's signature); I am spending my time there, so PM me if I don't answer your post in forums
I moved to Nosebane's corner (Doc Paterson's signature); I am spending my time there, so PM me if I don't answer your post in forums
Re: spaces in names of containers
SlowThinker wrote:Do you have an idea how I can implement a list of unit types, which
can be scanned/searched
and simultaneously their elements can be directly accessed
Code: Select all
[store_unit]
[filter]
type=Spearman
[/filter]
kill=#no/yes
variable=spearman
[/store_unit]
{FOREACH spearman i}
{VARIABLE spearman[$i].max_hitpoints 45}
{NEXT i}

If you want to directly access a variable including multiple unit types, you cannot separate them by types unless you do some fancy maneuvering. E.G.: ###Note: this assumes that the types are already stored.###
Code: Select all
{MODIFY_UNIT (
type=Spearman
find_in=types ###name of variable###
) max_hitpoints 45}
Of course, the supremely easiest thing to do is this:
Code: Select all
{MODIFY_UNIT (type=Spearman) max_hitpoints 45}
Code: Select all
{MODIFY_UNIT (
type=Spearman
find_in=types ###name of variable###
) max_hitpoints 45}
-
- Posts: 876
- Joined: November 28th, 2008, 6:18 pm
Re: spaces in names of containers
bigkahuna, sorry for the confusion:
I talk about an user-made container, not about a container acquired by [store_unit].
(i just replaced max_hitpoints by heal_cost in my code above)
This example describes what I need:
I need a list of unit types, and to store an attribute "heal_cost" with each type.
Once it is created, I need:
I talk about an user-made container, not about a container acquired by [store_unit].
(i just replaced max_hitpoints by heal_cost in my code above)
This example describes what I need:
I need a list of unit types, and to store an attribute "heal_cost" with each type.
Once it is created, I need:
- a direct access, i.e. for a given unit_type I need to get access to unit_type.heal_cost
- ability to scan unit types, i.e. to be able to create a menu with all unit types in the list and their heal_cost values.
I work on Conquest Minus • I use DFoolWide, Retro Terrain Package and the add-on 'High Contrast Water'
I moved to Nosebane's corner (Doc Paterson's signature); I am spending my time there, so PM me if I don't answer your post in forums
I moved to Nosebane's corner (Doc Paterson's signature); I am spending my time there, so PM me if I don't answer your post in forums
Re: spaces in names of containers
I haven't tried it, but wouldn't this work? : my_container["Dwarvish Thunderguard"].hitpoints
Jazz is not dead, it just smells funny - Frank Zappa
Current projects: Internet meme Era, The Settlers of Wesnoth
Current projects: Internet meme Era, The Settlers of Wesnoth
Re: spaces in names of containers
Just out of curiosity, could you give me a link to the wiki section on how to make user-made tags/containers? I've always wondered how
Unless it is in Lua.

Re: spaces in names of containers
Sounds like something you'd need Lua for. With WML, the best you can do is something like this:SlowThinker wrote:You are right. The containers with spaces were kicked.zookeeper wrote:Have you tried loading a savefile of a scenario using variables with spaces in their names? The last time I checked (which was quite a long time ago) you'll get some (non-fatal) errors.
Do you have an idea how I can implement a list of unit types, which?
- can be scanned/searched
- and simultaneously their elements can be directly accessed
Code: Select all
[heal_costs]
[unit]
id=Spearman
heal_cost=25
[/unit]
[unit]
id=Dwarvish Guardsman
heal_cost=45
[/unit]
# ...
[/heal_costs]
Sure. To get a space-less version of a unit type name into a variable, all you need is this (untested):SlowThinker wrote:I could replace spaces by underscores and return them back, but does WML allow to manipulate chars in strings?
Code: Select all
[set_variables]
name=unittypewordlist
[split]
list=stored_guardsman.type
key=word
separator=" "
[/split]
[/set_variables]
# -> [unittypewordlist]
# word=Dwarvish
# [/unittypewordlist]
# [unittypewordlist]
# word=Guardsman
# [/unittypewordlist]
[set_variable]
name=typewithoutspaces
[join]
variable=unittypewordlist
key=word
separator=""
[/join]
[/set_variable]
# -> typewithoutspaces="DwarvishGuardsman"
-
- Posts: 7
- Joined: October 5th, 2006, 5:14 am
Re: spaces in names of containers
It is 1 line of WML to lookup, if you use the macro from utils.cfg
there is also LOOKUP_INDEX... you should know that, guy 
Code: Select all
[set_variables]
name=heal_costs
[value]
type="Dwarvish Guardsman"
heal_cost=45
[/value]
[value]
type="Spearman"
heal_cost=25
[/value]
[/set_variables]
{LOOKUP_VALUE heal_costs type "Dwarvish Guardsman" heal_cost $default_cost result}
{DEBUG_MSG "Dwarvish Guardsman has heal cost of $result"}

Re: spaces in names of containers
Mecha^Croc wrote:It is 1 line of WML to lookup, if you use the macro from utils.cfg
Yes, and LOOKUP_INDEX is 20 lines of WML and LOOKUP_VALUE is 38 lines. It's still a [while] loop.
-
- Posts: 876
- Joined: November 28th, 2008, 6:18 pm
Re: spaces in names of containers
Of course not. Arrays may be indexed by integers only: my_container[5].hitpointsDixie wrote:I haven't tried it, but wouldn't this work? : my_container["Dwarvish Thunderguard"].hitpoints
A 5th sub-container has a sense, but a Thunderguard'th sub-container does not.
By set_variables:bigkahuna wrote:Just out of curiosity, could you give me a link to the wiki section on how to make user-made tags/containers? I've always wondered howUnless it is in Lua.
http://wiki.wesnoth.org/InternalActions ... riables.5D
With [value] you can manually insert values (with to_variable you assign to another container/array: BTW I think this is a situation where container and container[0] have a different effect)
Edit 1:Also [variables] should work, but I suppose it rewrites all existing variables.
Edit 2
i wrote a nonsense, deleted
Last edited by SlowThinker on December 16th, 2010, 11:57 am, edited 2 times in total.
I work on Conquest Minus • I use DFoolWide, Retro Terrain Package and the add-on 'High Contrast Water'
I moved to Nosebane's corner (Doc Paterson's signature); I am spending my time there, so PM me if I don't answer your post in forums
I moved to Nosebane's corner (Doc Paterson's signature); I am spending my time there, so PM me if I don't answer your post in forums
-
- Posts: 876
- Joined: November 28th, 2008, 6:18 pm
Re: spaces in names of containers
I was referred to lua already, because recently I theoretically talked about a similar problem here. But I would have to learn lua, and also I want to understand wml abilities first.zookeeper wrote:Sounds like something you'd need Lua for.
Tested now, it works. Thank you. I will use this way because then I don't need to rewrite my code. (For "join" I will use "_" as a separator, beacuse then I can return back without an exigency to store the original value)Sure. To get a space-less version of a unit type name into a variable, all you need is this (untested):Code: Select all
[set_variables] name=unittypewordlist [split] ...
So a direct access to characters in a string (like string[5]) is impossible in a pure WML? (I don't count the possibility to split a string with all possible characters

This way is somewhat painful, but I suppose it wouldn't slow down the code, because the interpreter must use a loop for a "direct" access to heal_costs.Spearman too.Of course that means you have to search for the right container in a [while] loop everytime.Code: Select all
[heal_costs] [unit] id=Spearman heal_cost=25 [/unit]
This is why I don't understand the limitations for container names: theoretically any string that doesn't spoil the syntax could be allowed.
I work on Conquest Minus • I use DFoolWide, Retro Terrain Package and the add-on 'High Contrast Water'
I moved to Nosebane's corner (Doc Paterson's signature); I am spending my time there, so PM me if I don't answer your post in forums
I moved to Nosebane's corner (Doc Paterson's signature); I am spending my time there, so PM me if I don't answer your post in forums
-
- Posts: 876
- Joined: November 28th, 2008, 6:18 pm
Re: spaces in names of containers
A quality of my fastthinking is quite low.SlowThinker wrote:This way is somewhat painful, but I suppose it wouldn't slow down the code, because the interpreter must use a loop for a "direct" access to heal_costs.Spearman too.
This is why I don't understand the limitations for container names: theoretically any string that doesn't spoil the syntax could be allowed.
The loop that must be interpreted is a lot slower than an internal loop (except all the loop is translated as a whole, but this is not possible with [insert tag])
"This is why" is wrong, as there is no relationship between both sentences.
I work on Conquest Minus • I use DFoolWide, Retro Terrain Package and the add-on 'High Contrast Water'
I moved to Nosebane's corner (Doc Paterson's signature); I am spending my time there, so PM me if I don't answer your post in forums
I moved to Nosebane's corner (Doc Paterson's signature); I am spending my time there, so PM me if I don't answer your post in forums
Re: spaces in names of containers
WML does not have associative arrays (i.e. "dictionaries").
LOOKUP_VALUE is the closest thing to it that is currently available. If you want a pure WML approach, I highly recommend that you just use LOOKUP_VALUE. In fact, this thread should be considered soft-locked because that is a definitive answer for your problem.
I also suggest you stick to the basics of making code that is clearly understood and works correctly, rather than worrying about optimizing your WML for efficiency. Premature optimization is well known to be a bad influence-- it leads to code that is unnecessarily ugly and verbose and does not address any real bottlenecks.
LOOKUP_VALUE is the closest thing to it that is currently available. If you want a pure WML approach, I highly recommend that you just use LOOKUP_VALUE. In fact, this thread should be considered soft-locked because that is a definitive answer for your problem.
I also suggest you stick to the basics of making code that is clearly understood and works correctly, rather than worrying about optimizing your WML for efficiency. Premature optimization is well known to be a bad influence-- it leads to code that is unnecessarily ugly and verbose and does not address any real bottlenecks.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
-
- Posts: 876
- Joined: November 28th, 2008, 6:18 pm
Re: spaces in names of containers
I forgot to mention this:Sapient wrote:If you want a pure WML approach, I highly recommend that you just use LOOKUP_VALUE.
The problem of WML is there are situations where
- you can use a direct variable value
and simultaneously - you cannot use {LOOKUP_VALUE}
Inside a tag that shall be applied by [insert_tag]:
no {MACRO} may be used, and so no {LOOKUP_VALUE}
inside a declarational-type code:
no action-type code may be used, and so no {LOOKUP_VALUE}
I work on Conquest Minus • I use DFoolWide, Retro Terrain Package and the add-on 'High Contrast Water'
I moved to Nosebane's corner (Doc Paterson's signature); I am spending my time there, so PM me if I don't answer your post in forums
I moved to Nosebane's corner (Doc Paterson's signature); I am spending my time there, so PM me if I don't answer your post in forums