combining multiple variable names
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.
combining multiple variable names
I have a very interesting situation where i want to store units as "in_boat_$boat.id"
Then i would be able to run a {FOREACH in_boat_$boat.id i} to find all the units in a boat with a particular id however if i do this:
the variable stores properly but i fail to be able to access it again through the FOREACH statement.
I am sure their must be an easier way to do this. Here is my full code:
Thank you!!!
Then i would be able to run a {FOREACH in_boat_$boat.id i} to find all the units in a boat with a particular id however if i do this:
Code: Select all
[store_unit]
[filter]
id=$unit.id
[/filter]
variable=in_boat_$boat_selected.id
kill=yes
mode=append
[/store_unit]
I am sure their must be an easier way to do this. Here is my full code:
Code: Select all
#define BOAT_STUFF
[event]
name=moveto
first_time_only=no
[filter]
[filter_adjacent]
side=$unit.side
count=1
type="Elvish Fighter"
[/filter_adjacent]
[/filter]
[store_unit]
[filter]
side=$unit.side
type="Elvish Fighter"
[filter_adjacent]
id=$unit.id
[/filter_adjacent]
[/filter]
variable=boat_selected
[/store_unit]
{MESSAGE_N (Adjacent to a Boat $boat_selected.name)}
[message]
speaker=narrator
message=_"Get in?"
[option]
message=_"Nope"
[/option]
[option]
message=_"Yes"
[command]
[store_unit]
[filter]
id=$unit.id
[/filter]
variable=in_boat_$boat_selected.id
kill=yes
mode=append
[/store_unit]
{MESSAGE_N (Stored unit in_boat_$boat_selected.id)}
[/command]
[/option]
[/message]
[/event]
[event]
name=moveto
first_time_only=no
[filter]
[filter_adjacent]
side=$unit.side
type="Elvish Fighter"
[/filter_adjacent]
[and]
[not]
[filter_adjacent]
side=$unit.side
type="Elvish Fighter"
count=1
[/filter_adjacent]
[/not]
[/and]
[/filter]
{MESSAGE_N (More than one boat, what??)}
[/event]
[event]
name=side turn
first_time_only=no
[set_menu_item]
id=assign_hero_menu_item
description="Unstore units from boat"
image="misc/ums.png"
[show_if]
# if this is a boat on your team
[have_unit]
x,y=$x1,$y1
side=$side_number
type="Elvish Fighter"
[/have_unit]
[/show_if]
[command]
[store_unit]
[filter]
id=$unit.id
[/filter]
variable=boat_selected
[/store_unit]
[message]
speaker=narrator
message="Doing something with $boat_selected.id The first three in the boat are: - $in_boat_[$boat_selected[0].id].id - $in_boat_[$boat_selected[1].id].id - in_boat_$boat_selected[2].id
Also written as - in_boat_$boat_selected.id[0].id"
[/message]
{FOREACH in_boat_$boat_selected.id i}
[message]
speaker=narrator
message="Releasing $in_boat_[$boat_selected[$i].id]"
[/message]
[unstore_unit]
variable=in_boat_[$boat_selected[$i].id]
[/unstore_unit]
{NEXT i}
{CLEAR_VARIABLE in_boat_$boat_selected}
[unstore_unit]
variable=boat_selected
[/unstore_unit]
[/command]
[/set_menu_item]
[/event]
#enddef
Creator of: The Reign of The Lords Era,The Gnats Franken Dungeon.
Re: combining multiple variable names
Likely not your current problem, but if you use unit id's as part of variable names then you have to make sure that they never contain spaces.
Re: combining multiple variable names
Yep, that is my problem the unit Elvish Fighter's id is "Elvish Fighter-4" so since it has a space it would then cause problems.zookeeper wrote:Likely not your current problem, but if you use unit id's as part of variable names then you have to make sure that they never contain spaces.
Is there anyway to check if a variable contains a space? Is there anyway to then remove that space?
Thank you for the quick response!
Creator of: The Reign of The Lords Era,The Gnats Franken Dungeon.
- Pentarctagon
- Project Manager
- Posts: 5565
- Joined: March 22nd, 2009, 10:50 pm
- Location: Earth (occasionally)
Re: combining multiple variable names
Also, when posting chunks of code like this, I think it would be best if you instead created a minimal example of what the problem is - something that someone else can easily copy/paste into any scenario and quickly setup to see what you're seeing. Often times this even let's me figure out how to solve my own problem, since to create a minimal example requires you to also have a good understanding of what the problem is and how to reproduce it.
As for removing spaces, you'll almost certainly need to use lua, in which case there's string.gsub.
As for removing spaces, you'll almost certainly need to use lua, in which case there's string.gsub.
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: combining multiple variable names
I wonder whether we should replace all spaces wih underscores in mainline, code like recuit="Elvish Archer" or type="Elvish Archer" woudl ofc still work since we could make those points spaces treat the same as underscores.
I think we had this discussion already someho but i don't remember the conclusion.
EDIT: just noticed that in 1.13 the
I think we had this discussion already someho but i don't remember the conclusion.
EDIT: just noticed that in 1.13 the
-
chracter is invalid in variablenames aswell, so we maybe want to replace -
with _
aswellScenario 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.
- Paulomat4
- Moderator Emeritus
- Posts: 730
- Joined: October 16th, 2012, 3:32 pm
- Location: Wesmere library, probably summoning Zhangor
Re: combining multiple variable names
I fully support this!I wonder whether we should replace all spaces wih underscores in mainline, code like recuit="Elvish Archer" or type="Elvish Archer" woudl ofc still work since we could make those points spaces treat the same as underscores.
I think we had this discussion already someho but i don't remember the conclusion.
EDIT: just noticed that in 1.13 the - chracter is invalid in variablenames aswell, so we maybe want to replace - with _ aswell
Creator of Dawn of Thunder and Global Unitmarkers
"I thought Naga's used semi-automatic crossbows with incendiary thermite arrows . . . my beliefs that this race is awesome are now shattered." - Evil Earl
"I thought Naga's used semi-automatic crossbows with incendiary thermite arrows . . . my beliefs that this race is awesome are now shattered." - Evil Earl
Re: combining multiple variable names
Thanks Pentarctagon, i will look at my code closer and try to isolate the problem. I agree pasting all that code is very confusingPentarctagon wrote:Also, when posting chunks of code like this, I think it would be best if you instead created a minimal example of what the problem is - something that someone else can easily copy/paste into any scenario and quickly setup to see what you're seeing. Often times this even let's me figure out how to solve my own problem, since to create a minimal example requires you to also have a good understanding of what the problem is and how to reproduce it.
As for removing spaces, you'll almost certainly need to use lua, in which case there's string.gsub.
Creator of: The Reign of The Lords Era,The Gnats Franken Dungeon.
Re: combining multiple variable names
Usual way for this would be "boat.variables.units".
Re: combining multiple variable names
ThanksRavana wrote:Usual way for this would be "boat.variables.units".
Creator of: The Reign of The Lords Era,The Gnats Franken Dungeon.
Re: combining multiple variable names
Hello Dev's i have managed to create a working event that allows units to enter a boat or caravan and then get off again on a right-click menu button.
Here is the thread i post the code on. It seems mostly functional and should work in multiplayer and campaigns!
Unfortunately i read that you can not use [allow_undo] in 1.12 if you have [messages] and [options], that is unfortunate. (Also does this also happen in 1.13)
Thank you for all your help.
(btw i figured out how to do this after examining SoBe, so this is not entirely my genious )
Here is the thread i post the code on. It seems mostly functional and should work in multiplayer and campaigns!
Unfortunately i read that you can not use [allow_undo] in 1.12 if you have [messages] and [options], that is unfortunate. (Also does this also happen in 1.13)
Thank you for all your help.
(btw i figured out how to do this after examining SoBe, so this is not entirely my genious )
Creator of: The Reign of The Lords Era,The Gnats Franken Dungeon.
Re: combining multiple variable names
in 1.13 you can use [allow_undo] in events with [messages] and [option]s, unfortunatley we couldn't backport that fix because it could have resulted in incompabilities version in the 1.12 multipler server.Unfortunately i read that you can not use [allow_undo] in 1.12 if you have [messages] and [options], that is unfortunate. (Also does this also happen in 1.13)
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: combining multiple variable names
A very late reply: Thank you, yes that makes sense and i am glad to hear it has been fixed in 1.13!gfgtdf wrote:in 1.13 you can use [allow_undo] in events with [messages] and [option]s, unfortunatley we couldn't backport that fix because it could have resulted in incompabilities version in the 1.12 multipler server.Unfortunately i read that you can not use [allow_undo] in 1.12 if you have [messages] and [options], that is unfortunate. (Also does this also happen in 1.13)
Creator of: The Reign of The Lords Era,The Gnats Franken Dungeon.
another variable problem
Hello again. I have had another variable problem.
As you can see from the inspector the event has a variable as its x and y coordinates. However this is a problem, because i overwrite that variable in order to use it for another event.
Is there a way to give an event a variable amount, but then assign it the actual value of that variable so the filter in my event would instead say:
Which is what my variables contain until they are overwritten.
As you can see from the inspector the event has a variable as its x and y coordinates. However this is a problem, because i overwrite that variable in order to use it for another event.
Is there a way to give an event a variable amount, but then assign it the actual value of that variable so the filter in my event would instead say:
Code: Select all
[filter]
x=10
y=8
[/filter]
Creator of: The Reign of The Lords Era,The Gnats Franken Dungeon.
Re: combining multiple variable names
I think i understand, basically if i put
delayed_variable_substituition=no
then it will set my variables from the moment the event is created!Thank you i will see if this works!
Creator of: The Reign of The Lords Era,The Gnats Franken Dungeon.