Quantcast
Channel: The Battle for Wesnoth Forums
Viewing all articles
Browse latest Browse all 1444

Lua Labs • Re: Global varialbes begginer guide

$
0
0
Sorry to be dim, but are you saying that this code:

Code:

[set_variable]            name=game_number            value=starting_value_string        [/set_variable]        [set_global_variable]            namespace=Bandits_from_Brown_Hills            from_local=game_number            to_global=loads.1.1.1            side=1            immediate=yes        [/set_global_variable]
produced this output:

Code:

[variables]game=0[/variables]
in persist/Bandits_from_Brown_Hills.cfg?

If so then something set a global variable game to zero apparently.
No idea why, all I can suggest is simplify and try again.

Given the code above, I'd expect to see a statement like:

Code:

[variables]loads.1.1.1="starting_value_string"[/variables]
in persist/Bandits_from_Brown_Hills.cfg.


I have this format of global variables...
How to get the highest number of loads.number?
Any ideas?

Code:

[loads]    [1]        [1]            [variables]                1=1                2=12                3=8            [/variables]        [/1]        [2]            [variables]                1=1                2=12                3=8            [/variables]        [/2]    [/1]    [2]        [1]            [variables]                1=1                2=12                3=8                4=10                5=2324            [/variables]        [/1]    [/2][/loads]
Is [loads] a custom tag?
Thought it might've been some savefileWML thing but seemingly not.
Never seen that before - tho' there's lots about WML I don't know...

Assuming that the contents/values in [loads] came from or can be stored in an array, then to get the highest number (in WML) I'd use the WFL max function (or something similar in lua if you prefer).
Of course conditional WML's greater_than is available but the formula is shorter - and there might be clever ways to compare more than 2 values at a time, perhaps - not really thought about it.

If the number of comparisons is high you could consider a bubble sort?
Otherwise the first thing I'd try would be nested [foreach] statements (one [foreach] per array dimension) to do a linear pass through all array elements and return the highest (or joint highest if the highest value occurs more than once).

Otherwise if you're considering reading data from a file on disk, no idea, sorry.
WML has limited disk write capabilities, probably deliberately for security reasons.
If you want to store these values in persistent variables then I'd shove them all in a single array for ease of processing when the data is retrieved.

Not sure any of that helps, but as I said I'm not clear what it is you're trying to do. :doh:

Cheers!
-- Spannerbag

Statistics: Posted by Spannerbag — Today, 12:26 am



Viewing all articles
Browse latest Browse all 1444

Trending Articles