Dynamic alocation of 2D 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.
Dynamic alocation of 2D array?
I have a problem with allocating 2D array.
First dimension allocates right, second dimension is nonexisting inside save game in [variables] tag
My current code is (well, different names for variables):
Macros are ok, checked them.
I do realize i can emulate n'thD array as 1D array with some operations
, but still 2D would be nicer and easier to debug.
Anyone can help with that?
First dimension allocates right, second dimension is nonexisting inside save game in [variables] tag
My current code is (well, different names for variables):
Code: Select all
[set_variables]
name=array
[/set_variables]
{REPEAT_SAFE $columns iterator_0 (
[set_variables]
name=array.x[$iterator_0]
mode=insert
[/set_variables]
)}
{REPEAT_SAFE $columns iterator_0 (
{REPEAT_SAFE $rows iterator_1 (
[set_variables]
name=array.x[$iterator_0].y[$iterator_1]
mode=insert
[/set_variables]
)}
)}
I do realize i can emulate n'thD array as 1D array with some operations

Anyone can help with that?
Re: Dynamic alocation of 2D array?
Array indexes are created automatically as needed. So there is no need to pre-populate an array. Thus, typical WML style would be to leave it uninitialized until such an index is needed to store actual data. However, one could do this very easily if it were desired.
As for your code, the engine should probably be complaining that you are attempting to set a variable without supplying any value. Fore example, [value][/value].
Other than that, mode=insert is not intended to insert in front of a non-existant array index. It is mentioned in the WML Reference not to use it for that purpose.
Code: Select all
[set_variable]
name=big_empty_array.x[$max_columns].waste_space
value="yes"
[/set_variable]
[clear_variable]
name=big_empty_array.x[$max_columns].waste_space
[/clear_variable]
{FOREACH big_empty_array.x column}
[set_variable]
name=big_empty_array.x[$column].y[$max_rows].waste_space
value="yes"
[/set_variable]
[clear_variable]
name=big_empty_array.x[$column].y[$max_rows].waste_space
[/clear_variable]
{NEXT column}
Other than that, mode=insert is not intended to insert in front of a non-existant array index. It is mentioned in the WML Reference not to use it for that purpose.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
Re: Dynamic alocation of 2D array?
Thank you very much 
