unit variables not immediately showing [solved]
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.
unit variables not immediately showing [solved]
I have twice encountered i assign a unit a variable (using
This may be something standard but it seems like i am doing something wrong, here is an example:
Upon attacking i modify the unit to have a new variable and then print the variable. The first time the narrator says "Hey look, his defense is " and the variables value is obviously null because it does not print anything. The second time the unit attacks him However it prints "Hey look, his defense is 50".
Thank you for your help, this is confusing, maybe i should not be using [modify_unit] for these circumstances.
[modify_unit]
and [variables]
) and the variable does not appear until the next turn or until i assign it again?????This may be something standard but it seems like i am doing something wrong, here is an example:
Code: Select all
[modify_unit]
[filter]
id=$second_unit.id
[/filter]
[variables]
defense=50
[/variables]
[/modify_unit]
{MESSAGE_N (Hey look, his defense is $second_unit.variables.defense)}
{MESSAGE_N}
= a message by the narratorUpon attacking i modify the unit to have a new variable and then print the variable. The first time the narrator says "Hey look, his defense is " and the variables value is obviously null because it does not print anything. The second time the unit attacks him However it prints "Hey look, his defense is 50".
Another Example
Last edited by The_Gnat on January 9th, 2017, 2:10 am, edited 1 time in total.
Creator of: The Reign of The Lords Era,The Gnats Franken Dungeon.
Re: unit variables not immediately showing
You're a modifying a unit, and then you're printing the value of an unrelated variable. Modifying a unit doesn't change anything except the actual real unit; the contents of second_unit are still the same.
When you refer to an automatically stored unit variable/container like $second_unit, what happens is that the unit as it exists at that moment gets stored into that variable/container, and that's it. Nothing further automatically happens to it. If you modify the corresponding real unit, that won't be reflected in the variable. Similarly, you can do whatever you want to the variable, but unless you actually use [unstore_unit], none of that will ever be reflected in the corresponding real unit. Variables like $unit and $second_unit are not "pointers" to the real unit, they're simply a copy of the unit data for your convenience, so that you don't need to manually [store_unit] the unit every time you want to access their contents.
When you refer to an automatically stored unit variable/container like $second_unit, what happens is that the unit as it exists at that moment gets stored into that variable/container, and that's it. Nothing further automatically happens to it. If you modify the corresponding real unit, that won't be reflected in the variable. Similarly, you can do whatever you want to the variable, but unless you actually use [unstore_unit], none of that will ever be reflected in the corresponding real unit. Variables like $unit and $second_unit are not "pointers" to the real unit, they're simply a copy of the unit data for your convenience, so that you don't need to manually [store_unit] the unit every time you want to access their contents.
Re: unit variables not immediately showing
Ahh... i understand i would have to restore the variable in order to see it because the stored unitzookeeper wrote:You're a modifying a unit, and then you're printing the value of an unrelated variable. Modifying a unit doesn't change anything except the actual real unit; the contents of second_unit are still the same.
second_unit
has not been modified yet. Thank you very much, i knew that but somehow overlooked itzookeeper wrote:When you refer to an automatically stored unit variable/container like $second_unit, what happens is that the unit as it exists at that moment gets stored into that variable/container, and that's it. Nothing further automatically happens to it. If you modify the corresponding real unit, that won't be reflected in the variable. Similarly, you can do whatever you want to the variable, but unless you actually use [unstore_unit], none of that will ever be reflected in the corresponding real unit. Variables like $unit and $second_unit are not "pointers" to the real unit, they're simply a copy of the unit data for your convenience, so that you don't need to manually [store_unit] the unit every time you want to access their contents.
That solves my problem, [modify_unit] in and $second_unit are not related and that is the problem i was having! Thank you!
EDIT: what i ended up doing is restoring second_unit and unit once i had made a modification
Creator of: The Reign of The Lords Era,The Gnats Franken Dungeon.