Copying array contents to another array
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: 54
- Joined: May 22nd, 2008, 2:45 am
Copying array contents to another array
Hello again!
I guess this is my first time to get serious with WML and Wesnoth, after all of these years. I tend to make assumptions based upon other languages I've programmed in and that's biting me in the back side! I've searched and read a lot and cannot find a working solution.
I have an array whose elements are container WML "objects" (I think of them as "objects", structs, composite values, whatever). I just want to move or copy them from one array object to another, but nothing I do works. The only thing that comes close is wrong, and that's
This is wrong because it can't copy child containers. I just want the objects I have in useable_spells moved or copied into use_cast_menu.
Of course, I'm later adding this array as options to a message command, so I can see that every thing else is working when I use the (incorrect) mechanism above.
... I mean, I can modify the code to only ever insert into
I guess this is my first time to get serious with WML and Wesnoth, after all of these years. I tend to make assumptions based upon other languages I've programmed in and that's biting me in the back side! I've searched and read a lot and cannot find a working solution.
I have an array whose elements are container WML "objects" (I think of them as "objects", structs, composite values, whatever). I just want to move or copy them from one array object to another, but nothing I do works. The only thing that comes close is wrong, and that's
Code: Select all
[foreach]
array=useable_spells
variable=spell
[do]
[set_variables]
name=use_cast_menu
mode=append
[value]
image=$spell.image
label="$spell.label"
description="$spell.description"
command="$spell.command"
[/value]
[/set_variables]
[/do]
[/foreach]
Of course, I'm later adding this array as options to a message command, so I can see that every thing else is working when I use the (incorrect) mechanism above.
Code: Select all
[message]
speaker=narrator
message= _ "Use which?"
[option]
image=check.png
label=_ "(End)"
description=_ "uses left"
[command]
... blah blah blah blah
[/command]
[/option]
[insert_tag]
name=option
variable=use_cast_menu
[/insert_tag]
[/message]
use_cast_menu
, but that frankly uglifies it.- Pentarctagon
- Project Manager
- Posts: 5592
- Joined: March 22nd, 2009, 10:50 pm
- Location: Earth (occasionally)
Re: Copying array contents to another array
to_variable
might work for this?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
-
- Posts: 54
- Joined: May 22nd, 2008, 2:45 am
Re: Copying array contents to another array
Thank you. I've tried SO many variations that I sure would appreciate an example!
-
- Posts: 54
- Joined: May 22nd, 2008, 2:45 am
Re: Copying array contents to another array
OK, so this worked!
It sure has me baffled from a linguistic stand point. Shouldn't that be called
But thank you for the answer! I knew that I shouldn't have to be looping. This is a strange language for me, and I've programmed in a LOT of strange languages -- think Reverse Polish Notation!
Code: Select all
[set_variables]
name=use_cast_menu
mode=append
to_variable=useable_spells
[/set_variables]
from_variable
?But thank you for the answer! I knew that I shouldn't have to be looping. This is a strange language for me, and I've programmed in a LOT of strange languages -- think Reverse Polish Notation!
Re: Copying array contents to another array
With other language experience it might be easier to implement some of logic in Lua.
-
- Posts: 54
- Joined: May 22nd, 2008, 2:45 am
Re: Copying array contents to another array
Yes, indeed! I think I'm starting to learn that! I also suppose I want to get the best feel that I can for how to work with WML. Wesband/Weshack is a huge mod, 77k lines of code! I'm hoping I can refactor and get some control of that beast. To me, the implementation looks terrible (no offense to anyone) but I'm in love with the game design. I just find the WAY they made Wesnoth into an Angband-ish game to be so cool! It's hard to play because of how much you need to click, but that's part of what I'm hoping to improve.
Thanks for the advice! I think it's right on.